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

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 <sirnot@gmail.com> Acked-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nick Edelen committed Jun 10, 2009 at 01:50 UTC f0cea83f631689331fce73b51f22707e897f7939
2 files changed +51 -12
t/t5530-upload-pack-error.sh
+12 -2
@@ -30,11 +30,12 @@ test_expect_success 'fsck fails' '
30 test_must_fail git fsck
31 '
32
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' '
34
35 ! echo "0032want $(git rev-parse HEAD)
36 00000009done
37 0000" | git upload-pack . > /dev/null 2> output.err &&
38 + grep "unable to read" output.err &&
39 grep "pack-objects died" output.err
40 '
41
@@ -51,11 +52,20 @@ test_expect_success 'fsck fails' '
52 test_expect_success 'upload-pack fails due to error in rev-list' '
53
54 ! echo "0032want $(git rev-parse HEAD)
54 -00000009done
55 +0034shallow $(git rev-parse HEAD^)00000009done
56 0000" | git upload-pack . > /dev/null 2> output.err &&
57 grep "waitpid (async) failed" output.err
58 '
59
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 +
69 test_expect_success 'create empty repository' '
70
71 mkdir foo &&
upload-pack.c
+39 -10
@@ -29,6 +29,7 @@ static unsigned long oldest_have;
29 static int multi_ack, nr_our_refs;
30 static int use_thin_pack, use_ofs_delta, use_include_tag;
31 static int no_progress;
32 +static int shallow_nr;
33 static struct object_array have_obj;
34 static struct object_array want_obj;
35 static unsigned int timeout;
@@ -107,8 +108,6 @@ static int do_rev_list(int fd, void *create_full_pack)
108 struct rev_info revs;
109
110 pack_pipe = fdopen(fd, "w");
110 - if (create_full_pack)
111 - use_thin_pack = 0; /* no point doing it */
111 init_revisions(&revs, NULL);
112 revs.tag_objects = 1;
113 revs.tree_objects = 1;
@@ -155,13 +154,21 @@ static void create_pack_file(void)
154 const char *argv[10];
155 int arg = 0;
156
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 + }
171
164 - argv[arg++] = "pack-objects";
172 argv[arg++] = "--stdout";
173 if (!no_progress)
174 argv[arg++] = "--progress";
@@ -172,7 +179,7 @@ static void create_pack_file(void)
179 argv[arg++] = NULL;
180
181 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;
183 pack_objects.out = -1;
184 pack_objects.err = -1;
185 pack_objects.git_cmd = 1;
@@ -181,6 +188,24 @@ static void create_pack_file(void)
188 if (start_command(&pack_objects))
189 die("git upload-pack: unable to fork git-pack-objects");
190
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 +
209 /* We read from pack_objects.err to capture stderr output for
210 * progress bar, and pack_objects.out to capture the pack data.
211 */
@@ -276,7 +301,7 @@ static void create_pack_file(void)
301 error("git upload-pack: git-pack-objects died with error.");
302 goto fail;
303 }
279 - if (finish_async(&rev_list))
304 + if (shallow_nr && finish_async(&rev_list))
305 goto fail; /* error was already reported */
306
307 /* flush the data */
@@ -451,6 +476,7 @@ static void receive_needs(void)
476 static char line[1000];
477 int len, depth = 0;
478
479 + shallow_nr = 0;
480 if (debug_fd)
481 write_in_full(debug_fd, "#S\n", 3);
482 for (;;) {
@@ -534,6 +560,7 @@ static void receive_needs(void)
560 packet_write(1, "shallow %s",
561 sha1_to_hex(object->sha1));
562 register_shallow(object->sha1);
563 + shallow_nr++;
564 }
565 result = result->next;
566 }
@@ -567,6 +594,8 @@ static void receive_needs(void)
594 for (i = 0; i < shallows.nr; i++)
595 register_shallow(shallows.objects[i].item->sha1);
596 }
597 +
598 + shallow_nr += shallows.nr;
599 free(shallows.objects);
600 }
601