Skip to content

Commit 3949053

Browse files
peffgitster
authored andcommitted
pack-objects: fix off-by-one in delta-island tree-depth computation
When delta-islands are in use, we need to record the deepest path at which we find each tree and blob. Our loop to do so counts slashes, so "foo" is depth 0, "foo/bar" is depth 1, and so on. However, this neglects root trees, which are represented by the empty string. Those also have depth 0, but are at a layer above "foo". Thus, "foo" should be 1, "foo/bar" at 2, and so on. We use this depth to topo-sort the trees in resolve_tree_islands(). As a result, we may fail to visit a root tree before the sub-trees it contains, and therefore not correctly pass down the island marks. That in turn could lead to missing some delta opportunities (objects are in the same island, but we didn't realize it) or creating unwanted cross-island deltas (one object is in an island another isn't, but we don't realize). In practice, it seems to have only a small effect. Some experiments on the real-world git/git fork network at GitHub showed an improvement of only 0.14% in the resulting clone size. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e159b81 commit 3949053

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,9 +2709,11 @@ static void show_object(struct object *obj, const char *name, void *data)
27092709

27102710
if (use_delta_islands) {
27112711
const char *p;
2712-
unsigned depth = 0;
2712+
unsigned depth;
27132713
struct object_entry *ent;
27142714

2715+
/* the empty string is a root tree, which is depth 0 */
2716+
depth = *name ? 1 : 0;
27152717
for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
27162718
depth++;
27172719

0 commit comments

Comments
 (0)