@matheusbsbs / matheus-bagliano / commits / 454e2025a9
Fork 0

move duplicated get_local_heads() to remote.c

get_local_heads() appears to have been copied from builtin-send-pack.c to http-push.c via cut and paste. This patch moves the function and its helper one_local_ref() to remote.c. The two copies of one_local_ref() were not identical. I used the more recent version from builtin-send-pack.c after confirming with Jeff King that it was an oversight that commit 30affa1e did not update both copies. This is in preparation for being able to call it from builtin-remote.c Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jay Soffian committed Feb 25, 2009 at 03:32 UTC 454e2025a933593fd751475b59cc014887b4df6d
4 files changed +31 -48
builtin-send-pack.c
+2 -27
@@ -133,33 +133,8 @@ static int ref_newer(const unsigned char *new_sha1,
133 return found;
134 }
135
136 -static struct ref *local_refs, **local_tail;
136 static struct ref *remote_refs, **remote_tail;
137
139 -static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
140 -{
141 - struct ref *ref;
142 - int len;
143 -
144 - /* we already know it starts with refs/ to get here */
145 - if (check_ref_format(refname + 5))
146 - return 0;
147 -
148 - len = strlen(refname) + 1;
149 - ref = xcalloc(1, sizeof(*ref) + len);
150 - hashcpy(ref->new_sha1, sha1);
151 - memcpy(ref->name, refname, len);
152 - *local_tail = ref;
153 - local_tail = &ref->next;
154 - return 0;
155 -}
156 -
157 -static void get_local_heads(void)
158 -{
159 - local_tail = &local_refs;
160 - for_each_ref(one_local_ref, NULL);
161 -}
162 -
138 static int receive_status(int in, struct ref *refs)
139 {
140 struct ref *hint;
@@ -387,7 +362,7 @@ static int refs_pushed(struct ref *ref)
362
363 static int do_send_pack(int in, int out, struct remote *remote, const char *dest, int nr_refspec, const char **refspec)
364 {
390 - struct ref *ref;
365 + struct ref *ref, *local_refs;
366 int new_refs;
367 int ask_for_status_report = 0;
368 int allow_deleting_refs = 0;
@@ -405,7 +380,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
380 /* No funny business with the matcher */
381 remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL,
382 &extra_have);
408 - get_local_heads();
383 + local_refs = get_local_heads();
384
385 /* Does the other end support the reporting? */
386 if (server_supports("report-status"))
http-push.c
+2 -21
@@ -1792,21 +1792,8 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
1792 return 1;
1793 }
1794
1795 -static struct ref *local_refs, **local_tail;
1795 static struct ref *remote_refs, **remote_tail;
1796
1798 -static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
1799 -{
1800 - struct ref *ref;
1801 - int len = strlen(refname) + 1;
1802 - ref = xcalloc(1, sizeof(*ref) + len);
1803 - hashcpy(ref->new_sha1, sha1);
1804 - memcpy(ref->name, refname, len);
1805 - *local_tail = ref;
1806 - local_tail = &ref->next;
1807 - return 0;
1808 -}
1809 -
1797 static void one_remote_ref(char *refname)
1798 {
1799 struct ref *ref;
@@ -1839,12 +1826,6 @@ static void one_remote_ref(char *refname)
1826 remote_tail = &ref->next;
1827 }
1828
1842 -static void get_local_heads(void)
1843 -{
1844 - local_tail = &local_refs;
1845 - for_each_ref(one_local_ref, NULL);
1846 -}
1847 -
1829 static void get_dav_remote_heads(void)
1830 {
1831 remote_tail = &remote_refs;
@@ -2195,7 +2176,7 @@ int main(int argc, char **argv)
2176 int rc = 0;
2177 int i;
2178 int new_refs;
2198 - struct ref *ref;
2179 + struct ref *ref, *local_refs;
2180 char *rewritten_url = NULL;
2181
2182 git_extract_argv0_path(argv[0]);
@@ -2302,7 +2283,7 @@ int main(int argc, char **argv)
2283 fetch_indices();
2284
2285 /* Get a list of all local and remote heads to validate refspecs */
2305 - get_local_heads();
2286 + local_refs = get_local_heads();
2287 fprintf(stderr, "Fetching remote heads...\n");
2288 get_dav_remote_heads();
2289
remote.c
+26
@@ -1376,3 +1376,29 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
1376 base, num_ours, num_theirs);
1377 return 1;
1378 }
1379 +
1380 +static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
1381 +{
1382 + struct ref ***local_tail = cb_data;
1383 + struct ref *ref;
1384 + int len;
1385 +
1386 + /* we already know it starts with refs/ to get here */
1387 + if (check_ref_format(refname + 5))
1388 + return 0;
1389 +
1390 + len = strlen(refname) + 1;
1391 + ref = xcalloc(1, sizeof(*ref) + len);
1392 + hashcpy(ref->new_sha1, sha1);
1393 + memcpy(ref->name, refname, len);
1394 + **local_tail = ref;
1395 + *local_tail = &ref->next;
1396 + return 0;
1397 +}
1398 +
1399 +struct ref *get_local_heads(void)
1400 +{
1401 + struct ref *local_refs, **local_tail = &local_refs;
1402 + for_each_ref(one_local_ref, &local_tail);
1403 + return local_refs;
1404 +}
remote.h
+1
@@ -137,4 +137,5 @@ enum match_refs_flags {
137 int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
138 int format_tracking_info(struct branch *branch, struct strbuf *sb);
139
140 +struct ref *get_local_heads(void);
141 #endif