Skip to content

Commit f0cea83

Browse files
sirnotgitster
authored andcommitted
Shift object enumeration out of upload-pack
Offload object enumeration in upload-pack to pack-objects, but fall back on internal revision walker for shallow interaction. Aside from architecturally making more sense, this also leaves the door open for pack-objects to employ a revision cache mechanism. Test t5530 updated in order to explicitly check both enumeration methods. Signed-off-by: Nick Edelen <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4f78e6 commit f0cea83

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

t/t5530-upload-pack-error.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ test_expect_success 'fsck fails' '
3030
test_must_fail git fsck
3131
'
3232

33-
test_expect_success 'upload-pack fails due to error in pack-objects' '
33+
test_expect_success 'upload-pack fails due to error in pack-objects packing' '
3434
3535
! echo "0032want $(git rev-parse HEAD)
3636
00000009done
3737
0000" | git upload-pack . > /dev/null 2> output.err &&
38+
grep "unable to read" output.err &&
3839
grep "pack-objects died" output.err
3940
'
4041

@@ -51,11 +52,20 @@ test_expect_success 'fsck fails' '
5152
test_expect_success 'upload-pack fails due to error in rev-list' '
5253
5354
! echo "0032want $(git rev-parse HEAD)
54-
00000009done
55+
0034shallow $(git rev-parse HEAD^)00000009done
5556
0000" | git upload-pack . > /dev/null 2> output.err &&
5657
grep "waitpid (async) failed" output.err
5758
'
5859

60+
test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
61+
62+
! echo "0032want $(git rev-parse HEAD)
63+
00000009done
64+
0000" | git upload-pack . > /dev/null 2> output.err &&
65+
grep "bad tree object" output.err &&
66+
grep "pack-objects died" output.err
67+
'
68+
5969
test_expect_success 'create empty repository' '
6070
6171
mkdir foo &&

upload-pack.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static unsigned long oldest_have;
2929
static int multi_ack, nr_our_refs;
3030
static int use_thin_pack, use_ofs_delta, use_include_tag;
3131
static int no_progress;
32+
static int shallow_nr;
3233
static struct object_array have_obj;
3334
static struct object_array want_obj;
3435
static unsigned int timeout;
@@ -107,8 +108,6 @@ static int do_rev_list(int fd, void *create_full_pack)
107108
struct rev_info revs;
108109

109110
pack_pipe = fdopen(fd, "w");
110-
if (create_full_pack)
111-
use_thin_pack = 0; /* no point doing it */
112111
init_revisions(&revs, NULL);
113112
revs.tag_objects = 1;
114113
revs.tree_objects = 1;
@@ -155,13 +154,21 @@ static void create_pack_file(void)
155154
const char *argv[10];
156155
int arg = 0;
157156

158-
rev_list.proc = do_rev_list;
159-
/* .data is just a boolean: any non-NULL value will do */
160-
rev_list.data = create_full_pack ? &rev_list : NULL;
161-
if (start_async(&rev_list))
162-
die("git upload-pack: unable to fork git-rev-list");
157+
if (shallow_nr) {
158+
rev_list.proc = do_rev_list;
159+
rev_list.data = 0;
160+
if (start_async(&rev_list))
161+
die("git upload-pack: unable to fork git-rev-list");
162+
argv[arg++] = "pack-objects";
163+
} else {
164+
argv[arg++] = "pack-objects";
165+
argv[arg++] = "--revs";
166+
if (create_full_pack)
167+
argv[arg++] = "--all";
168+
else if (use_thin_pack)
169+
argv[arg++] = "--thin";
170+
}
163171

164-
argv[arg++] = "pack-objects";
165172
argv[arg++] = "--stdout";
166173
if (!no_progress)
167174
argv[arg++] = "--progress";
@@ -172,7 +179,7 @@ static void create_pack_file(void)
172179
argv[arg++] = NULL;
173180

174181
memset(&pack_objects, 0, sizeof(pack_objects));
175-
pack_objects.in = rev_list.out; /* start_command closes it */
182+
pack_objects.in = shallow_nr ? rev_list.out : -1;
176183
pack_objects.out = -1;
177184
pack_objects.err = -1;
178185
pack_objects.git_cmd = 1;
@@ -181,6 +188,24 @@ static void create_pack_file(void)
181188
if (start_command(&pack_objects))
182189
die("git upload-pack: unable to fork git-pack-objects");
183190

191+
/* pass on revisions we (don't) want */
192+
if (!shallow_nr) {
193+
FILE *pipe_fd = fdopen(pack_objects.in, "w");
194+
if (!create_full_pack) {
195+
int i;
196+
for (i = 0; i < want_obj.nr; i++)
197+
fprintf(pipe_fd, "%s\n", sha1_to_hex(want_obj.objects[i].item->sha1));
198+
fprintf(pipe_fd, "--not\n");
199+
for (i = 0; i < have_obj.nr; i++)
200+
fprintf(pipe_fd, "%s\n", sha1_to_hex(have_obj.objects[i].item->sha1));
201+
}
202+
203+
fprintf(pipe_fd, "\n");
204+
fflush(pipe_fd);
205+
fclose(pipe_fd);
206+
}
207+
208+
184209
/* We read from pack_objects.err to capture stderr output for
185210
* progress bar, and pack_objects.out to capture the pack data.
186211
*/
@@ -276,7 +301,7 @@ static void create_pack_file(void)
276301
error("git upload-pack: git-pack-objects died with error.");
277302
goto fail;
278303
}
279-
if (finish_async(&rev_list))
304+
if (shallow_nr && finish_async(&rev_list))
280305
goto fail; /* error was already reported */
281306

282307
/* flush the data */
@@ -451,6 +476,7 @@ static void receive_needs(void)
451476
static char line[1000];
452477
int len, depth = 0;
453478

479+
shallow_nr = 0;
454480
if (debug_fd)
455481
write_in_full(debug_fd, "#S\n", 3);
456482
for (;;) {
@@ -534,6 +560,7 @@ static void receive_needs(void)
534560
packet_write(1, "shallow %s",
535561
sha1_to_hex(object->sha1));
536562
register_shallow(object->sha1);
563+
shallow_nr++;
537564
}
538565
result = result->next;
539566
}
@@ -567,6 +594,8 @@ static void receive_needs(void)
567594
for (i = 0; i < shallows.nr; i++)
568595
register_shallow(shallows.objects[i].item->sha1);
569596
}
597+
598+
shallow_nr += shallows.nr;
570599
free(shallows.objects);
571600
}
572601

0 commit comments

Comments
 (0)