Skip to content

Commit d1a0ed1

Browse files
committed
index-pack: show histogram when emulating "verify-pack -v"
The histogram produced by "verify-pack -v" always had an artificial limit of 50, but index-pack knows what the maximum delta depth is, so we do not have to limit it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 38a4556 commit d1a0ed1

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

builtin/index-pack.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static struct progress *progress;
7070
static unsigned char input_buffer[4096];
7171
static unsigned int input_offset, input_len;
7272
static off_t consumed_bytes;
73+
static unsigned deepest_delta;
7374
static git_SHA_CTX input_ctx;
7475
static uint32_t input_crc32;
7576
static int input_fd, output_fd, pack_fd;
@@ -538,6 +539,8 @@ static void resolve_delta(struct object_entry *delta_obj,
538539

539540
delta_obj->real_type = base->obj->real_type;
540541
delta_obj->delta_depth = base->obj->delta_depth + 1;
542+
if (deepest_delta < delta_obj->delta_depth)
543+
deepest_delta = delta_obj->delta_depth;
541544
delta_obj->base_object_no = base->obj - objects;
542545
delta_data = get_data_from_pack(delta_obj);
543546
base_data = get_base_data(base);
@@ -973,12 +976,17 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
973976

974977
static void show_pack_info(int stat_only)
975978
{
976-
int i;
979+
int i, baseobjects = nr_objects - nr_deltas;
980+
unsigned long *chain_histogram = NULL;
981+
982+
if (deepest_delta)
983+
chain_histogram = xcalloc(deepest_delta, sizeof(unsigned long));
984+
977985
for (i = 0; i < nr_objects; i++) {
978986
struct object_entry *obj = &objects[i];
979987

980-
/* NEEDSWORK: Compute data necessary for the "histogram" here */
981-
988+
if (is_delta_type(obj->type))
989+
chain_histogram[obj->delta_depth - 1]++;
982990
if (stat_only)
983991
continue;
984992
printf("%s %-6s %lu %lu %"PRIuMAX,
@@ -992,6 +1000,18 @@ static void show_pack_info(int stat_only)
9921000
}
9931001
putchar('\n');
9941002
}
1003+
1004+
if (baseobjects)
1005+
printf("non delta: %d object%s\n",
1006+
baseobjects, baseobjects > 1 ? "s" : "");
1007+
for (i = 0; i < deepest_delta; i++) {
1008+
if (!chain_histogram[i])
1009+
continue;
1010+
printf("chain length = %d: %lu object%s\n",
1011+
i + 1,
1012+
chain_histogram[i],
1013+
chain_histogram[i] > 1 ? "s" : "");
1014+
}
9951015
}
9961016

9971017
int cmd_index_pack(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)