@matheusbsbs / matheus-bagliano / commits / 797656e58d
Fork 0

send-pack: do not give up when remote has insanely large number of refs.

Stephen C. Tweedie noticed that we give up running rev-list when we see too many refs on the remote side. Limit the number of negative references we give to rev-list and continue. Not sending any negative references to rev-list is very bad -- we may be pushing a ref that is new to the other end. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 21, 2006 at 18:59 UTC 797656e58ddbd82ac461a5142ed726db3a4d0ac0
1 file changed +28 -10
send-pack.c
+28 -10
@@ -37,26 +37,44 @@ static void exec_pack_objects(void)
37
38 static void exec_rev_list(struct ref *refs)
39 {
40 + struct ref *ref;
41 static char *args[1000];
41 - int i = 0;
42 + int i = 0, j;
43
44 args[i++] = "rev-list"; /* 0 */
45 args[i++] = "--objects"; /* 1 */
45 - while (refs) {
46 - char *buf = malloc(100);
47 - if (i > 900)
46 +
47 + /* First send the ones we care about most */
48 + for (ref = refs; ref; ref = ref->next) {
49 + if (900 < i)
50 die("git-rev-list environment overflow");
49 - if (!is_zero_sha1(refs->old_sha1) &&
50 - has_sha1_file(refs->old_sha1)) {
51 + if (!is_zero_sha1(ref->new_sha1)) {
52 + char *buf = malloc(100);
53 args[i++] = buf;
52 - snprintf(buf, 50, "^%s", sha1_to_hex(refs->old_sha1));
54 + snprintf(buf, 50, "%s", sha1_to_hex(ref->new_sha1));
55 buf += 50;
56 + if (!is_zero_sha1(ref->old_sha1) &&
57 + has_sha1_file(ref->old_sha1)) {
58 + args[i++] = buf;
59 + snprintf(buf, 50, "^%s",
60 + sha1_to_hex(ref->old_sha1));
61 + }
62 }
55 - if (!is_zero_sha1(refs->new_sha1)) {
63 + }
64 +
65 + /* Then a handful of the remainder
66 + * NEEDSWORK: we would be better off if used the newer ones first.
67 + */
68 + for (ref = refs, j = i + 16;
69 + i < 900 && i < j && ref;
70 + ref = ref->next) {
71 + if (is_zero_sha1(ref->new_sha1) &&
72 + !is_zero_sha1(ref->old_sha1) &&
73 + has_sha1_file(ref->old_sha1)) {
74 + char *buf = malloc(42);
75 args[i++] = buf;
57 - snprintf(buf, 50, "%s", sha1_to_hex(refs->new_sha1));
76 + snprintf(buf, 42, "^%s", sha1_to_hex(ref->old_sha1));
77 }
59 - refs = refs->next;
78 }
79 args[i] = NULL;
80 execv_git_cmd(args);