diff options
author | Victoria Dye <vdye@github.com> | 2022-08-12 22:10:16 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-08-12 22:20:02 +0200 |
commit | 7ecf193f7d621f618b322498d884ee103a44522f (patch) | |
tree | 0f32a7af200f886cadbceab0fc86be37f2789f70 /diagnose.c | |
parent | builtin/diagnose.c: create 'git diagnose' builtin (diff) | |
download | git-7ecf193f7d621f618b322498d884ee103a44522f.tar.xz git-7ecf193f7d621f618b322498d884ee103a44522f.zip |
builtin/diagnose.c: add '--mode' option
Create '--mode=<mode>' option in 'git diagnose' to allow users to optionally
select non-default diagnostic information to include in the output archive.
Additionally, document the currently-available modes, emphasizing the
importance of not sharing a '--mode=all' archive publicly due to the
presence of sensitive information.
Note that the option parsing callback - 'option_parse_diagnose()' - is added
to 'diagnose.c' rather than 'builtin/diagnose.c' so that it may be reused in
future callers configuring a diagnostics archive.
Helped-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diagnose.c')
-rw-r--r-- | diagnose.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/diagnose.c b/diagnose.c index 9270056db2..beb0a8741b 100644 --- a/diagnose.c +++ b/diagnose.c @@ -13,6 +13,36 @@ struct archive_dir { int recursive; }; +struct diagnose_option { + enum diagnose_mode mode; + const char *option_name; +}; + +static struct diagnose_option diagnose_options[] = { + { DIAGNOSE_STATS, "stats" }, + { DIAGNOSE_ALL, "all" }, +}; + +int option_parse_diagnose(const struct option *opt, const char *arg, int unset) +{ + int i; + enum diagnose_mode *diagnose = opt->value; + + if (!arg) { + *diagnose = unset ? DIAGNOSE_NONE : DIAGNOSE_STATS; + return 0; + } + + for (i = 0; i < ARRAY_SIZE(diagnose_options); i++) { + if (!strcmp(arg, diagnose_options[i].option_name)) { + *diagnose = diagnose_options[i].mode; + return 0; + } + } + + return error(_("invalid --%s value '%s'"), opt->long_name, arg); +} + static void dir_file_stats_objects(const char *full_path, size_t full_path_len, const char *file_name, void *data) { |