Skip to content

Commit 3f1da57

Browse files
committed
upload-pack: simplify request validation
Long time ago, we used to punt on a large (read: asking for more than 256 refs) fetch request and instead sent a full pack, because we couldn't fit many refs on the command line of rev-list we run internally to enumerate the objects to be sent. To fix this, 565ebbf (upload-pack: tighten request validation., 2005-10-24), added a check to count the number of refs in the request and matched with the number of refs we advertised, and changed the invocation of rev-list to pass "--all" to it, still keeping us under the command line argument limit. However, these days we feed the list of objects requested and the list of objects the other end is known to have via standard input, so there is no longer a valid reason to special case a full clone request. Remove the code associated with "create_full_pack" to simplify the logic. Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbbe50d commit 3f1da57

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

upload-pack.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<
2828

2929
static unsigned long oldest_have;
3030

31-
static int multi_ack, nr_our_refs;
31+
static int multi_ack;
3232
static int no_done;
3333
static int use_thin_pack, use_ofs_delta, use_include_tag;
3434
static int no_progress, daemon_mode;
@@ -139,7 +139,6 @@ static void create_pack_file(void)
139139
{
140140
struct async rev_list;
141141
struct child_process pack_objects;
142-
int create_full_pack = (nr_our_refs == want_obj.nr && !have_obj.nr);
143142
char data[8193], progress[128];
144143
char abort_msg[] = "aborting due to possible repository "
145144
"corruption on the remote side.";
@@ -151,9 +150,7 @@ static void create_pack_file(void)
151150
argv[arg++] = "pack-objects";
152151
if (!shallow_nr) {
153152
argv[arg++] = "--revs";
154-
if (create_full_pack)
155-
argv[arg++] = "--all";
156-
else if (use_thin_pack)
153+
if (use_thin_pack)
157154
argv[arg++] = "--thin";
158155
}
159156

@@ -185,15 +182,15 @@ static void create_pack_file(void)
185182
}
186183
else {
187184
FILE *pipe_fd = xfdopen(pack_objects.in, "w");
188-
if (!create_full_pack) {
189-
int i;
190-
for (i = 0; i < want_obj.nr; i++)
191-
fprintf(pipe_fd, "%s\n", sha1_to_hex(want_obj.objects[i].item->sha1));
192-
fprintf(pipe_fd, "--not\n");
193-
for (i = 0; i < have_obj.nr; i++)
194-
fprintf(pipe_fd, "%s\n", sha1_to_hex(have_obj.objects[i].item->sha1));
195-
}
185+
int i;
196186

187+
for (i = 0; i < want_obj.nr; i++)
188+
fprintf(pipe_fd, "%s\n",
189+
sha1_to_hex(want_obj.objects[i].item->sha1));
190+
fprintf(pipe_fd, "--not\n");
191+
for (i = 0; i < have_obj.nr; i++)
192+
fprintf(pipe_fd, "%s\n",
193+
sha1_to_hex(have_obj.objects[i].item->sha1));
197194
fprintf(pipe_fd, "\n");
198195
fflush(pipe_fd);
199196
fclose(pipe_fd);
@@ -727,10 +724,7 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag
727724
struct object *o = lookup_unknown_object(sha1);
728725
if (!o)
729726
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
730-
if (!(o->flags & OUR_REF)) {
731-
o->flags |= OUR_REF;
732-
nr_our_refs++;
733-
}
727+
o->flags |= OUR_REF;
734728
return 0;
735729
}
736730

0 commit comments

Comments
 (0)