Skip to content

Commit df85f78

Browse files
committed
Merge branch 'sp/missing-thin-base' into maint
* sp/missing-thin-base: pack-objects: Allow missing base objects when creating thin packs
2 parents 014aff7 + 6d6f9cd commit df85f78

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

builtin-pack-objects.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,12 @@ static void check_object(struct object_entry *entry)
10951095
}
10961096

10971097
entry->type = sha1_object_info(entry->idx.sha1, &entry->size);
1098-
if (entry->type < 0)
1099-
die("unable to get type of object %s",
1100-
sha1_to_hex(entry->idx.sha1));
1098+
/*
1099+
* The error condition is checked in prepare_pack(). This is
1100+
* to permit a missing preferred base object to be ignored
1101+
* as a preferred base. Doing so can result in a larger
1102+
* pack file, but the transfer will still take place.
1103+
*/
11011104
}
11021105

11031106
static int pack_offset_sort(const void *_a, const void *_b)
@@ -1721,8 +1724,12 @@ static void prepare_pack(int window, int depth)
17211724
if (entry->no_try_delta)
17221725
continue;
17231726

1724-
if (!entry->preferred_base)
1727+
if (!entry->preferred_base) {
17251728
nr_deltas++;
1729+
if (entry->type < 0)
1730+
die("unable to get type of object %s",
1731+
sha1_to_hex(entry->idx.sha1));
1732+
}
17261733

17271734
delta_list[n++] = entry;
17281735
}

t/t5306-pack-nobase.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Google Inc.
4+
#
5+
6+
test_description='git-pack-object with missing base
7+
8+
'
9+
. ./test-lib.sh
10+
11+
# Create A-B chain
12+
#
13+
test_expect_success \
14+
'setup base' \
15+
'for a in a b c d e f g h i; do echo $a >>text; done &&
16+
echo side >side &&
17+
git update-index --add text side &&
18+
A=$(echo A | git commit-tree $(git write-tree)) &&
19+
20+
echo m >>text &&
21+
git update-index text &&
22+
B=$(echo B | git commit-tree $(git write-tree) -p $A) &&
23+
git update-ref HEAD $B
24+
'
25+
26+
# Create repository with C whose parent is B.
27+
# Repository contains C, C^{tree}, C:text, B, B^{tree}.
28+
# Repository is missing B:text (best delta base for C:text).
29+
# Repository is missing A (parent of B).
30+
# Repository is missing A:side.
31+
#
32+
test_expect_success \
33+
'setup patch_clone' \
34+
'base_objects=$(pwd)/.git/objects &&
35+
(mkdir patch_clone &&
36+
cd patch_clone &&
37+
git init &&
38+
echo "$base_objects" >.git/objects/info/alternates &&
39+
echo q >>text &&
40+
git read-tree $B &&
41+
git update-index text &&
42+
git update-ref HEAD $(echo C | git commit-tree $(git write-tree) -p $B) &&
43+
rm .git/objects/info/alternates &&
44+
45+
git --git-dir=../.git cat-file commit $B |
46+
git hash-object -t commit -w --stdin &&
47+
48+
git --git-dir=../.git cat-file tree "$B^{tree}" |
49+
git hash-object -t tree -w --stdin
50+
) &&
51+
C=$(git --git-dir=patch_clone/.git rev-parse HEAD)
52+
'
53+
54+
# Clone patch_clone indirectly by cloning base and fetching.
55+
#
56+
test_expect_success \
57+
'indirectly clone patch_clone' \
58+
'(mkdir user_clone &&
59+
cd user_clone &&
60+
git init &&
61+
git pull ../.git &&
62+
test $(git rev-parse HEAD) = $B &&
63+
64+
git pull ../patch_clone/.git &&
65+
test $(git rev-parse HEAD) = $C
66+
)
67+
'
68+
69+
# Cloning the patch_clone directly should fail.
70+
#
71+
test_expect_success \
72+
'clone of patch_clone is incomplete' \
73+
'(mkdir user_direct &&
74+
cd user_direct &&
75+
git init &&
76+
test_must_fail git fetch ../patch_clone/.git
77+
)
78+
'
79+
80+
test_done

0 commit comments

Comments
 (0)