scalar-diagnose: use 'git diagnose --mode=all'

Replace implementation of 'scalar diagnose' with an internal invocation of
'git diagnose --mode=all'. This simplifies the implementation of
'cmd_diagnose' by making it a direct alias of 'git diagnose' and removes
some code in 'scalar.c' that is duplicated in 'builtin/diagnose.c'. The
simplicity of the alias also sets up a clean deprecation path for 'scalar
diagnose' (in favor of 'git diagnose'), if that is desired in the future.

This introduces one minor change to the output of 'scalar diagnose', which
is that the prefix of the created zip archive is changed from 'scalar_' to
'git-diagnostics-'.

Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Victoria Dye 2022-08-12 20:10:18 +00:00 committed by Junio C Hamano
parent aac0e8ffee
commit 672196a307

View File

@ -11,7 +11,6 @@
#include "dir.h" #include "dir.h"
#include "packfile.h" #include "packfile.h"
#include "help.h" #include "help.h"
#include "diagnose.h"
/* /*
* Remove the deepest subdirectory in the provided path string. Path must not * Remove the deepest subdirectory in the provided path string. Path must not
@ -510,34 +509,19 @@ static int cmd_diagnose(int argc, const char **argv)
N_("scalar diagnose [<enlistment>]"), N_("scalar diagnose [<enlistment>]"),
NULL NULL
}; };
struct strbuf zip_path = STRBUF_INIT; struct strbuf diagnostics_root = STRBUF_INIT;
time_t now = time(NULL);
struct tm tm;
int res = 0; int res = 0;
argc = parse_options(argc, argv, NULL, options, argc = parse_options(argc, argv, NULL, options,
usage, 0); usage, 0);
setup_enlistment_directory(argc, argv, usage, options, &zip_path); setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");
strbuf_addstr(&zip_path, "/.scalarDiagnostics/scalar_"); res = run_git("diagnose", "--mode=all", "-s", "%Y%m%d_%H%M%S",
strbuf_addftime(&zip_path, "-o", diagnostics_root.buf, NULL);
"%Y%m%d_%H%M%S", localtime_r(&now, &tm), 0, 0);
strbuf_addstr(&zip_path, ".zip");
switch (safe_create_leading_directories(zip_path.buf)) {
case SCLD_EXISTS:
case SCLD_OK:
break;
default:
error_errno(_("could not create directory for '%s'"),
zip_path.buf);
goto diagnose_cleanup;
}
res = create_diagnostics_archive(&zip_path, DIAGNOSE_ALL); strbuf_release(&diagnostics_root);
diagnose_cleanup:
strbuf_release(&zip_path);
return res; return res;
} }