2020-08-13 14:59:36 +00:00
|
|
|
#include "builtin.h"
|
2023-03-21 06:25:58 +00:00
|
|
|
#include "abspath.h"
|
2023-04-11 07:41:57 +00:00
|
|
|
#include "editor.h"
|
2023-03-21 06:25:54 +00:00
|
|
|
#include "gettext.h"
|
2020-04-16 21:18:04 +00:00
|
|
|
#include "parse-options.h"
|
|
|
|
#include "strbuf.h"
|
2020-04-16 21:18:05 +00:00
|
|
|
#include "help.h"
|
2020-04-16 21:18:07 +00:00
|
|
|
#include "compat/compiler.h"
|
2021-09-26 19:03:26 +00:00
|
|
|
#include "hook.h"
|
hook-list.h: add a generated list of hooks, like config-list.h
Make githooks(5) the source of truth for what hooks git supports, and
punt out early on hooks we don't know about in find_hook(). This
ensures that the documentation and the C code's idea about existing
hooks doesn't diverge.
We still have Perl and Python code running its own hooks, but that'll
be addressed by Emily Shaffer's upcoming "git hook run" command.
This resolves a long-standing TODO item in bugreport.c of there being
no centralized listing of hooks, and fixes a bug with the bugreport
listing only knowing about 1/4 of the p4 hooks. It didn't know about
the recent "reference-transaction" hook either.
We could make the find_hook() function die() or BUG() out if the new
known_hook() returned 0, but let's make it return NULL just as it does
when it can't find a hook of a known type. Making it die() is overly
anal, and unlikely to be what we need in catching stupid typos in the
name of some new hook hardcoded in git.git's sources. By making this
be tolerant of unknown hook names, changes in a later series to make
"git hook run" run arbitrary user-configured hook names will be easier
to implement.
I have not been able to directly test the CMake change being made
here. Since 4c2c38e800 (ci: modification of main.yml to use cmake for
vs-build job, 2020-06-26) some of the Windows CI has a hard dependency
on CMake, this change works there, and is to my eyes an obviously
correct use of a pattern established in previous CMake changes,
namely:
- 061c2240b1 (Introduce CMake support for configuring Git,
2020-06-12)
- 709df95b78 (help: move list_config_help to builtin/help,
2020-04-16)
- 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual
Studio solution, 2019-07-29)
The LC_ALL=C is needed because at least in my locale the dash ("-") is
ignored for the purposes of sorting, which results in a different
order. I'm not aware of anything in git that has a hard dependency on
the order, but e.g. the bugreport output would end up using whatever
locale was in effect when git was compiled.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-26 19:03:29 +00:00
|
|
|
#include "hook-list.h"
|
2022-08-12 20:10:17 +00:00
|
|
|
#include "diagnose.h"
|
2023-04-11 07:41:53 +00:00
|
|
|
#include "object-file.h"
|
2023-03-21 06:26:05 +00:00
|
|
|
#include "setup.h"
|
2023-03-21 06:26:01 +00:00
|
|
|
#include "wrapper.h"
|
2020-04-16 21:18:05 +00:00
|
|
|
|
|
|
|
static void get_system_info(struct strbuf *sys_info)
|
|
|
|
{
|
2020-04-16 21:18:06 +00:00
|
|
|
struct utsname uname_info;
|
2020-05-12 23:42:13 +00:00
|
|
|
char *shell = NULL;
|
2020-04-16 21:18:06 +00:00
|
|
|
|
2020-04-16 21:18:05 +00:00
|
|
|
/* get git version from native cmd */
|
|
|
|
strbuf_addstr(sys_info, _("git version:\n"));
|
|
|
|
get_version_info(sys_info, 1);
|
2020-04-16 21:18:06 +00:00
|
|
|
|
|
|
|
/* system call for other version info */
|
|
|
|
strbuf_addstr(sys_info, "uname: ");
|
|
|
|
if (uname(&uname_info))
|
|
|
|
strbuf_addf(sys_info, _("uname() failed with error '%s' (%d)\n"),
|
|
|
|
strerror(errno),
|
|
|
|
errno);
|
|
|
|
else
|
|
|
|
strbuf_addf(sys_info, "%s %s %s %s\n",
|
|
|
|
uname_info.sysname,
|
|
|
|
uname_info.release,
|
|
|
|
uname_info.version,
|
|
|
|
uname_info.machine);
|
2020-04-16 21:18:07 +00:00
|
|
|
|
|
|
|
strbuf_addstr(sys_info, _("compiler info: "));
|
|
|
|
get_compiler_info(sys_info);
|
2020-05-12 23:42:13 +00:00
|
|
|
|
2020-04-16 21:18:07 +00:00
|
|
|
strbuf_addstr(sys_info, _("libc info: "));
|
|
|
|
get_libc_info(sys_info);
|
2020-05-12 23:42:13 +00:00
|
|
|
|
|
|
|
shell = getenv("SHELL");
|
|
|
|
strbuf_addf(sys_info, "$SHELL (typically, interactive shell): %s\n",
|
|
|
|
shell ? shell : "<unset>");
|
2020-04-16 21:18:05 +00:00
|
|
|
}
|
2020-04-16 21:18:04 +00:00
|
|
|
|
2020-05-08 00:53:57 +00:00
|
|
|
static void get_populated_hooks(struct strbuf *hook_info, int nongit)
|
|
|
|
{
|
hook-list.h: add a generated list of hooks, like config-list.h
Make githooks(5) the source of truth for what hooks git supports, and
punt out early on hooks we don't know about in find_hook(). This
ensures that the documentation and the C code's idea about existing
hooks doesn't diverge.
We still have Perl and Python code running its own hooks, but that'll
be addressed by Emily Shaffer's upcoming "git hook run" command.
This resolves a long-standing TODO item in bugreport.c of there being
no centralized listing of hooks, and fixes a bug with the bugreport
listing only knowing about 1/4 of the p4 hooks. It didn't know about
the recent "reference-transaction" hook either.
We could make the find_hook() function die() or BUG() out if the new
known_hook() returned 0, but let's make it return NULL just as it does
when it can't find a hook of a known type. Making it die() is overly
anal, and unlikely to be what we need in catching stupid typos in the
name of some new hook hardcoded in git.git's sources. By making this
be tolerant of unknown hook names, changes in a later series to make
"git hook run" run arbitrary user-configured hook names will be easier
to implement.
I have not been able to directly test the CMake change being made
here. Since 4c2c38e800 (ci: modification of main.yml to use cmake for
vs-build job, 2020-06-26) some of the Windows CI has a hard dependency
on CMake, this change works there, and is to my eyes an obviously
correct use of a pattern established in previous CMake changes,
namely:
- 061c2240b1 (Introduce CMake support for configuring Git,
2020-06-12)
- 709df95b78 (help: move list_config_help to builtin/help,
2020-04-16)
- 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual
Studio solution, 2019-07-29)
The LC_ALL=C is needed because at least in my locale the dash ("-") is
ignored for the purposes of sorting, which results in a different
order. I'm not aware of anything in git that has a hard dependency on
the order, but e.g. the bugreport output would end up using whatever
locale was in effect when git was compiled.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-26 19:03:29 +00:00
|
|
|
const char **p;
|
2020-05-08 00:53:57 +00:00
|
|
|
|
|
|
|
if (nongit) {
|
|
|
|
strbuf_addstr(hook_info,
|
|
|
|
_("not run from a git repository - no hooks to show\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
hook-list.h: add a generated list of hooks, like config-list.h
Make githooks(5) the source of truth for what hooks git supports, and
punt out early on hooks we don't know about in find_hook(). This
ensures that the documentation and the C code's idea about existing
hooks doesn't diverge.
We still have Perl and Python code running its own hooks, but that'll
be addressed by Emily Shaffer's upcoming "git hook run" command.
This resolves a long-standing TODO item in bugreport.c of there being
no centralized listing of hooks, and fixes a bug with the bugreport
listing only knowing about 1/4 of the p4 hooks. It didn't know about
the recent "reference-transaction" hook either.
We could make the find_hook() function die() or BUG() out if the new
known_hook() returned 0, but let's make it return NULL just as it does
when it can't find a hook of a known type. Making it die() is overly
anal, and unlikely to be what we need in catching stupid typos in the
name of some new hook hardcoded in git.git's sources. By making this
be tolerant of unknown hook names, changes in a later series to make
"git hook run" run arbitrary user-configured hook names will be easier
to implement.
I have not been able to directly test the CMake change being made
here. Since 4c2c38e800 (ci: modification of main.yml to use cmake for
vs-build job, 2020-06-26) some of the Windows CI has a hard dependency
on CMake, this change works there, and is to my eyes an obviously
correct use of a pattern established in previous CMake changes,
namely:
- 061c2240b1 (Introduce CMake support for configuring Git,
2020-06-12)
- 709df95b78 (help: move list_config_help to builtin/help,
2020-04-16)
- 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual
Studio solution, 2019-07-29)
The LC_ALL=C is needed because at least in my locale the dash ("-") is
ignored for the purposes of sorting, which results in a different
order. I'm not aware of anything in git that has a hard dependency on
the order, but e.g. the bugreport output would end up using whatever
locale was in effect when git was compiled.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-26 19:03:29 +00:00
|
|
|
for (p = hook_name_list; *p; p++) {
|
|
|
|
const char *hook = *p;
|
|
|
|
|
|
|
|
if (hook_exists(hook))
|
|
|
|
strbuf_addf(hook_info, "%s\n", hook);
|
|
|
|
}
|
2020-05-08 00:53:57 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:18:04 +00:00
|
|
|
static const char * const bugreport_usage[] = {
|
2022-10-13 15:39:10 +00:00
|
|
|
N_("git bugreport [(-o | --output-directory) <path>] [(-s | --suffix) <format>]\n"
|
2022-10-13 15:39:05 +00:00
|
|
|
" [--diagnose[=<mode>]]"),
|
2020-04-16 21:18:04 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int get_bug_template(struct strbuf *template)
|
|
|
|
{
|
|
|
|
const char template_text[] = N_(
|
|
|
|
"Thank you for filling out a Git bug report!\n"
|
|
|
|
"Please answer the following questions to help us understand your issue.\n"
|
|
|
|
"\n"
|
|
|
|
"What did you do before the bug happened? (Steps to reproduce your issue)\n"
|
|
|
|
"\n"
|
|
|
|
"What did you expect to happen? (Expected behavior)\n"
|
|
|
|
"\n"
|
|
|
|
"What happened instead? (Actual behavior)\n"
|
|
|
|
"\n"
|
|
|
|
"What's different between what you expected and what actually happened?\n"
|
|
|
|
"\n"
|
|
|
|
"Anything else you want to add:\n"
|
|
|
|
"\n"
|
|
|
|
"Please review the rest of the bug report below.\n"
|
|
|
|
"You can delete any lines you don't wish to share.\n");
|
|
|
|
|
|
|
|
strbuf_addstr(template, _(template_text));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:18:05 +00:00
|
|
|
static void get_header(struct strbuf *buf, const char *title)
|
|
|
|
{
|
|
|
|
strbuf_addf(buf, "\n\n[%s]\n", title);
|
|
|
|
}
|
|
|
|
|
2020-08-13 14:59:36 +00:00
|
|
|
int cmd_bugreport(int argc, const char **argv, const char *prefix)
|
2020-04-16 21:18:04 +00:00
|
|
|
{
|
|
|
|
struct strbuf buffer = STRBUF_INIT;
|
|
|
|
struct strbuf report_path = STRBUF_INIT;
|
|
|
|
int report = -1;
|
|
|
|
time_t now = time(NULL);
|
2020-12-01 00:30:06 +00:00
|
|
|
struct tm tm;
|
2022-08-12 20:10:17 +00:00
|
|
|
enum diagnose_mode diagnose = DIAGNOSE_NONE;
|
2020-04-16 21:18:04 +00:00
|
|
|
char *option_output = NULL;
|
|
|
|
char *option_suffix = "%Y-%m-%d-%H%M";
|
|
|
|
const char *user_relative_path = NULL;
|
2021-04-25 14:16:13 +00:00
|
|
|
char *prefixed_filename;
|
2022-08-12 20:10:17 +00:00
|
|
|
size_t output_path_len;
|
built-ins: use free() not UNLEAK() if trivial, rm dead code
For a lot of uses of UNLEAK() it would be quite tricky to release the
memory involved, or we're missing the relevant *_(release|clear)()
functions. But in these cases we have them already, and can just
invoke them on the variable(s) involved, instead of UNLEAK().
For "builtin/worktree.c" the UNLEAK() was also added in [1], but the
struct member it's unleaking was removed in [2]. The only non-"int"
member of that structure is "const char *keep_locked", which comes to
us via "argv" or a string literal[3].
We have good visibility via the compiler and
tooling (e.g. SANITIZE=address) on bad free()-ing, but none on
UNLEAK() we don't need anymore. So let's prefer releasing the memory
when it's easy.
For "bugreport", "worktree" and "config" we need to start using a "ret
= ..." return pattern. For "builtin/bugreport.c" these UNLEAK() were
added in [4], and for "builtin/config.c" in [1].
For "config" the code seen here was the only user of the "value"
variable. For "ACTION_{RENAME,REMOVE}_SECTION" we need to be sure to
return the right exit code in the cases where we were relying on
falling through to the top-level.
I think there's still a use-case for UNLEAK(), but hat it's changed
since then. Using it so that "we can see the real leaks" is
counter-productive in these cases.
It's more useful to have UNLEAK() be a marker of the remaining odd
cases where it's hard to free() the memory for whatever reason. With
this change less than 20 of them remain in-tree.
1. 0e5bba53af7 (add UNLEAK annotation for reducing leak false
positives, 2017-09-08)
2. d861d34a6ed (worktree: remove extra members from struct add_opts,
2018-04-24)
3. 0db4961c49b (worktree: teach `add` to accept --reason <string> with
--lock, 2021-07-15)
4. 0e5bba53af7 and 00d8c311050 (commit: fix "author_ident" leak,
2022-05-12).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-11-08 18:17:51 +00:00
|
|
|
int ret;
|
2020-04-16 21:18:04 +00:00
|
|
|
|
|
|
|
const struct option bugreport_options[] = {
|
2022-08-12 20:10:17 +00:00
|
|
|
OPT_CALLBACK_F(0, "diagnose", &diagnose, N_("mode"),
|
|
|
|
N_("create an additional zip archive of detailed diagnostics (default 'stats')"),
|
|
|
|
PARSE_OPT_OPTARG, option_parse_diagnose),
|
2020-04-16 21:18:04 +00:00
|
|
|
OPT_STRING('o', "output-directory", &option_output, N_("path"),
|
2022-08-12 20:10:17 +00:00
|
|
|
N_("specify a destination for the bugreport file(s)")),
|
2020-04-16 21:18:04 +00:00
|
|
|
OPT_STRING('s', "suffix", &option_suffix, N_("format"),
|
2022-08-12 20:10:17 +00:00
|
|
|
N_("specify a strftime format suffix for the filename(s)")),
|
2020-04-16 21:18:04 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, bugreport_options,
|
|
|
|
bugreport_usage, 0);
|
|
|
|
|
|
|
|
/* Prepare the path to put the result */
|
2021-04-25 14:16:13 +00:00
|
|
|
prefixed_filename = prefix_filename(prefix,
|
|
|
|
option_output ? option_output : "");
|
|
|
|
strbuf_addstr(&report_path, prefixed_filename);
|
2020-04-16 21:18:04 +00:00
|
|
|
strbuf_complete(&report_path, '/');
|
2022-08-12 20:10:17 +00:00
|
|
|
output_path_len = report_path.len;
|
2020-04-16 21:18:04 +00:00
|
|
|
|
|
|
|
strbuf_addstr(&report_path, "git-bugreport-");
|
2020-12-01 00:30:06 +00:00
|
|
|
strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0);
|
2020-04-16 21:18:04 +00:00
|
|
|
strbuf_addstr(&report_path, ".txt");
|
|
|
|
|
|
|
|
switch (safe_create_leading_directories(report_path.buf)) {
|
|
|
|
case SCLD_OK:
|
|
|
|
case SCLD_EXISTS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
die(_("could not create leading directories for '%s'"),
|
|
|
|
report_path.buf);
|
|
|
|
}
|
|
|
|
|
2022-08-12 20:10:17 +00:00
|
|
|
/* Prepare diagnostics, if requested */
|
|
|
|
if (diagnose != DIAGNOSE_NONE) {
|
|
|
|
struct strbuf zip_path = STRBUF_INIT;
|
|
|
|
strbuf_add(&zip_path, report_path.buf, output_path_len);
|
|
|
|
strbuf_addstr(&zip_path, "git-diagnostics-");
|
|
|
|
strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0);
|
|
|
|
strbuf_addstr(&zip_path, ".zip");
|
|
|
|
|
|
|
|
if (create_diagnostics_archive(&zip_path, diagnose))
|
|
|
|
die_errno(_("unable to create diagnostics archive %s"), zip_path.buf);
|
|
|
|
|
|
|
|
strbuf_release(&zip_path);
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:18:04 +00:00
|
|
|
/* Prepare the report contents */
|
|
|
|
get_bug_template(&buffer);
|
|
|
|
|
2020-04-16 21:18:05 +00:00
|
|
|
get_header(&buffer, _("System Info"));
|
|
|
|
get_system_info(&buffer);
|
|
|
|
|
2020-05-08 00:53:57 +00:00
|
|
|
get_header(&buffer, _("Enabled Hooks"));
|
2020-08-13 14:59:36 +00:00
|
|
|
get_populated_hooks(&buffer, !startup_info->have_repository);
|
2020-05-08 00:53:57 +00:00
|
|
|
|
2020-04-16 21:18:04 +00:00
|
|
|
/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
|
2021-08-25 20:16:46 +00:00
|
|
|
report = xopen(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);
|
2020-04-16 21:18:04 +00:00
|
|
|
|
2020-06-19 20:23:19 +00:00
|
|
|
if (write_in_full(report, buffer.buf, buffer.len) < 0)
|
|
|
|
die_errno(_("unable to write to %s"), report_path.buf);
|
|
|
|
|
2020-04-16 21:18:04 +00:00
|
|
|
close(report);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to print the path relative to the user, but we still need the
|
|
|
|
* path relative to us to give to the editor.
|
|
|
|
*/
|
|
|
|
if (!(prefix && skip_prefix(report_path.buf, prefix, &user_relative_path)))
|
|
|
|
user_relative_path = report_path.buf;
|
|
|
|
fprintf(stderr, _("Created new report at '%s'.\n"),
|
|
|
|
user_relative_path);
|
|
|
|
|
2021-04-25 14:16:13 +00:00
|
|
|
free(prefixed_filename);
|
built-ins: use free() not UNLEAK() if trivial, rm dead code
For a lot of uses of UNLEAK() it would be quite tricky to release the
memory involved, or we're missing the relevant *_(release|clear)()
functions. But in these cases we have them already, and can just
invoke them on the variable(s) involved, instead of UNLEAK().
For "builtin/worktree.c" the UNLEAK() was also added in [1], but the
struct member it's unleaking was removed in [2]. The only non-"int"
member of that structure is "const char *keep_locked", which comes to
us via "argv" or a string literal[3].
We have good visibility via the compiler and
tooling (e.g. SANITIZE=address) on bad free()-ing, but none on
UNLEAK() we don't need anymore. So let's prefer releasing the memory
when it's easy.
For "bugreport", "worktree" and "config" we need to start using a "ret
= ..." return pattern. For "builtin/bugreport.c" these UNLEAK() were
added in [4], and for "builtin/config.c" in [1].
For "config" the code seen here was the only user of the "value"
variable. For "ACTION_{RENAME,REMOVE}_SECTION" we need to be sure to
return the right exit code in the cases where we were relying on
falling through to the top-level.
I think there's still a use-case for UNLEAK(), but hat it's changed
since then. Using it so that "we can see the real leaks" is
counter-productive in these cases.
It's more useful to have UNLEAK() be a marker of the remaining odd
cases where it's hard to free() the memory for whatever reason. With
this change less than 20 of them remain in-tree.
1. 0e5bba53af7 (add UNLEAK annotation for reducing leak false
positives, 2017-09-08)
2. d861d34a6ed (worktree: remove extra members from struct add_opts,
2018-04-24)
3. 0db4961c49b (worktree: teach `add` to accept --reason <string> with
--lock, 2021-07-15)
4. 0e5bba53af7 and 00d8c311050 (commit: fix "author_ident" leak,
2022-05-12).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-11-08 18:17:51 +00:00
|
|
|
strbuf_release(&buffer);
|
|
|
|
|
|
|
|
ret = !!launch_editor(report_path.buf, NULL, NULL);
|
|
|
|
strbuf_release(&report_path);
|
|
|
|
return ret;
|
2020-04-16 21:18:04 +00:00
|
|
|
}
|