@matheusbsbs / matheus-bagliano / commits / e091eb9325
Fork 0

upload-pack: Do not choke on too many heads request.

Cloning from a repository with more than 256 refs (heads and tags included) will choke, because upload-pack has a built-in limit of feeding not more than MAX_NEEDS (currently 256) heads to underlying git-rev-list. This is a problem when cloning a repository with many tags, like http://www.linux-mips.org/pub/scm/linux.git, which has 290+ tags. This commit introduces a new flag, --all, to git-rev-list, to include all refs in the repository. Updated upload-pack detects requests that ask more than MAX_NEEDS refs, and sends everything back instead. We may probably want to tweak the definitions of MAX_NEEDS and MAX_HAS, but that is a separate topic. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 5, 2005 at 14:49 UTC e091eb93258f05a58bc5d1c60f058f5f57dd92b6
3 files changed +56 -16
rev-list.c
+21
@@ -1,4 +1,5 @@
1 #include "cache.h"
2 +#include "refs.h"
3 #include "tag.h"
4 #include "commit.h"
5 #include "tree.h"
@@ -489,6 +490,22 @@ static void handle_one_commit(struct commit *com, struct commit_list **lst)
490 commit_list_insert(com, lst);
491 }
492
493 +/* for_each_ref() callback does not allow user data -- Yuck. */
494 +static struct commit_list **global_lst;
495 +
496 +static int include_one_commit(const char *path, const unsigned char *sha1)
497 +{
498 + struct commit *com = get_commit_reference(path, 0);
499 + handle_one_commit(com, global_lst);
500 + return 0;
501 +}
502 +
503 +static void handle_all(struct commit_list **lst)
504 +{
505 + global_lst = lst;
506 + for_each_ref(include_one_commit);
507 + global_lst = NULL;
508 +}
509
510 int main(int argc, char **argv)
511 {
@@ -542,6 +559,10 @@ int main(int argc, char **argv)
559 bisect_list = 1;
560 continue;
561 }
562 + if (!strcmp(arg, "--all")) {
563 + handle_all(&list);
564 + continue;
565 + }
566 if (!strcmp(arg, "--objects")) {
567 tag_objects = 1;
568 tree_objects = 1;
rev-parse.c
+1
@@ -32,6 +32,7 @@ static int revs_count = 0;
32 static int is_rev_argument(const char *arg)
33 {
34 static const char *rev_args[] = {
35 + "--all",
36 "--bisect",
37 "--header",
38 "--max-age=",
upload-pack.c
+34 -16
@@ -30,10 +30,18 @@ static void create_pack_file(void)
30
31 if (!pid) {
32 int i;
33 - int args = nr_has + nr_needs + 5;
34 - char **argv = xmalloc(args * sizeof(char *));
35 - char *buf = xmalloc(args * 45);
36 - char **p = argv;
33 + int args;
34 + char **argv;
35 + char *buf;
36 + char **p;
37 +
38 + if (MAX_NEEDS <= nr_needs)
39 + args = nr_has + 10;
40 + else
41 + args = nr_has + nr_needs + 5;
42 + argv = xmalloc(args * sizeof(char *));
43 + buf = xmalloc(args * 45);
44 + p = argv;
45
46 dup2(fd[1], 1);
47 close(0);
@@ -41,10 +49,14 @@ static void create_pack_file(void)
49 close(fd[1]);
50 *p++ = "git-rev-list";
51 *p++ = "--objects";
44 - for (i = 0; i < nr_needs; i++) {
45 - *p++ = buf;
46 - memcpy(buf, sha1_to_hex(needs_sha1[i]), 41);
47 - buf += 41;
52 + if (MAX_NEEDS <= nr_needs)
53 + *p++ = "--all";
54 + else {
55 + for (i = 0; i < nr_needs; i++) {
56 + *p++ = buf;
57 + memcpy(buf, sha1_to_hex(needs_sha1[i]), 41);
58 + buf += 41;
59 + }
60 }
61 for (i = 0; i < nr_has; i++) {
62 *p++ = buf;
@@ -129,18 +141,24 @@ static int receive_needs(void)
141
142 needs = 0;
143 for (;;) {
144 + unsigned char dummy[20], *sha1_buf;
145 len = packet_read_line(0, line, sizeof(line));
146 if (!len)
147 return needs;
148
136 - /*
137 - * This is purely theoretical right now: git-fetch-pack only
138 - * ever asks for a single HEAD
139 - */
140 - if (needs >= MAX_NEEDS)
141 - die("I'm only doing a max of %d requests", MAX_NEEDS);
142 - if (strncmp("want ", line, 5) || get_sha1_hex(line+5, needs_sha1[needs]))
143 - die("git-upload-pack: protocol error, expected to get sha, not '%s'", line);
149 + sha1_buf = dummy;
150 + if (needs == MAX_NEEDS) {
151 + fprintf(stderr,
152 + "warning: supporting only a max of %d requests. "
153 + "sending everything instead.\n",
154 + MAX_NEEDS);
155 + }
156 + else if (needs < MAX_NEEDS)
157 + sha1_buf = needs_sha1[needs];
158 +
159 + if (strncmp("want ", line, 5) || get_sha1_hex(line+5, sha1_buf))
160 + die("git-upload-pack: protocol error, "
161 + "expected to get sha, not '%s'", line);
162 needs++;
163 }
164 }