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 <gitster@pobox.com>

Junio C Hamano committed Jun 3, 2011 at 15:32 UTC d1a0ed187cbea2941a5cc10dcc43f3a7052ce32d
1 file changed +23 -3
builtin/index-pack.c
+23 -3
@@ -70,6 +70,7 @@ static struct progress *progress;
70 static unsigned char input_buffer[4096];
71 static unsigned int input_offset, input_len;
72 static off_t consumed_bytes;
73 +static unsigned deepest_delta;
74 static git_SHA_CTX input_ctx;
75 static uint32_t input_crc32;
76 static int input_fd, output_fd, pack_fd;
@@ -538,6 +539,8 @@ static void resolve_delta(struct object_entry *delta_obj,
539
540 delta_obj->real_type = base->obj->real_type;
541 delta_obj->delta_depth = base->obj->delta_depth + 1;
542 + if (deepest_delta < delta_obj->delta_depth)
543 + deepest_delta = delta_obj->delta_depth;
544 delta_obj->base_object_no = base->obj - objects;
545 delta_data = get_data_from_pack(delta_obj);
546 base_data = get_base_data(base);
@@ -973,12 +976,17 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
976
977 static void show_pack_info(int stat_only)
978 {
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 +
985 for (i = 0; i < nr_objects; i++) {
986 struct object_entry *obj = &objects[i];
987
980 - /* NEEDSWORK: Compute data necessary for the "histogram" here */
981 -
988 + if (is_delta_type(obj->type))
989 + chain_histogram[obj->delta_depth - 1]++;
990 if (stat_only)
991 continue;
992 printf("%s %-6s %lu %lu %"PRIuMAX,
@@ -992,6 +1000,18 @@ static void show_pack_info(int stat_only)
1000 }
1001 putchar('\n');
1002 }
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 + }
1015 }
1016
1017 int cmd_index_pack(int argc, const char **argv, const char *prefix)