Skip to content

Commit 6d2bf96

Browse files
Clemens Buchachergitster
Clemens Buchacher
authored andcommitted
match_refs: search ref list tail internally
Avoid code duplication by moving list tail search to match_refs(). This does not change the semantics, except for http-push, which now inserts to the front of the ref list in order to get rid of the global remote_tail. Signed-off-by: Clemens Buchacher <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a01554 commit 6d2bf96

File tree

6 files changed

+23
-29
lines changed

6 files changed

+23
-29
lines changed

Diff for: builtin-remote.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,14 @@ static int get_push_ref_states(const struct ref *remote_refs,
294294
struct ref_states *states)
295295
{
296296
struct remote *remote = states->remote;
297-
struct ref *ref, *local_refs, *push_map, **push_tail;
297+
struct ref *ref, *local_refs, *push_map;
298298
if (remote->mirror)
299299
return 0;
300300

301301
local_refs = get_local_heads();
302302
push_map = copy_ref_list(remote_refs);
303303

304-
push_tail = &push_map;
305-
while (*push_tail)
306-
push_tail = &((*push_tail)->next);
307-
match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr,
304+
match_refs(local_refs, &push_map, remote->push_refspec_nr,
308305
remote->push_refspec, MATCH_REFS_NONE);
309306

310307
states->push.strdup_strings = 1;

Diff for: builtin-send-pack.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
473473
int fd[2];
474474
struct child_process *conn;
475475
struct extra_have_objects extra_have;
476-
struct ref *remote_refs, **remote_tail, *local_refs;
476+
struct ref *remote_refs, *local_refs;
477477
int ret;
478478
int send_all = 0;
479479
const char *receivepack = "git-receive-pack";
@@ -567,13 +567,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
567567
flags |= MATCH_REFS_MIRROR;
568568

569569
/* match them up */
570-
remote_tail = &remote_refs;
571-
while (*remote_tail)
572-
remote_tail = &((*remote_tail)->next);
573-
if (match_refs(local_refs, remote_refs, &remote_tail,
574-
nr_refspecs, refspecs, flags)) {
570+
if (match_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags))
575571
return -1;
576-
}
577572

578573
ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
579574

Diff for: http-push.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
18441844
return 1;
18451845
}
18461846

1847-
static struct ref *remote_refs, **remote_tail;
1847+
static struct ref *remote_refs;
18481848

18491849
static void one_remote_ref(char *refname)
18501850
{
@@ -1874,13 +1874,12 @@ static void one_remote_ref(char *refname)
18741874
}
18751875
}
18761876

1877-
*remote_tail = ref;
1878-
remote_tail = &ref->next;
1877+
ref->next = remote_refs;
1878+
remote_refs = ref;
18791879
}
18801880

18811881
static void get_dav_remote_heads(void)
18821882
{
1883-
remote_tail = &remote_refs;
18841883
remote_ls("refs/", (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL);
18851884
}
18861885

@@ -2311,9 +2310,7 @@ int main(int argc, char **argv)
23112310
}
23122311

23132312
/* match them up */
2314-
if (!remote_tail)
2315-
remote_tail = &remote_refs;
2316-
if (match_refs(local_refs, remote_refs, &remote_tail,
2313+
if (match_refs(local_refs, &remote_refs,
23172314
nr_refspec, (const char **) refspec, push_all)) {
23182315
rc = -1;
23192316
goto cleanup;

Diff for: remote.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -1085,26 +1085,35 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,
10851085
return NULL;
10861086
}
10871087

1088+
static struct ref **tail_ref(struct ref **head)
1089+
{
1090+
struct ref **tail = head;
1091+
while (*tail)
1092+
tail = &((*tail)->next);
1093+
return tail;
1094+
}
1095+
10881096
/*
10891097
* Note. This is used only by "push"; refspec matching rules for
10901098
* push and fetch are subtly different, so do not try to reuse it
10911099
* without thinking.
10921100
*/
1093-
int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
1101+
int match_refs(struct ref *src, struct ref **dst,
10941102
int nr_refspec, const char **refspec, int flags)
10951103
{
10961104
struct refspec *rs;
10971105
int send_all = flags & MATCH_REFS_ALL;
10981106
int send_mirror = flags & MATCH_REFS_MIRROR;
10991107
int errs;
11001108
static const char *default_refspec[] = { ":", 0 };
1109+
struct ref **dst_tail = tail_ref(dst);
11011110

11021111
if (!nr_refspec) {
11031112
nr_refspec = 1;
11041113
refspec = default_refspec;
11051114
}
11061115
rs = parse_push_refspec(nr_refspec, (const char **) refspec);
1107-
errs = match_explicit_refs(src, dst, dst_tail, rs, nr_refspec);
1116+
errs = match_explicit_refs(src, *dst, &dst_tail, rs, nr_refspec);
11081117

11091118
/* pick the remainder */
11101119
for ( ; src; src = src->next) {
@@ -1134,7 +1143,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
11341143
dst_side, &dst_name))
11351144
die("Didn't think it matches any more");
11361145
}
1137-
dst_peer = find_ref_by_name(dst, dst_name);
1146+
dst_peer = find_ref_by_name(*dst, dst_name);
11381147
if (dst_peer) {
11391148
if (dst_peer->peer_ref)
11401149
/* We're already sending something to this ref. */
@@ -1150,7 +1159,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
11501159
goto free_name;
11511160

11521161
/* Create a new one and link it */
1153-
dst_peer = make_linked_ref(dst_name, dst_tail);
1162+
dst_peer = make_linked_ref(dst_name, &dst_tail);
11541163
hashcpy(dst_peer->new_sha1, src->new_sha1);
11551164
}
11561165
dst_peer->peer_ref = copy_ref(src);

Diff for: remote.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void ref_remove_duplicates(struct ref *ref_map);
8585
int valid_fetch_refspec(const char *refspec);
8686
struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
8787

88-
int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
88+
int match_refs(struct ref *src, struct ref **dst,
8989
int nr_refspec, const char **refspec, int all);
9090

9191
/*

Diff for: transport.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,6 @@ int transport_push(struct transport *transport,
10031003
if (transport->push_refs) {
10041004
struct ref *remote_refs =
10051005
transport->get_refs_list(transport, 1);
1006-
struct ref **remote_tail;
10071006
struct ref *local_refs = get_local_heads();
10081007
int match_flags = MATCH_REFS_NONE;
10091008
int verbose = flags & TRANSPORT_PUSH_VERBOSE;
@@ -1014,10 +1013,7 @@ int transport_push(struct transport *transport,
10141013
if (flags & TRANSPORT_PUSH_MIRROR)
10151014
match_flags |= MATCH_REFS_MIRROR;
10161015

1017-
remote_tail = &remote_refs;
1018-
while (*remote_tail)
1019-
remote_tail = &((*remote_tail)->next);
1020-
if (match_refs(local_refs, remote_refs, &remote_tail,
1016+
if (match_refs(local_refs, &remote_refs,
10211017
refspec_nr, refspec, match_flags)) {
10221018
return -1;
10231019
}

0 commit comments

Comments
 (0)