summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2017-06-07 15:05:49 +0200
committerJunio C Hamano <gitster@pobox.com>2017-06-21 15:42:42 -0700
commit42b72152181821c029334d0637331c9d7de782d3 (patch)
treed27143598dbb4257ba506320b59b206d726805f7
parent26b867634bc9196e0cbdc91c5ca039bb1e830a56 (diff)
downloadgit-42b72152181821c029334d0637331c9d7de782d3.tar.gz
remote: don't use remote->{fetch,push}_refspec
builtin/remote.c uses remote->fetch_refspec and remote->push_refspec, i.e. refspecs as strings, in a few places, e.g. in an error message or to set configuration variables. Since we are about to eliminate remote->{fetch,push}_refspec, recreate those strings from the corresponding remote->{fetch,push} entries. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
-rw-r--r--builtin/remote.c22
-rw-r--r--remote.c20
-rw-r--r--remote.h2
3 files changed, 37 insertions, 7 deletions
diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe265..7f0072fe50 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -334,7 +334,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
for (i = 0; i < states->remote->fetch_refspec_nr; i++)
if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1))
die(_("Could not get fetch map for refspec %s"),
- states->remote->fetch_refspec[i]);
+ refspec_to_string(&states->remote->fetch[i]));
states->new.strdup_strings = 1;
states->tracked.strdup_strings = 1;
@@ -576,7 +576,7 @@ static int read_remote_branches(const char *refname,
static int migrate_file(struct remote *remote)
{
- struct strbuf buf = STRBUF_INIT;
+ struct strbuf buf = STRBUF_INIT, refspec = STRBUF_INIT;
int i;
strbuf_addf(&buf, "remote.%s.url", remote->name);
@@ -584,17 +584,25 @@ static int migrate_file(struct remote *remote)
git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.push", remote->name);
- for (i = 0; i < remote->push_refspec_nr; i++)
- git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0);
+ for (i = 0; i < remote->push_refspec_nr; i++) {
+ strbuf_add_refspec(&refspec, &remote->push[i]);
+ git_config_set_multivar(buf.buf, refspec.buf, "^$", 0);
+ strbuf_reset(&refspec);
+ }
strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
- for (i = 0; i < remote->fetch_refspec_nr; i++)
- git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0);
+ for (i = 0; i < remote->fetch_refspec_nr; i++) {
+ strbuf_add_refspec(&refspec, &remote->fetch[i]);
+ git_config_set_multivar(buf.buf, refspec.buf, "^$", 0);
+ strbuf_reset(&refspec);
+ }
if (remote->origin == REMOTE_REMOTES)
unlink_or_warn(git_path("remotes/%s", remote->name));
else if (remote->origin == REMOTE_BRANCHES)
unlink_or_warn(git_path("branches/%s", remote->name));
+ strbuf_release(&buf);
+ strbuf_release(&refspec);
return 0;
}
@@ -647,7 +655,7 @@ static int mv(int argc, const char **argv)
char *ptr;
strbuf_reset(&buf2);
- strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
+ strbuf_add_refspec(&buf2, &oldremote->fetch[i]);
ptr = strstr(buf2.buf, old_remote_context.buf);
if (ptr) {
refspec_updated = 1;
diff --git a/remote.c b/remote.c
index 336db8298a..a021deceee 100644
--- a/remote.c
+++ b/remote.c
@@ -919,6 +919,26 @@ char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
return query.dst;
}
+void strbuf_add_refspec(struct strbuf *sb, const struct refspec *refspec)
+{
+ if (refspec->force)
+ strbuf_addch(sb, '+');
+ if (refspec->src)
+ strbuf_addstr(sb, refspec->src);
+ if (refspec->dst) {
+ strbuf_addch(sb, ':');
+ strbuf_addstr(sb, refspec->dst);
+ } else if (!refspec->src)
+ strbuf_addch(sb, ':');
+}
+
+char *refspec_to_string(const struct refspec *refspec)
+{
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_add_refspec(&sb, refspec);
+ return strbuf_detach(&sb, NULL);
+}
+
int remote_find_tracking(struct remote *remote, struct refspec *refspec)
{
return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec);
diff --git a/remote.h b/remote.h
index 07316c21ec..4a05e72302 100644
--- a/remote.h
+++ b/remote.h
@@ -177,6 +177,8 @@ void free_refspec(int nr_refspec, struct refspec *refspec);
extern int query_refspecs(struct refspec *specs, int nr, struct refspec *query);
char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
const char *name);
+void strbuf_add_refspec(struct strbuf *sb, const struct refspec *refspec);
+char *refspec_to_string(const struct refspec *refspec);
int check_push_refs(struct ref *src, int nr_refspec, const char **refspec);
int match_push_refs(struct ref *src, struct ref **dst,