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 <gitster@pobox.com>
Junio C Hamano committed
Jun 3, 2011 at 15:32 UTC
38a4556198de17156f27f0463161a4d1b5e11555
1 file changed
+40
-3
builtin/index-pack.c
+40
-3
@@ -20,6 +20,8 @@ struct object_entry
20
unsigned int hdr_size;
21
enum object_type type;
22
enum object_type real_type;
23
+ unsigned delta_depth;
24
+ int base_object_no;
25
};
26
27
union delta_base {
@@ -535,6 +537,8 @@ static void resolve_delta(struct object_entry *delta_obj,
537
void *base_data, *delta_data;
538
539
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;
542
delta_data = get_data_from_pack(delta_obj);
543
base_data = get_base_data(base);
544
result->obj = delta_obj;
@@ -967,9 +971,32 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
971
free(p);
972
}
973
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
+
997
int cmd_index_pack(int argc, const char **argv, const char *prefix)
998
{
972
- int i, fix_thin_pack = 0, verify = 0;
999
+ int i, fix_thin_pack = 0, verify = 0, stat_only = 0, stat = 0;
1000
const char *curr_pack, *curr_index;
1001
const char *index_name = NULL, *pack_name = NULL;
1002
const char *keep_name = NULL, *keep_msg = NULL;
@@ -1000,6 +1027,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1027
strict = 1;
1028
} else if (!strcmp(arg, "--verify")) {
1029
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;
1037
} else if (!strcmp(arg, "--keep")) {
1038
keep_msg = "";
1039
} else if (!prefixcmp(arg, "--keep=")) {
@@ -1075,8 +1109,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1109
1110
curr_pack = open_pack_file(pack_name);
1111
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));
1114
parse_pack_objects(pack_sha1);
1115
if (nr_deltas == nr_resolved_deltas) {
1116
stop_progress(&progress);
@@ -1116,6 +1150,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1150
if (strict)
1151
check_objects();
1152
1153
+ if (stat)
1154
+ show_pack_info(stat_only);
1155
+
1156
idx_objects = xmalloc((nr_objects) * sizeof(struct pack_idx_entry *));
1157
for (i = 0; i < nr_objects; i++)
1158
idx_objects[i] = &objects[i].idx;