Skip to content

Commit 38a4556

Browse files
committed
index-pack: start learning to emulate "verify-pack -v"
The "index-pack" machinery already has almost enough knowledge to produce the same output as "verify-pack -v". Fill small gaps in its bookkeeping, and teach it to show what it knows. Add a few more command line options that do not have to be advertised to the end users. They will be used internally when verify-pack calls this. The eventual goal is to remove verify-pack implementation and redo it as a thin wrapper around the index-pack, so that we can remove the rather expensive packed_object_info_detail() API. This still does not do the delta-chain-depth histogram yet but that part is easy. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f8ec74 commit 38a4556

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

builtin/index-pack.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct object_entry
2020
unsigned int hdr_size;
2121
enum object_type type;
2222
enum object_type real_type;
23+
unsigned delta_depth;
24+
int base_object_no;
2325
};
2426

2527
union delta_base {
@@ -535,6 +537,8 @@ static void resolve_delta(struct object_entry *delta_obj,
535537
void *base_data, *delta_data;
536538

537539
delta_obj->real_type = base->obj->real_type;
540+
delta_obj->delta_depth = base->obj->delta_depth + 1;
541+
delta_obj->base_object_no = base->obj - objects;
538542
delta_data = get_data_from_pack(delta_obj);
539543
base_data = get_base_data(base);
540544
result->obj = delta_obj;
@@ -967,9 +971,32 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
967971
free(p);
968972
}
969973

974+
static void show_pack_info(int stat_only)
975+
{
976+
int i;
977+
for (i = 0; i < nr_objects; i++) {
978+
struct object_entry *obj = &objects[i];
979+
980+
/* NEEDSWORK: Compute data necessary for the "histogram" here */
981+
982+
if (stat_only)
983+
continue;
984+
printf("%s %-6s %lu %lu %"PRIuMAX,
985+
sha1_to_hex(obj->idx.sha1),
986+
typename(obj->real_type), obj->size,
987+
(unsigned long)(obj[1].idx.offset - obj->idx.offset),
988+
(uintmax_t)obj->idx.offset);
989+
if (is_delta_type(obj->type)) {
990+
struct object_entry *bobj = &objects[obj->base_object_no];
991+
printf(" %u %s", obj->delta_depth, sha1_to_hex(bobj->idx.sha1));
992+
}
993+
putchar('\n');
994+
}
995+
}
996+
970997
int cmd_index_pack(int argc, const char **argv, const char *prefix)
971998
{
972-
int i, fix_thin_pack = 0, verify = 0;
999+
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, stat = 0;
9731000
const char *curr_pack, *curr_index;
9741001
const char *index_name = NULL, *pack_name = NULL;
9751002
const char *keep_name = NULL, *keep_msg = NULL;
@@ -1000,6 +1027,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
10001027
strict = 1;
10011028
} else if (!strcmp(arg, "--verify")) {
10021029
verify = 1;
1030+
} else if (!strcmp(arg, "--verify-stat")) {
1031+
verify = 1;
1032+
stat = 1;
1033+
} else if (!strcmp(arg, "--verify-stat-only")) {
1034+
verify = 1;
1035+
stat = 1;
1036+
stat_only = 1;
10031037
} else if (!strcmp(arg, "--keep")) {
10041038
keep_msg = "";
10051039
} else if (!prefixcmp(arg, "--keep=")) {
@@ -1075,8 +1109,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
10751109

10761110
curr_pack = open_pack_file(pack_name);
10771111
parse_pack_header();
1078-
objects = xmalloc((nr_objects + 1) * sizeof(struct object_entry));
1079-
deltas = xmalloc(nr_objects * sizeof(struct delta_entry));
1112+
objects = xcalloc(nr_objects + 1, sizeof(struct object_entry));
1113+
deltas = xcalloc(nr_objects, sizeof(struct delta_entry));
10801114
parse_pack_objects(pack_sha1);
10811115
if (nr_deltas == nr_resolved_deltas) {
10821116
stop_progress(&progress);
@@ -1116,6 +1150,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
11161150
if (strict)
11171151
check_objects();
11181152

1153+
if (stat)
1154+
show_pack_info(stat_only);
1155+
11191156
idx_objects = xmalloc((nr_objects) * sizeof(struct pack_idx_entry *));
11201157
for (i = 0; i < nr_objects; i++)
11211158
idx_objects[i] = &objects[i].idx;

0 commit comments

Comments
 (0)