git

Форк
0
/
verify-pack.c 
91 строка · 2.2 Кб
1
#include "builtin.h"
2
#include "config.h"
3
#include "gettext.h"
4
#include "run-command.h"
5
#include "parse-options.h"
6
#include "strbuf.h"
7

8
#define VERIFY_PACK_VERBOSE 01
9
#define VERIFY_PACK_STAT_ONLY 02
10

11
static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
12
{
13
	struct child_process index_pack = CHILD_PROCESS_INIT;
14
	struct strvec *argv = &index_pack.args;
15
	struct strbuf arg = STRBUF_INIT;
16
	int verbose = flags & VERIFY_PACK_VERBOSE;
17
	int stat_only = flags & VERIFY_PACK_STAT_ONLY;
18
	int err;
19

20
	strvec_push(argv, "index-pack");
21

22
	if (stat_only)
23
		strvec_push(argv, "--verify-stat-only");
24
	else if (verbose)
25
		strvec_push(argv, "--verify-stat");
26
	else
27
		strvec_push(argv, "--verify");
28

29
	if (hash_algo)
30
		strvec_pushf(argv, "--object-format=%s", hash_algo);
31

32
	/*
33
	 * In addition to "foo.pack" we accept "foo.idx" and "foo";
34
	 * normalize these forms to "foo.pack" for "index-pack --verify".
35
	 */
36
	strbuf_addstr(&arg, path);
37
	if (strbuf_strip_suffix(&arg, ".idx") ||
38
	    !ends_with(arg.buf, ".pack"))
39
		strbuf_addstr(&arg, ".pack");
40
	strvec_push(argv, arg.buf);
41

42
	index_pack.git_cmd = 1;
43

44
	err = run_command(&index_pack);
45

46
	if (verbose || stat_only) {
47
		if (err)
48
			printf("%s: bad\n", arg.buf);
49
		else {
50
			if (!stat_only)
51
				printf("%s: ok\n", arg.buf);
52
		}
53
	}
54
	strbuf_release(&arg);
55

56
	return err;
57
}
58

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

64
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
65
{
66
	int err = 0;
67
	unsigned int flags = 0;
68
	const char *object_format = NULL;
69
	int i;
70
	const struct option verify_pack_options[] = {
71
		OPT_BIT('v', "verbose", &flags, N_("verbose"),
72
			VERIFY_PACK_VERBOSE),
73
		OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
74
			VERIFY_PACK_STAT_ONLY),
75
		OPT_STRING(0, "object-format", &object_format, N_("hash"),
76
			   N_("specify the hash algorithm to use")),
77
		OPT_END()
78
	};
79

80
	git_config(git_default_config, NULL);
81
	argc = parse_options(argc, argv, prefix, verify_pack_options,
82
			     verify_pack_usage, 0);
83
	if (argc < 1)
84
		usage_with_options(verify_pack_usage, verify_pack_options);
85
	for (i = 0; i < argc; i++) {
86
		if (verify_one_pack(argv[i], flags, object_format))
87
			err = 1;
88
	}
89

90
	return err;
91
}
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.