In "config.c" we host both the business logic to read and write config files as well as the logic to parse specific Git-related variables. On the one hand this is mixing concerns, but even more importantly it means that we cannot easily remove the dependency on `the_repository` in our config parsing logic. Move the logic into "environment.c". This file is a grab bag of all kinds of global state already, so it is quite a good fit. Furthermore, it also hosts most of the global variables that we're parsing the config values into, making this an even better fit. Note that there is one hidden change: in `parse_fsync_components()` we use an `int` to iterate through `ARRAY_SIZE(fsync_component_names)`. But as -Wsign-compare warnings are enabled in this file this causes a compiler warning. The issue is fixed by using a `size_t` instead. This change allows us to drop the `USE_THE_REPOSITORY_VARIABLE` declaration. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
97 lines
2.4 KiB
C
97 lines
2.4 KiB
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
#include "builtin.h"
|
|
#include "config.h"
|
|
#include "environment.h"
|
|
#include "gettext.h"
|
|
#include "run-command.h"
|
|
#include "parse-options.h"
|
|
#include "strbuf.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;
|
|
struct strvec *argv = &index_pack.args;
|
|
struct strbuf arg = STRBUF_INIT;
|
|
int verbose = flags & VERIFY_PACK_VERBOSE;
|
|
int stat_only = flags & VERIFY_PACK_STAT_ONLY;
|
|
int err;
|
|
|
|
strvec_push(argv, "index-pack");
|
|
|
|
if (stat_only)
|
|
strvec_push(argv, "--verify-stat-only");
|
|
else if (verbose)
|
|
strvec_push(argv, "--verify-stat");
|
|
else
|
|
strvec_push(argv, "--verify");
|
|
|
|
if (hash_algo)
|
|
strvec_pushf(argv, "--object-format=%s", hash_algo);
|
|
|
|
/*
|
|
* 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");
|
|
strvec_push(argv, arg.buf);
|
|
|
|
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>.idx..."),
|
|
NULL
|
|
};
|
|
|
|
int cmd_verify_pack(int argc,
|
|
const char **argv,
|
|
const char *prefix,
|
|
struct repository *repo UNUSED)
|
|
{
|
|
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()
|
|
};
|
|
|
|
repo_config(the_repository, 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;
|
|
}
|