Skip to content

Commit 6d6f9cd

Browse files
spearcegitster
authored andcommitted
pack-objects: Allow missing base objects when creating thin packs
If we are building a thin pack and one of the base objects we would consider for deltification is missing its OK, the other side already has that base object. We may be able to get a delta from another object, or we can simply send the new object whole (no delta). This change allows a shallow clone to store only the objects which are unique to it, as well as the boundary commit and its trees, but avoids storing the boundary blobs. This special form of a shallow clone is able to represent just the difference between two trees. Pack objects change suggested by Nicolas Pitre. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Acked-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 04c6e9e commit 6d6f9cd

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
@@ -1096,9 +1096,12 @@ static void check_object(struct object_entry *entry)
10961096
}
10971097

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

11041107
static int pack_offset_sort(const void *_a, const void *_b)
@@ -1722,8 +1725,12 @@ static void prepare_pack(int window, int depth)
17221725
if (entry->no_try_delta)
17231726
continue;
17241727

1725-
if (!entry->preferred_base)
1728+
if (!entry->preferred_base) {
17261729
nr_deltas++;
1730+
if (entry->type < 0)
1731+
die("unable to get type of object %s",
1732+
sha1_to_hex(entry->idx.sha1));
1733+
}
17271734

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

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)