Skip to content

Commit 06f15bf

Browse files
peffgitster
authored andcommitted
upload-pack: make sure "want" objects are parsed
When upload-pack receives a "want" line from the client, it adds it to an object array. We call lookup_object to find the actual object, which will only check for objects already in memory. This works because we are expecting to find objects that we already loaded during the ref advertisement. We use the resulting object structs for a variety of purposes. Some of them care only about the object flags, but others care about the type of the object (e.g., ok_to_give_up), or even feed them to the revision parser (when --depth is used), which assumes that objects it receives are fully parsed. Once upon a time, this was OK; any object we loaded into memory would also have been parsed. But since 435c833 (upload-pack: use peel_ref for ref advertisements, 2012-10-04), we try to avoid parsing objects during the ref advertisement. This means that lookup_object may return an object with a type of OBJ_NONE. The resulting mess depends on the exact set of objects, but can include the revision parser barfing, or the shallow code sending the wrong set of objects. This patch teaches upload-pack to parse each "want" object as we receive it. We do not replace the lookup_object call with parse_object, as the current code is careful not to let just any object appear on a "want" line, but rather only one we have previously advertised (whereas parse_object would actually load any arbitrary object from disk). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a6eec12 commit 06f15bf

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

t/t5500-fetch-pack.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ EOF
331331
test_cmp count7.expected count7.actual
332332
'
333333

334+
test_expect_success 'clone shallow with packed refs' '
335+
git pack-refs --all &&
336+
git clone --depth 1 --branch A "file://$(pwd)/." shallow8 &&
337+
echo "in-pack: 4" > count8.expected &&
338+
GIT_DIR=shallow8/.git git count-objects -v |
339+
grep "^in-pack" > count8.actual &&
340+
test_cmp count8.expected count8.actual
341+
'
342+
334343
test_expect_success 'setup tests for the --stdin parameter' '
335344
for head in C D E F
336345
do

upload-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static void receive_needs(void)
639639
use_include_tag = 1;
640640

641641
o = lookup_object(sha1_buf);
642-
if (!o)
642+
if (!o || !parse_object(o->sha1))
643643
die("git upload-pack: not our ref %s",
644644
sha1_to_hex(sha1_buf));
645645
if (!(o->flags & WANTED)) {

0 commit comments

Comments
 (0)