verify-pack --stat-only: show histogram without verifying
When this option is given, the command does not verify the pack contents, but shows the delta chain histogram. If used with --verbose, the usual list of objects is also shown. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 7, 2009 at 15:45 UTC
6c4f3ec9b477df534cd376f88618a57353f0f0fe
2 files changed
+40
-17
Documentation/git-verify-pack.txt
+7
-1
@@ -25,7 +25,13 @@ OPTIONS
25
-v::
26
--verbose::
27
After verifying the pack, show list of objects contained
28
- in the pack.
28
+ in the pack and a histogram of delta chain length.
29
+
30
+-s::
31
+--stat-only::
32
+ Do not verify the pack contents; only show the histogram of delta
33
+ chain length. With `--verbose`, list of objects is also shown.
34
+
35
\--::
36
Do not interpret any more arguments as options.
37
builtin-verify-pack.c
+33
-16
@@ -6,10 +6,14 @@
6
7
#define MAX_CHAIN 50
8
9
-static void show_pack_info(struct packed_git *p)
9
+#define VERIFY_PACK_VERBOSE 01
10
+#define VERIFY_PACK_STAT_ONLY 02
11
+
12
+static void show_pack_info(struct packed_git *p, unsigned int flags)
13
{
14
uint32_t nr_objects, i;
15
int cnt;
16
+ int stat_only = flags & VERIFY_PACK_STAT_ONLY;
17
unsigned long chain_histogram[MAX_CHAIN+1], baseobjects;
18
19
nr_objects = p->num_objects;
@@ -32,16 +36,19 @@ static void show_pack_info(struct packed_git *p)
36
type = packed_object_info_detail(p, offset, &size, &store_size,
37
&delta_chain_length,
38
base_sha1);
35
- printf("%s ", sha1_to_hex(sha1));
39
+ if (!stat_only)
40
+ printf("%s ", sha1_to_hex(sha1));
41
if (!delta_chain_length) {
37
- printf("%-6s %lu %lu %"PRIuMAX"\n",
38
- type, size, store_size, (uintmax_t)offset);
42
+ if (!stat_only)
43
+ printf("%-6s %lu %lu %"PRIuMAX"\n",
44
+ type, size, store_size, (uintmax_t)offset);
45
baseobjects++;
46
}
47
else {
42
- printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
43
- type, size, store_size, (uintmax_t)offset,
44
- delta_chain_length, sha1_to_hex(base_sha1));
48
+ if (!stat_only)
49
+ printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
50
+ type, size, store_size, (uintmax_t)offset,
51
+ delta_chain_length, sha1_to_hex(base_sha1));
52
if (delta_chain_length <= MAX_CHAIN)
53
chain_histogram[delta_chain_length]++;
54
else
@@ -66,10 +73,12 @@ static void show_pack_info(struct packed_git *p)
73
chain_histogram[0] > 1 ? "s" : "");
74
}
75
69
-static int verify_one_pack(const char *path, int verbose)
76
+static int verify_one_pack(const char *path, unsigned int flags)
77
{
78
char arg[PATH_MAX];
79
int len;
80
+ int verbose = flags & VERIFY_PACK_VERBOSE;
81
+ int stat_only = flags & VERIFY_PACK_STAT_ONLY;
82
struct packed_git *pack;
83
int err;
84
@@ -105,14 +114,19 @@ static int verify_one_pack(const char *path, int verbose)
114
return error("packfile %s not found.", arg);
115
116
install_packed_git(pack);
108
- err = verify_pack(pack);
117
110
- if (verbose) {
118
+ if (!stat_only)
119
+ err = verify_pack(pack);
120
+ else
121
+ err = open_pack_index(pack);
122
+
123
+ if (verbose || stat_only) {
124
if (err)
125
printf("%s: bad\n", pack->pack_name);
126
else {
114
- show_pack_info(pack);
115
- printf("%s: ok\n", pack->pack_name);
127
+ show_pack_info(pack, flags);
128
+ if (!stat_only)
129
+ printf("%s: ok\n", pack->pack_name);
130
}
131
}
132
@@ -120,17 +134,20 @@ static int verify_one_pack(const char *path, int verbose)
134
}
135
136
static const char * const verify_pack_usage[] = {
123
- "git verify-pack [-v|--verbose] <pack>...",
137
+ "git verify-pack [-v|--verbose] [-s|--stat-only] <pack>...",
138
NULL
139
};
140
141
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
142
{
143
int err = 0;
130
- int verbose = 0;
144
+ unsigned int flags = 0;
145
int i;
146
const struct option verify_pack_options[] = {
133
- OPT__VERBOSE(&verbose),
147
+ OPT_BIT('v', "verbose", &flags, "verbose",
148
+ VERIFY_PACK_VERBOSE),
149
+ OPT_BIT('s', "stat-only", &flags, "show statistics only",
150
+ VERIFY_PACK_STAT_ONLY),
151
OPT_END()
152
};
153
@@ -140,7 +157,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
157
if (argc < 1)
158
usage_with_options(verify_pack_usage, verify_pack_options);
159
for (i = 0; i < argc; i++) {
143
- if (verify_one_pack(argv[i], verbose))
160
+ if (verify_one_pack(argv[i], flags))
161
err = 1;
162
discard_revindex();
163
}