Skip to content

Commit 6bdb304

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16eefc8 commit 6bdb304

File tree

4 files changed

+28
-37
lines changed

4 files changed

+28
-37
lines changed

builtin/push.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ static const char *map_refspec(const char *ref,
7979
if (count_refspec_match(ref, local_refs, &matched) != 1)
8080
return ref;
8181

82-
if (remote->push) {
82+
if (remote->push.nr) {
8383
struct refspec_item query;
8484
memset(&query, 0, sizeof(struct refspec_item));
8585
query.src = matched->name;
86-
if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) &&
86+
if (!query_refspecs(remote->push.items, remote->push.nr, &query) &&
8787
query.dst) {
8888
struct strbuf buf = STRBUF_INIT;
8989
strbuf_addf(&buf, "%s%s:%s",
@@ -436,9 +436,9 @@ static int do_push(const char *repo, int flags,
436436
}
437437

438438
if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
439-
if (remote->push_refspec_nr) {
440-
refspec = remote->push_refspec;
441-
refspec_nr = remote->push_refspec_nr;
439+
if (remote->push.raw_nr) {
440+
refspec = remote->push.raw;
441+
refspec_nr = remote->push.raw_nr;
442442
} else if (!(flags & TRANSPORT_PUSH_MIRROR))
443443
setup_default_push_refspecs(remote);
444444
}

builtin/remote.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
388388
local_refs = get_local_heads();
389389
push_map = copy_ref_list(remote_refs);
390390

391-
match_push_refs(local_refs, &push_map, remote->push_refspec_nr,
392-
remote->push_refspec, MATCH_REFS_NONE);
391+
match_push_refs(local_refs, &push_map, remote->push.raw_nr,
392+
remote->push.raw, MATCH_REFS_NONE);
393393

394394
states->push.strdup_strings = 1;
395395
for (ref = push_map; ref; ref = ref->next) {
@@ -435,14 +435,14 @@ static int get_push_ref_states_noquery(struct ref_states *states)
435435
return 0;
436436

437437
states->push.strdup_strings = 1;
438-
if (!remote->push_refspec_nr) {
438+
if (!remote->push.nr) {
439439
item = string_list_append(&states->push, _("(matching)"));
440440
info = item->util = xcalloc(1, sizeof(struct push_info));
441441
info->status = PUSH_STATUS_NOTQUERIED;
442442
info->dest = xstrdup(item->string);
443443
}
444-
for (i = 0; i < remote->push_refspec_nr; i++) {
445-
struct refspec_item *spec = remote->push + i;
444+
for (i = 0; i < remote->push.nr; i++) {
445+
const struct refspec_item *spec = &remote->push.items[i];
446446
if (spec->matching)
447447
item = string_list_append(&states->push, _("(matching)"));
448448
else if (strlen(spec->src))
@@ -586,8 +586,8 @@ static int migrate_file(struct remote *remote)
586586
git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
587587
strbuf_reset(&buf);
588588
strbuf_addf(&buf, "remote.%s.push", remote->name);
589-
for (i = 0; i < remote->push_refspec_nr; i++)
590-
git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0);
589+
for (i = 0; i < remote->push.raw_nr; i++)
590+
git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0);
591591
strbuf_reset(&buf);
592592
strbuf_addf(&buf, "remote.%s.fetch", remote->name);
593593
for (i = 0; i < remote->fetch_refspec_nr; i++)

remote.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ static const char *alias_url(const char *url, struct rewrites *r)
7777
return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
7878
}
7979

80-
static void add_push_refspec(struct remote *remote, const char *ref)
81-
{
82-
ALLOC_GROW(remote->push_refspec,
83-
remote->push_refspec_nr + 1,
84-
remote->push_refspec_alloc);
85-
remote->push_refspec[remote->push_refspec_nr++] = ref;
86-
}
87-
8880
static void add_fetch_refspec(struct remote *remote, const char *ref)
8981
{
9082
ALLOC_GROW(remote->fetch_refspec,
@@ -175,9 +167,11 @@ static struct remote *make_remote(const char *name, int len)
175167
ret = xcalloc(1, sizeof(struct remote));
176168
ret->prune = -1; /* unspecified */
177169
ret->prune_tags = -1; /* unspecified */
170+
ret->name = xstrndup(name, len);
171+
refspec_init(&ret->push, REFSPEC_PUSH);
172+
178173
ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc);
179174
remotes[remotes_nr++] = ret;
180-
ret->name = xstrndup(name, len);
181175

182176
hashmap_entry_init(ret, lookup_entry.hash);
183177
replaced = hashmap_put(&remotes_hash, ret);
@@ -275,7 +269,7 @@ static void read_remotes_file(struct remote *remote)
275269
if (skip_prefix(buf.buf, "URL:", &v))
276270
add_url_alias(remote, xstrdup(skip_spaces(v)));
277271
else if (skip_prefix(buf.buf, "Push:", &v))
278-
add_push_refspec(remote, xstrdup(skip_spaces(v)));
272+
refspec_append(&remote->push, skip_spaces(v));
279273
else if (skip_prefix(buf.buf, "Pull:", &v))
280274
add_fetch_refspec(remote, xstrdup(skip_spaces(v)));
281275
}
@@ -323,8 +317,10 @@ static void read_branches_file(struct remote *remote)
323317
* Cogito compatible push: push current HEAD to remote #branch
324318
* (master if missing)
325319
*/
326-
add_push_refspec(remote, xstrfmt("HEAD:refs/heads/%s", frag));
320+
strbuf_addf(&buf, "HEAD:refs/heads/%s", frag);
321+
refspec_append(&remote->push, buf.buf);
327322
remote->fetch_tags = 1; /* always auto-follow */
323+
strbuf_release(&buf);
328324
}
329325

330326
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)
409405
const char *v;
410406
if (git_config_string(&v, key, value))
411407
return -1;
412-
add_push_refspec(remote, v);
408+
refspec_append(&remote->push, v);
409+
free((char *)v);
413410
} else if (!strcmp(subkey, "fetch")) {
414411
const char *v;
415412
if (git_config_string(&v, key, value))
@@ -542,9 +539,9 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push,
542539
pushremote_for_branch(branch, NULL);
543540
struct remote *remote = remote_get(remote_name);
544541

545-
if (remote && remote->push_refspec_nr &&
546-
(dst = apply_refspecs(remote->push,
547-
remote->push_refspec_nr,
542+
if (remote && remote->push.nr &&
543+
(dst = apply_refspecs(remote->push.items,
544+
remote->push.nr,
548545
branch->refname))) {
549546
if (explicit)
550547
*explicit = 1;
@@ -582,7 +579,6 @@ static struct remote *remote_get_1(const char *name,
582579
if (!valid_remote(ret))
583580
return NULL;
584581
ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec);
585-
ret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec);
586582
return ret;
587583
}
588584

@@ -616,9 +612,6 @@ int for_each_remote(each_remote_fn fn, void *priv)
616612
if (!r->fetch)
617613
r->fetch = parse_fetch_refspec(r->fetch_refspec_nr,
618614
r->fetch_refspec);
619-
if (!r->push)
620-
r->push = parse_push_refspec(r->push_refspec_nr,
621-
r->push_refspec);
622615
result = fn(r, priv);
623616
}
624617
return result;
@@ -1613,11 +1606,11 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
16131606
_("branch '%s' has no remote for pushing"),
16141607
branch->name);
16151608

1616-
if (remote->push_refspec_nr) {
1609+
if (remote->push.nr) {
16171610
char *dst;
16181611
const char *ret;
16191612

1620-
dst = apply_refspecs(remote->push, remote->push_refspec_nr,
1613+
dst = apply_refspecs(remote->push.items, remote->push.nr,
16211614
branch->refname);
16221615
if (!dst)
16231616
return error_buf(err,

remote.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "parse-options.h"
55
#include "hashmap.h"
6+
#include "refspec.h"
67

78
enum {
89
REMOTE_UNCONFIGURED = 0,
@@ -27,10 +28,7 @@ struct remote {
2728
int pushurl_nr;
2829
int pushurl_alloc;
2930

30-
const char **push_refspec;
31-
struct refspec_item *push;
32-
int push_refspec_nr;
33-
int push_refspec_alloc;
31+
struct refspec push;
3432

3533
const char **fetch_refspec;
3634
struct refspec_item *fetch;

0 commit comments

Comments
 (0)