diff options
author | Vincent Ambo <Vincent Ambo> | 2020-01-11T23·36+0000 |
---|---|---|
committer | Vincent Ambo <Vincent Ambo> | 2020-01-11T23·40+0000 |
commit | 7ef0d62730840ded097b524104cc0a0904591a63 (patch) | |
tree | a670f96103667aeca4789a95d94ca0dff550c4ce /third_party/git/builtin/verify-pack.c | |
parent | 6a2a3007077818e24a3d56fc492ada9206a10cf0 (diff) | |
parent | 1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5 (diff) |
merge(third_party/git): Merge squashed git subtree at v2.23.0 r/373
Merge commit '1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5' as 'third_party/git'
Diffstat (limited to 'third_party/git/builtin/verify-pack.c')
-rw-r--r-- | third_party/git/builtin/verify-pack.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/third_party/git/builtin/verify-pack.c b/third_party/git/builtin/verify-pack.c new file mode 100644 index 000000000000..c2a1a5c50484 --- /dev/null +++ b/third_party/git/builtin/verify-pack.c @@ -0,0 +1,83 @@ +#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) +{ + struct child_process index_pack = CHILD_PROCESS_INIT; + const char *argv[] = {"index-pack", NULL, NULL, NULL }; + struct strbuf arg = STRBUF_INIT; + int verbose = flags & VERIFY_PACK_VERBOSE; + int stat_only = flags & VERIFY_PACK_STAT_ONLY; + int err; + + if (stat_only) + argv[1] = "--verify-stat-only"; + else if (verbose) + argv[1] = "--verify-stat"; + else + argv[1] = "--verify"; + + /* + * 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[2] = 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; + 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_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)) + err = 1; + } + + return err; +} |