Skip to content

Commit 7fab474

Browse files
committed
Merge branch 'cc/delta-islands'
A few issues in the implementation of "delta-islands" feature has been corrected. * cc/delta-islands: pack-objects: fix off-by-one in delta-island tree-depth computation pack-objects: zero-initialize tree_depth/layer arrays pack-objects: fix tree_depth and layer invariants
2 parents fde566f + 3949053 commit 7fab474

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

builtin/pack-objects.c

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

27872787
if (use_delta_islands) {
27882788
const char *p;
2789-
unsigned depth = 0;
2789+
unsigned depth;
27902790
struct object_entry *ent;
27912791

2792+
/* the empty string is a root tree, which is depth 0 */
2793+
depth = *name ? 1 : 0;
27922794
for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
27932795
depth++;
27942796

git-compat-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ extern FILE *fopen_or_warn(const char *path, const char *mode);
861861
#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)
862862

863863
#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
864+
#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)));
864865
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
865866

866867
#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \

pack-objects.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static inline void oe_set_tree_depth(struct packing_data *pack,
412412
unsigned int tree_depth)
413413
{
414414
if (!pack->tree_depth)
415-
ALLOC_ARRAY(pack->tree_depth, pack->nr_objects);
415+
CALLOC_ARRAY(pack->tree_depth, pack->nr_alloc);
416416
pack->tree_depth[e - pack->objects] = tree_depth;
417417
}
418418

@@ -429,7 +429,7 @@ static inline void oe_set_layer(struct packing_data *pack,
429429
unsigned char layer)
430430
{
431431
if (!pack->layer)
432-
ALLOC_ARRAY(pack->layer, pack->nr_objects);
432+
CALLOC_ARRAY(pack->layer, pack->nr_alloc);
433433
pack->layer[e - pack->objects] = layer;
434434
}
435435

0 commit comments

Comments
 (0)