summaryrefslogtreecommitdiff
path: root/builtin-verify-pack.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin-verify-pack.c')
-rw-r--r--builtin-verify-pack.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/builtin-verify-pack.c b/builtin-verify-pack.c
index 0ee0a9af60..b5bd28e959 100644
--- a/builtin-verify-pack.c
+++ b/builtin-verify-pack.c
@@ -2,15 +2,19 @@
#include "cache.h"
#include "pack.h"
#include "pack-revindex.h"
+#include "parse-options.h"
#define MAX_CHAIN 50
static void show_pack_info(struct packed_git *p)
{
- uint32_t nr_objects, i, chain_histogram[MAX_CHAIN+1];
+ uint32_t nr_objects, i;
+ int cnt;
+ unsigned long chain_histogram[MAX_CHAIN+1], baseobjects;
nr_objects = p->num_objects;
memset(chain_histogram, 0, sizeof(chain_histogram));
+ baseobjects = 0;
for (i = 0; i < nr_objects; i++) {
const unsigned char *sha1;
@@ -29,9 +33,11 @@ static void show_pack_info(struct packed_git *p)
&delta_chain_length,
base_sha1);
printf("%s ", sha1_to_hex(sha1));
- if (!delta_chain_length)
+ if (!delta_chain_length) {
printf("%-6s %lu %lu %"PRIuMAX"\n",
type, size, store_size, (uintmax_t)offset);
+ baseobjects++;
+ }
else {
printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
type, size, store_size, (uintmax_t)offset,
@@ -43,15 +49,21 @@ static void show_pack_info(struct packed_git *p)
}
}
- for (i = 0; i <= MAX_CHAIN; i++) {
- if (!chain_histogram[i])
+ if (baseobjects)
+ printf("non delta: %lu object%s\n",
+ baseobjects, baseobjects > 1 ? "s" : "");
+
+ for (cnt = 1; cnt <= MAX_CHAIN; cnt++) {
+ if (!chain_histogram[cnt])
continue;
- printf("chain length = %"PRIu32": %"PRIu32" object%s\n", i,
- chain_histogram[i], chain_histogram[i] > 1 ? "s" : "");
+ printf("chain length = %d: %lu object%s\n", cnt,
+ chain_histogram[cnt],
+ chain_histogram[cnt] > 1 ? "s" : "");
}
if (chain_histogram[0])
- printf("chain length > %d: %"PRIu32" object%s\n", MAX_CHAIN,
- chain_histogram[0], chain_histogram[0] > 1 ? "s" : "");
+ printf("chain length > %d: %lu object%s\n", MAX_CHAIN,
+ chain_histogram[0],
+ chain_histogram[0] > 1 ? "s" : "");
}
static int verify_one_pack(const char *path, int verbose)
@@ -107,36 +119,31 @@ static int verify_one_pack(const char *path, int verbose)
return err;
}
-static const char verify_pack_usage[] = "git verify-pack [-v] <pack>...";
+static const char * const verify_pack_usage[] = {
+ "git verify-pack [-v|--verbose] <pack>...",
+ NULL
+};
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
{
int err = 0;
int verbose = 0;
- int no_more_options = 0;
- int nothing_done = 1;
+ int i;
+ const struct option verify_pack_options[] = {
+ OPT__VERBOSE(&verbose),
+ OPT_END()
+ };
git_config(git_default_config, NULL);
- while (1 < argc) {
- if (!no_more_options && argv[1][0] == '-') {
- if (!strcmp("-v", argv[1]))
- verbose = 1;
- else if (!strcmp("--", argv[1]))
- no_more_options = 1;
- else
- usage(verify_pack_usage);
- }
- else {
- if (verify_one_pack(argv[1], verbose))
- err = 1;
- discard_revindex();
- nothing_done = 0;
- }
- argc--; argv++;
+ argc = parse_options(argc, argv, prefix, verify_pack_options,
+ verify_pack_usage, 0);
+ if (argc < 1)
+ usage_with_options(verify_pack_usage, verify_pack_options);
+ for (i = 0; i < argc; i++) {
+ if (verify_one_pack(argv[i], verbose))
+ err = 1;
+ discard_revindex();
}
- if (nothing_done)
- usage(verify_pack_usage);
-
return err;
}