remote: convert fetch refspecs to struct refspec
Convert the set of fetch refspecs stored in 'struct remote' to use 'struct refspec'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6bdb304b10
commit
e5349abf93
@ -407,8 +407,8 @@ static struct ref *get_ref_map(struct transport *transport,
|
|||||||
fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array);
|
fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array);
|
||||||
fetch_refspec_nr = refmap_nr;
|
fetch_refspec_nr = refmap_nr;
|
||||||
} else {
|
} else {
|
||||||
fetch_refspec = transport->remote->fetch;
|
fetch_refspec = transport->remote->fetch.items;
|
||||||
fetch_refspec_nr = transport->remote->fetch_refspec_nr;
|
fetch_refspec_nr = transport->remote->fetch.nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < fetch_refspec_nr; i++)
|
for (i = 0; i < fetch_refspec_nr; i++)
|
||||||
@ -421,16 +421,16 @@ static struct ref *get_ref_map(struct transport *transport,
|
|||||||
struct branch *branch = branch_get(NULL);
|
struct branch *branch = branch_get(NULL);
|
||||||
int has_merge = branch_has_merge_config(branch);
|
int has_merge = branch_has_merge_config(branch);
|
||||||
if (remote &&
|
if (remote &&
|
||||||
(remote->fetch_refspec_nr ||
|
(remote->fetch.nr ||
|
||||||
/* Note: has_merge implies non-NULL branch->remote_name */
|
/* Note: has_merge implies non-NULL branch->remote_name */
|
||||||
(has_merge && !strcmp(branch->remote_name, remote->name)))) {
|
(has_merge && !strcmp(branch->remote_name, remote->name)))) {
|
||||||
for (i = 0; i < remote->fetch_refspec_nr; i++) {
|
for (i = 0; i < remote->fetch.nr; i++) {
|
||||||
get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0);
|
get_fetch_map(remote_refs, &remote->fetch.items[i], &tail, 0);
|
||||||
if (remote->fetch[i].dst &&
|
if (remote->fetch.items[i].dst &&
|
||||||
remote->fetch[i].dst[0])
|
remote->fetch.items[i].dst[0])
|
||||||
*autotags = 1;
|
*autotags = 1;
|
||||||
if (!i && !has_merge && ref_map &&
|
if (!i && !has_merge && ref_map &&
|
||||||
!remote->fetch[0].pattern)
|
!remote->fetch.items[0].pattern)
|
||||||
ref_map->fetch_head_status = FETCH_HEAD_MERGE;
|
ref_map->fetch_head_status = FETCH_HEAD_MERGE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -1166,8 +1166,8 @@ static int do_fetch(struct transport *transport,
|
|||||||
if (ref_count) {
|
if (ref_count) {
|
||||||
prune_refs(refs, ref_count, ref_map, transport->url);
|
prune_refs(refs, ref_count, ref_map, transport->url);
|
||||||
} else {
|
} else {
|
||||||
prune_refs(transport->remote->fetch,
|
prune_refs(transport->remote->fetch.items,
|
||||||
transport->remote->fetch_refspec_nr,
|
transport->remote->fetch.nr,
|
||||||
ref_map,
|
ref_map,
|
||||||
transport->url);
|
transport->url);
|
||||||
}
|
}
|
||||||
|
@ -333,10 +333,10 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
|
|||||||
struct ref *ref, *stale_refs;
|
struct ref *ref, *stale_refs;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < states->remote->fetch_refspec_nr; i++)
|
for (i = 0; i < states->remote->fetch.nr; i++)
|
||||||
if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1))
|
if (get_fetch_map(remote_refs, &states->remote->fetch.items[i], &tail, 1))
|
||||||
die(_("Could not get fetch map for refspec %s"),
|
die(_("Could not get fetch map for refspec %s"),
|
||||||
states->remote->fetch_refspec[i]);
|
states->remote->fetch.raw[i]);
|
||||||
|
|
||||||
states->new_refs.strdup_strings = 1;
|
states->new_refs.strdup_strings = 1;
|
||||||
states->tracked.strdup_strings = 1;
|
states->tracked.strdup_strings = 1;
|
||||||
@ -347,8 +347,8 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
|
|||||||
else
|
else
|
||||||
string_list_append(&states->tracked, abbrev_branch(ref->name));
|
string_list_append(&states->tracked, abbrev_branch(ref->name));
|
||||||
}
|
}
|
||||||
stale_refs = get_stale_heads(states->remote->fetch,
|
stale_refs = get_stale_heads(states->remote->fetch.items,
|
||||||
states->remote->fetch_refspec_nr, fetch_map);
|
states->remote->fetch.nr, fetch_map);
|
||||||
for (ref = stale_refs; ref; ref = ref->next) {
|
for (ref = stale_refs; ref; ref = ref->next) {
|
||||||
struct string_list_item *item =
|
struct string_list_item *item =
|
||||||
string_list_append(&states->stale, abbrev_branch(ref->name));
|
string_list_append(&states->stale, abbrev_branch(ref->name));
|
||||||
@ -590,8 +590,8 @@ static int migrate_file(struct remote *remote)
|
|||||||
git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0);
|
git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0);
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
|
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
|
||||||
for (i = 0; i < remote->fetch_refspec_nr; i++)
|
for (i = 0; i < remote->fetch.raw_nr; i++)
|
||||||
git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0);
|
git_config_set_multivar(buf.buf, remote->fetch.raw[i], "^$", 0);
|
||||||
if (remote->origin == REMOTE_REMOTES)
|
if (remote->origin == REMOTE_REMOTES)
|
||||||
unlink_or_warn(git_path("remotes/%s", remote->name));
|
unlink_or_warn(git_path("remotes/%s", remote->name));
|
||||||
else if (remote->origin == REMOTE_BRANCHES)
|
else if (remote->origin == REMOTE_BRANCHES)
|
||||||
@ -646,11 +646,11 @@ static int mv(int argc, const char **argv)
|
|||||||
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
|
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
|
||||||
git_config_set_multivar(buf.buf, NULL, NULL, 1);
|
git_config_set_multivar(buf.buf, NULL, NULL, 1);
|
||||||
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
|
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
|
||||||
for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
|
for (i = 0; i < oldremote->fetch.raw_nr; i++) {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
strbuf_reset(&buf2);
|
strbuf_reset(&buf2);
|
||||||
strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
|
strbuf_addstr(&buf2, oldremote->fetch.raw[i]);
|
||||||
ptr = strstr(buf2.buf, old_remote_context.buf);
|
ptr = strstr(buf2.buf, old_remote_context.buf);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
refspec_updated = 1;
|
refspec_updated = 1;
|
||||||
|
38
remote.c
38
remote.c
@ -77,23 +77,9 @@ static const char *alias_url(const char *url, struct rewrites *r)
|
|||||||
return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
|
return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_fetch_refspec(struct remote *remote, const char *ref)
|
|
||||||
{
|
|
||||||
ALLOC_GROW(remote->fetch_refspec,
|
|
||||||
remote->fetch_refspec_nr + 1,
|
|
||||||
remote->fetch_refspec_alloc);
|
|
||||||
remote->fetch_refspec[remote->fetch_refspec_nr++] = ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_prune_tags_to_fetch_refspec(struct remote *remote)
|
void add_prune_tags_to_fetch_refspec(struct remote *remote)
|
||||||
{
|
{
|
||||||
int nr = remote->fetch_refspec_nr;
|
refspec_append(&remote->fetch, TAG_REFSPEC);
|
||||||
int bufsize = nr + 1;
|
|
||||||
int size = sizeof(struct refspec_item);
|
|
||||||
|
|
||||||
remote->fetch = xrealloc(remote->fetch, size * bufsize);
|
|
||||||
memcpy(&remote->fetch[nr], tag_refspec, size);
|
|
||||||
add_fetch_refspec(remote, xstrdup(TAG_REFSPEC));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_url(struct remote *remote, const char *url)
|
static void add_url(struct remote *remote, const char *url)
|
||||||
@ -169,6 +155,7 @@ static struct remote *make_remote(const char *name, int len)
|
|||||||
ret->prune_tags = -1; /* unspecified */
|
ret->prune_tags = -1; /* unspecified */
|
||||||
ret->name = xstrndup(name, len);
|
ret->name = xstrndup(name, len);
|
||||||
refspec_init(&ret->push, REFSPEC_PUSH);
|
refspec_init(&ret->push, REFSPEC_PUSH);
|
||||||
|
refspec_init(&ret->fetch, REFSPEC_FETCH);
|
||||||
|
|
||||||
ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc);
|
ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc);
|
||||||
remotes[remotes_nr++] = ret;
|
remotes[remotes_nr++] = ret;
|
||||||
@ -271,7 +258,7 @@ static void read_remotes_file(struct remote *remote)
|
|||||||
else if (skip_prefix(buf.buf, "Push:", &v))
|
else if (skip_prefix(buf.buf, "Push:", &v))
|
||||||
refspec_append(&remote->push, skip_spaces(v));
|
refspec_append(&remote->push, skip_spaces(v));
|
||||||
else if (skip_prefix(buf.buf, "Pull:", &v))
|
else if (skip_prefix(buf.buf, "Pull:", &v))
|
||||||
add_fetch_refspec(remote, xstrdup(skip_spaces(v)));
|
refspec_append(&remote->fetch, skip_spaces(v));
|
||||||
}
|
}
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@ -310,13 +297,15 @@ static void read_branches_file(struct remote *remote)
|
|||||||
frag = "master";
|
frag = "master";
|
||||||
|
|
||||||
add_url_alias(remote, strbuf_detach(&buf, NULL));
|
add_url_alias(remote, strbuf_detach(&buf, NULL));
|
||||||
add_fetch_refspec(remote, xstrfmt("refs/heads/%s:refs/heads/%s",
|
strbuf_addf(&buf, "refs/heads/%s:refs/heads/%s",
|
||||||
frag, remote->name));
|
frag, remote->name);
|
||||||
|
refspec_append(&remote->fetch, buf.buf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cogito compatible push: push current HEAD to remote #branch
|
* Cogito compatible push: push current HEAD to remote #branch
|
||||||
* (master if missing)
|
* (master if missing)
|
||||||
*/
|
*/
|
||||||
|
strbuf_reset(&buf);
|
||||||
strbuf_addf(&buf, "HEAD:refs/heads/%s", frag);
|
strbuf_addf(&buf, "HEAD:refs/heads/%s", frag);
|
||||||
refspec_append(&remote->push, buf.buf);
|
refspec_append(&remote->push, buf.buf);
|
||||||
remote->fetch_tags = 1; /* always auto-follow */
|
remote->fetch_tags = 1; /* always auto-follow */
|
||||||
@ -411,7 +400,8 @@ static int handle_config(const char *key, const char *value, void *cb)
|
|||||||
const char *v;
|
const char *v;
|
||||||
if (git_config_string(&v, key, value))
|
if (git_config_string(&v, key, value))
|
||||||
return -1;
|
return -1;
|
||||||
add_fetch_refspec(remote, v);
|
refspec_append(&remote->fetch, v);
|
||||||
|
free((char *)v);
|
||||||
} else if (!strcmp(subkey, "receivepack")) {
|
} else if (!strcmp(subkey, "receivepack")) {
|
||||||
const char *v;
|
const char *v;
|
||||||
if (git_config_string(&v, key, value))
|
if (git_config_string(&v, key, value))
|
||||||
@ -578,7 +568,6 @@ static struct remote *remote_get_1(const char *name,
|
|||||||
add_url_alias(ret, name);
|
add_url_alias(ret, name);
|
||||||
if (!valid_remote(ret))
|
if (!valid_remote(ret))
|
||||||
return NULL;
|
return NULL;
|
||||||
ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,9 +598,6 @@ int for_each_remote(each_remote_fn fn, void *priv)
|
|||||||
struct remote *r = remotes[i];
|
struct remote *r = remotes[i];
|
||||||
if (!r)
|
if (!r)
|
||||||
continue;
|
continue;
|
||||||
if (!r->fetch)
|
|
||||||
r->fetch = parse_fetch_refspec(r->fetch_refspec_nr,
|
|
||||||
r->fetch_refspec);
|
|
||||||
result = fn(r, priv);
|
result = fn(r, priv);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -790,7 +776,7 @@ char *apply_refspecs(struct refspec_item *refspecs, int nr_refspec,
|
|||||||
|
|
||||||
int remote_find_tracking(struct remote *remote, struct refspec_item *refspec)
|
int remote_find_tracking(struct remote *remote, struct refspec_item *refspec)
|
||||||
{
|
{
|
||||||
return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec);
|
return query_refspecs(remote->fetch.items, remote->fetch.nr, refspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
|
static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
|
||||||
@ -1588,7 +1574,7 @@ static const char *tracking_for_push_dest(struct remote *remote,
|
|||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
ret = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
|
ret = apply_refspecs(remote->fetch.items, remote->fetch.nr, refname);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return error_buf(err,
|
return error_buf(err,
|
||||||
_("push destination '%s' on remote '%s' has no local tracking branch"),
|
_("push destination '%s' on remote '%s' has no local tracking branch"),
|
||||||
@ -2222,7 +2208,7 @@ static int remote_tracking(struct remote *remote, const char *refname,
|
|||||||
{
|
{
|
||||||
char *dst;
|
char *dst;
|
||||||
|
|
||||||
dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
|
dst = apply_refspecs(remote->fetch.items, remote->fetch.nr, refname);
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return -1; /* no tracking ref for refname at remote */
|
return -1; /* no tracking ref for refname at remote */
|
||||||
if (read_ref(dst, oid))
|
if (read_ref(dst, oid))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user