git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob c4090102a965d85aca926fc5cef7ba1f0376509e 2336 bytes (raw)
name: builtin/verify-pack.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "run-command.h"
#include "parse-options.h"

#define VERIFY_PACK_VERBOSE 01
#define VERIFY_PACK_STAT_ONLY 02

static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
{
	struct child_process index_pack = CHILD_PROCESS_INIT;
	const char *argv[] = {"index-pack", NULL, NULL, NULL, NULL };
	struct strbuf arg = STRBUF_INIT, hash_arg = STRBUF_INIT;
	int verbose = flags & VERIFY_PACK_VERBOSE;
	int stat_only = flags & VERIFY_PACK_STAT_ONLY;
	int err;
	int argno = 1;

	if (stat_only)
		argv[argno++] = "--verify-stat-only";
	else if (verbose)
		argv[argno++] = "--verify-stat";
	else
		argv[argno++] = "--verify";

	if (hash_algo) {
		strbuf_addf(&hash_arg, "--object-format=%s", hash_algo);
		argv[argno++] = hash_arg.buf;
	}

	/*
	 * In addition to "foo.pack" we accept "foo.idx" and "foo";
	 * normalize these forms to "foo.pack" for "index-pack --verify".
	 */
	strbuf_addstr(&arg, path);
	if (strbuf_strip_suffix(&arg, ".idx") ||
	    !ends_with(arg.buf, ".pack"))
		strbuf_addstr(&arg, ".pack");
	argv[argno++] = arg.buf;

	index_pack.argv = argv;
	index_pack.git_cmd = 1;

	err = run_command(&index_pack);

	if (verbose || stat_only) {
		if (err)
			printf("%s: bad\n", arg.buf);
		else {
			if (!stat_only)
				printf("%s: ok\n", arg.buf);
		}
	}
	strbuf_release(&arg);

	return err;
}

static const char * const verify_pack_usage[] = {
	N_("git verify-pack [-v | --verbose] [-s | --stat-only] <pack>..."),
	NULL
};

int cmd_verify_pack(int argc, const char **argv, const char *prefix)
{
	int err = 0;
	unsigned int flags = 0;
	const char *object_format = NULL;
	int i;
	const struct option verify_pack_options[] = {
		OPT_BIT('v', "verbose", &flags, N_("verbose"),
			VERIFY_PACK_VERBOSE),
		OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
			VERIFY_PACK_STAT_ONLY),
		OPT_STRING(0, "object-format", &object_format, N_("hash"),
			   N_("specify the hash algorithm to use")),
		OPT_END()
	};

	git_config(git_default_config, NULL);
	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], flags, object_format))
			err = 1;
	}

	return err;
}

debug log:

solving c4090102a9 ...
found c4090102a9 in https://public-inbox.org/git/20200723010943.2329634-31-sandals@crustytoothpaste.net/ ||
	https://public-inbox.org/git/20200710024728.3100527-31-sandals@crustytoothpaste.net/ ||
	https://public-inbox.org/git/20200713024909.3714837-31-sandals@crustytoothpaste.net/
found c2a1a5c504 in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 c2a1a5c5048412abaa545862dbd0f3dd93338dc5	builtin/verify-pack.c

applying [1/1] https://public-inbox.org/git/20200723010943.2329634-31-sandals@crustytoothpaste.net/
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index c2a1a5c504..c4090102a9 100644

Checking patch builtin/verify-pack.c...
Applied patch builtin/verify-pack.c cleanly.

skipping https://public-inbox.org/git/20200710024728.3100527-31-sandals@crustytoothpaste.net/ for c4090102a9
skipping https://public-inbox.org/git/20200713024909.3714837-31-sandals@crustytoothpaste.net/ for c4090102a9
index at:
100644 c4090102a965d85aca926fc5cef7ba1f0376509e	builtin/verify-pack.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).