remote: convert push refspecs to struct refspec

Convert the set of push 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:
Brandon Williams 2018-05-16 15:58:00 -07:00 коммит произвёл Junio C Hamano
Родитель 16eefc8eb3
Коммит 6bdb304b10
4 изменённых файлов: 28 добавлений и 37 удалений

Просмотреть файл

@ -79,11 +79,11 @@ static const char *map_refspec(const char *ref,
if (count_refspec_match(ref, local_refs, &matched) != 1)
return ref;
if (remote->push) {
if (remote->push.nr) {
struct refspec_item query;
memset(&query, 0, sizeof(struct refspec_item));
query.src = matched->name;
if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) &&
if (!query_refspecs(remote->push.items, remote->push.nr, &query) &&
query.dst) {
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "%s%s:%s",
@ -436,9 +436,9 @@ static int do_push(const char *repo, int flags,
}
if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
if (remote->push_refspec_nr) {
refspec = remote->push_refspec;
refspec_nr = remote->push_refspec_nr;
if (remote->push.raw_nr) {
refspec = remote->push.raw;
refspec_nr = remote->push.raw_nr;
} else if (!(flags & TRANSPORT_PUSH_MIRROR))
setup_default_push_refspecs(remote);
}

Просмотреть файл

@ -388,8 +388,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
local_refs = get_local_heads();
push_map = copy_ref_list(remote_refs);
match_push_refs(local_refs, &push_map, remote->push_refspec_nr,
remote->push_refspec, MATCH_REFS_NONE);
match_push_refs(local_refs, &push_map, remote->push.raw_nr,
remote->push.raw, MATCH_REFS_NONE);
states->push.strdup_strings = 1;
for (ref = push_map; ref; ref = ref->next) {
@ -435,14 +435,14 @@ static int get_push_ref_states_noquery(struct ref_states *states)
return 0;
states->push.strdup_strings = 1;
if (!remote->push_refspec_nr) {
if (!remote->push.nr) {
item = string_list_append(&states->push, _("(matching)"));
info = item->util = xcalloc(1, sizeof(struct push_info));
info->status = PUSH_STATUS_NOTQUERIED;
info->dest = xstrdup(item->string);
}
for (i = 0; i < remote->push_refspec_nr; i++) {
struct refspec_item *spec = remote->push + i;
for (i = 0; i < remote->push.nr; i++) {
const struct refspec_item *spec = &remote->push.items[i];
if (spec->matching)
item = string_list_append(&states->push, _("(matching)"));
else if (strlen(spec->src))
@ -586,8 +586,8 @@ 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.raw_nr; i++)
git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0);
strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
for (i = 0; i < remote->fetch_refspec_nr; i++)

Просмотреть файл

@ -77,14 +77,6 @@ static const char *alias_url(const char *url, struct rewrites *r)
return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
}
static void add_push_refspec(struct remote *remote, const char *ref)
{
ALLOC_GROW(remote->push_refspec,
remote->push_refspec_nr + 1,
remote->push_refspec_alloc);
remote->push_refspec[remote->push_refspec_nr++] = ref;
}
static void add_fetch_refspec(struct remote *remote, const char *ref)
{
ALLOC_GROW(remote->fetch_refspec,
@ -175,9 +167,11 @@ static struct remote *make_remote(const char *name, int len)
ret = xcalloc(1, sizeof(struct remote));
ret->prune = -1; /* unspecified */
ret->prune_tags = -1; /* unspecified */
ret->name = xstrndup(name, len);
refspec_init(&ret->push, REFSPEC_PUSH);
ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc);
remotes[remotes_nr++] = ret;
ret->name = xstrndup(name, len);
hashmap_entry_init(ret, lookup_entry.hash);
replaced = hashmap_put(&remotes_hash, ret);
@ -275,7 +269,7 @@ static void read_remotes_file(struct remote *remote)
if (skip_prefix(buf.buf, "URL:", &v))
add_url_alias(remote, xstrdup(skip_spaces(v)));
else if (skip_prefix(buf.buf, "Push:", &v))
add_push_refspec(remote, xstrdup(skip_spaces(v)));
refspec_append(&remote->push, skip_spaces(v));
else if (skip_prefix(buf.buf, "Pull:", &v))
add_fetch_refspec(remote, xstrdup(skip_spaces(v)));
}
@ -323,8 +317,10 @@ static void read_branches_file(struct remote *remote)
* Cogito compatible push: push current HEAD to remote #branch
* (master if missing)
*/
add_push_refspec(remote, xstrfmt("HEAD:refs/heads/%s", frag));
strbuf_addf(&buf, "HEAD:refs/heads/%s", frag);
refspec_append(&remote->push, buf.buf);
remote->fetch_tags = 1; /* always auto-follow */
strbuf_release(&buf);
}
static int handle_config(const char *key, const char *value, void *cb)
@ -409,7 +405,8 @@ static int handle_config(const char *key, const char *value, void *cb)
const char *v;
if (git_config_string(&v, key, value))
return -1;
add_push_refspec(remote, v);
refspec_append(&remote->push, v);
free((char *)v);
} else if (!strcmp(subkey, "fetch")) {
const char *v;
if (git_config_string(&v, key, value))
@ -542,9 +539,9 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push,
pushremote_for_branch(branch, NULL);
struct remote *remote = remote_get(remote_name);
if (remote && remote->push_refspec_nr &&
(dst = apply_refspecs(remote->push,
remote->push_refspec_nr,
if (remote && remote->push.nr &&
(dst = apply_refspecs(remote->push.items,
remote->push.nr,
branch->refname))) {
if (explicit)
*explicit = 1;
@ -582,7 +579,6 @@ static struct remote *remote_get_1(const char *name,
if (!valid_remote(ret))
return NULL;
ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec);
ret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec);
return ret;
}
@ -616,9 +612,6 @@ int for_each_remote(each_remote_fn fn, void *priv)
if (!r->fetch)
r->fetch = parse_fetch_refspec(r->fetch_refspec_nr,
r->fetch_refspec);
if (!r->push)
r->push = parse_push_refspec(r->push_refspec_nr,
r->push_refspec);
result = fn(r, priv);
}
return result;
@ -1613,11 +1606,11 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
_("branch '%s' has no remote for pushing"),
branch->name);
if (remote->push_refspec_nr) {
if (remote->push.nr) {
char *dst;
const char *ret;
dst = apply_refspecs(remote->push, remote->push_refspec_nr,
dst = apply_refspecs(remote->push.items, remote->push.nr,
branch->refname);
if (!dst)
return error_buf(err,

Просмотреть файл

@ -3,6 +3,7 @@
#include "parse-options.h"
#include "hashmap.h"
#include "refspec.h"
enum {
REMOTE_UNCONFIGURED = 0,
@ -27,10 +28,7 @@ struct remote {
int pushurl_nr;
int pushurl_alloc;
const char **push_refspec;
struct refspec_item *push;
int push_refspec_nr;
int push_refspec_alloc;
struct refspec push;
const char **fetch_refspec;
struct refspec_item *fetch;