@matheusbsbs / matheus-bagliano / commits / 6d2bf96e55
Fork 0

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 <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed May 31, 2009 at 16:26 UTC 6d2bf96e550731499c73731e5623017d193f837f
6 files changed +23 -29
builtin-remote.c
+2 -5
@@ -294,17 +294,14 @@ static int get_push_ref_states(const struct ref *remote_refs,
294 struct ref_states *states)
295 {
296 struct remote *remote = states->remote;
297 - struct ref *ref, *local_refs, *push_map, **push_tail;
297 + struct ref *ref, *local_refs, *push_map;
298 if (remote->mirror)
299 return 0;
300
301 local_refs = get_local_heads();
302 push_map = copy_ref_list(remote_refs);
303
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,
305 remote->push_refspec, MATCH_REFS_NONE);
306
307 states->push.strdup_strings = 1;
builtin-send-pack.c
+2 -7
@@ -473,7 +473,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
473 int fd[2];
474 struct child_process *conn;
475 struct extra_have_objects extra_have;
476 - struct ref *remote_refs, **remote_tail, *local_refs;
476 + struct ref *remote_refs, *local_refs;
477 int ret;
478 int send_all = 0;
479 const char *receivepack = "git-receive-pack";
@@ -567,13 +567,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
567 flags |= MATCH_REFS_MIRROR;
568
569 /* 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))
571 return -1;
576 - }
572
573 ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
574
http-push.c
+4 -7
@@ -1844,7 +1844,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
1844 return 1;
1845 }
1846
1847 -static struct ref *remote_refs, **remote_tail;
1847 +static struct ref *remote_refs;
1848
1849 static void one_remote_ref(char *refname)
1850 {
@@ -1874,13 +1874,12 @@ static void one_remote_ref(char *refname)
1874 }
1875 }
1876
1877 - *remote_tail = ref;
1878 - remote_tail = &ref->next;
1877 + ref->next = remote_refs;
1878 + remote_refs = ref;
1879 }
1880
1881 static void get_dav_remote_heads(void)
1882 {
1883 - remote_tail = &remote_refs;
1883 remote_ls("refs/", (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL);
1884 }
1885
@@ -2311,9 +2310,7 @@ int main(int argc, char **argv)
2310 }
2311
2312 /* 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,
2314 nr_refspec, (const char **) refspec, push_all)) {
2315 rc = -1;
2316 goto cleanup;
remote.c
+13 -4
@@ -1085,12 +1085,20 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,
1085 return NULL;
1086 }
1087
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 +
1096 /*
1097 * Note. This is used only by "push"; refspec matching rules for
1098 * push and fetch are subtly different, so do not try to reuse it
1099 * without thinking.
1100 */
1093 -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
1101 +int match_refs(struct ref *src, struct ref **dst,
1102 int nr_refspec, const char **refspec, int flags)
1103 {
1104 struct refspec *rs;
@@ -1098,13 +1106,14 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
1106 int send_mirror = flags & MATCH_REFS_MIRROR;
1107 int errs;
1108 static const char *default_refspec[] = { ":", 0 };
1109 + struct ref **dst_tail = tail_ref(dst);
1110
1111 if (!nr_refspec) {
1112 nr_refspec = 1;
1113 refspec = default_refspec;
1114 }
1115 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);
1117
1118 /* pick the remainder */
1119 for ( ; src; src = src->next) {
@@ -1134,7 +1143,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
1143 dst_side, &dst_name))
1144 die("Didn't think it matches any more");
1145 }
1137 - dst_peer = find_ref_by_name(dst, dst_name);
1146 + dst_peer = find_ref_by_name(*dst, dst_name);
1147 if (dst_peer) {
1148 if (dst_peer->peer_ref)
1149 /* 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,
1159 goto free_name;
1160
1161 /* 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);
1163 hashcpy(dst_peer->new_sha1, src->new_sha1);
1164 }
1165 dst_peer->peer_ref = copy_ref(src);
remote.h
+1 -1
@@ -85,7 +85,7 @@ void ref_remove_duplicates(struct ref *ref_map);
85 int valid_fetch_refspec(const char *refspec);
86 struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
87
88 -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
88 +int match_refs(struct ref *src, struct ref **dst,
89 int nr_refspec, const char **refspec, int all);
90
91 /*
transport.c
+1 -5
@@ -1003,7 +1003,6 @@ int transport_push(struct transport *transport,
1003 if (transport->push_refs) {
1004 struct ref *remote_refs =
1005 transport->get_refs_list(transport, 1);
1006 - struct ref **remote_tail;
1006 struct ref *local_refs = get_local_heads();
1007 int match_flags = MATCH_REFS_NONE;
1008 int verbose = flags & TRANSPORT_PUSH_VERBOSE;
@@ -1014,10 +1013,7 @@ int transport_push(struct transport *transport,
1013 if (flags & TRANSPORT_PUSH_MIRROR)
1014 match_flags |= MATCH_REFS_MIRROR;
1015
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,
1017 refspec_nr, refspec, match_flags)) {
1018 return -1;
1019 }