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

upload-pack: use object pointer not copy of sha1 to keep track of has/needs.

This does not change what happens in the command in any way, but is to prepare for further work. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jul 5, 2006 at 17:41 UTC 6ece0d3030ae2dc5b49fcfcc83df4966a52e0d0b
1 file changed +10 -10
upload-pack.c
+10 -10
@@ -18,8 +18,8 @@ static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=n
18 #define MAX_NEEDS 256
19 static int nr_has = 0, nr_needs = 0, multi_ack = 0, nr_our_refs = 0;
20 static int use_thin_pack = 0;
21 -static unsigned char has_sha1[MAX_HAS][20];
22 -static unsigned char needs_sha1[MAX_NEEDS][20];
21 +static struct object *has_tip[MAX_HAS];
22 +static struct object *needs_tip[MAX_NEEDS];
23 static unsigned int timeout = 0;
24 static int use_sideband = 0;
25
@@ -119,7 +119,7 @@ static void create_pack_file(void)
119 else {
120 for (i = 0; i < nr_needs; i++) {
121 *p++ = buf;
122 - memcpy(buf, sha1_to_hex(needs_sha1[i]), 41);
122 + memcpy(buf, sha1_to_hex(needs_tip[i]->sha1), 41);
123 buf += 41;
124 }
125 }
@@ -127,7 +127,7 @@ static void create_pack_file(void)
127 for (i = 0; i < nr_has; i++) {
128 *p++ = buf;
129 *buf++ = '^';
130 - memcpy(buf, sha1_to_hex(has_sha1[i]), 41);
130 + memcpy(buf, sha1_to_hex(has_tip[i]->sha1), 41);
131 buf += 41;
132 }
133 *p++ = NULL;
@@ -336,7 +336,7 @@ static int got_sha1(char *hex, unsigned char *sha1)
336 parents = parents->next)
337 parents->item->object.flags |= THEY_HAVE;
338 }
339 - memcpy(has_sha1[nr_has++], sha1, 20);
339 + has_tip[nr_has++] = o;
340 }
341 return 1;
342 }
@@ -395,23 +395,21 @@ static int receive_needs(void)
395 needs = 0;
396 for (;;) {
397 struct object *o;
398 - unsigned char dummy[20], *sha1_buf;
398 + unsigned char sha1_buf[20];
399 len = packet_read_line(0, line, sizeof(line));
400 reset_timeout();
401 if (!len)
402 return needs;
403
404 - sha1_buf = dummy;
404 if (needs == MAX_NEEDS) {
405 fprintf(stderr,
406 "warning: supporting only a max of %d requests. "
407 "sending everything instead.\n",
408 MAX_NEEDS);
409 }
411 - else if (needs < MAX_NEEDS)
412 - sha1_buf = needs_sha1[needs];
410
414 - if (strncmp("want ", line, 5) || get_sha1_hex(line+5, sha1_buf))
411 + if (strncmp("want ", line, 5) ||
412 + get_sha1_hex(line+5, sha1_buf))
413 die("git-upload-pack: protocol error, "
414 "expected to get sha, not '%s'", line);
415 if (strstr(line+45, "multi_ack"))
@@ -434,6 +432,8 @@ static int receive_needs(void)
432 die("git-upload-pack: not our ref %s", line+5);
433 if (!(o->flags & WANTED)) {
434 o->flags |= WANTED;
435 + if (needs < MAX_NEEDS)
436 + needs_tip[needs] = o;
437 needs++;
438 }
439 }