Skip to content

Commit efbace6

Browse files
nasamuffingitster
authored andcommitted
bugreport: gather git version and build info
Knowing which version of Git a user has and how it was built allows us to more precisely pin down the circumstances when a certain issue occurs, so teach bugreport how to tell us the same output as 'git version --build-options'. It's not ideal to directly call 'git version --build-options' because that output goes to stdout. Instead, wrap the version string in a helper within help.[ch] library, and call that helper from within the bugreport library. Signed-off-by: Emily Shaffer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27da720 commit efbace6

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

Documentation/git-bugreport.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ The following information is requested from the user:
2323
- Expected behavior
2424
- Actual behavior
2525

26+
The following information is captured automatically:
27+
28+
- 'git version --build-options'
29+
2630
This tool is invoked via the typical Git setup process, which means that in some
2731
cases, it might not be able to launch - for example, if a relevant config file
2832
is unreadable. In this kind of scenario, it may be helpful to manually gather

bugreport.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
#include "builtin.h"
1+
#include "cache.h"
22
#include "parse-options.h"
33
#include "stdio.h"
44
#include "strbuf.h"
55
#include "time.h"
6+
#include "help.h"
7+
8+
static void get_system_info(struct strbuf *sys_info)
9+
{
10+
/* get git version from native cmd */
11+
strbuf_addstr(sys_info, _("git version:\n"));
12+
get_version_info(sys_info, 1);
13+
strbuf_complete_line(sys_info);
14+
}
615

716
static const char * const bugreport_usage[] = {
817
N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
@@ -32,6 +41,11 @@ static int get_bug_template(struct strbuf *template)
3241
return 0;
3342
}
3443

44+
static void get_header(struct strbuf *buf, const char *title)
45+
{
46+
strbuf_addf(buf, "\n\n[%s]\n", title);
47+
}
48+
3549
int cmd_main(int argc, const char **argv)
3650
{
3751
struct strbuf buffer = STRBUF_INIT;
@@ -79,6 +93,9 @@ int cmd_main(int argc, const char **argv)
7993
/* Prepare the report contents */
8094
get_bug_template(&buffer);
8195

96+
get_header(&buffer, _("System Info"));
97+
get_system_info(&buffer);
98+
8299
/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
83100
report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);
84101

help.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,32 @@ const char *help_unknown_cmd(const char *cmd)
622622
exit(1);
623623
}
624624

625+
void get_version_info(struct strbuf *buf, int show_build_options)
626+
{
627+
/*
628+
* The format of this string should be kept stable for compatibility
629+
* with external projects that rely on the output of "git version".
630+
*
631+
* Always show the version, even if other options are given.
632+
*/
633+
strbuf_addf(buf, "git version %s\n", git_version_string);
634+
635+
if (show_build_options) {
636+
strbuf_addf(buf, "cpu: %s\n", GIT_HOST_CPU);
637+
if (git_built_from_commit_string[0])
638+
strbuf_addf(buf, "built from commit: %s\n",
639+
git_built_from_commit_string);
640+
else
641+
strbuf_addstr(buf, "no commit associated with this build\n");
642+
strbuf_addf(buf, "sizeof-long: %d\n", (int)sizeof(long));
643+
strbuf_addf(buf, "sizeof-size_t: %d\n", (int)sizeof(size_t));
644+
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
645+
}
646+
}
647+
625648
int cmd_version(int argc, const char **argv, const char *prefix)
626649
{
650+
struct strbuf buf = STRBUF_INIT;
627651
int build_options = 0;
628652
const char * const usage[] = {
629653
N_("git version [<options>]"),
@@ -637,25 +661,11 @@ int cmd_version(int argc, const char **argv, const char *prefix)
637661

638662
argc = parse_options(argc, argv, prefix, options, usage, 0);
639663

640-
/*
641-
* The format of this string should be kept stable for compatibility
642-
* with external projects that rely on the output of "git version".
643-
*
644-
* Always show the version, even if other options are given.
645-
*/
646-
printf("git version %s\n", git_version_string);
664+
get_version_info(&buf, build_options);
665+
printf("%s", buf.buf);
666+
667+
strbuf_release(&buf);
647668

648-
if (build_options) {
649-
printf("cpu: %s\n", GIT_HOST_CPU);
650-
if (git_built_from_commit_string[0])
651-
printf("built from commit: %s\n",
652-
git_built_from_commit_string);
653-
else
654-
printf("no commit associated with this build\n");
655-
printf("sizeof-long: %d\n", (int)sizeof(long));
656-
printf("sizeof-size_t: %d\n", (int)sizeof(size_t));
657-
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
658-
}
659669
return 0;
660670
}
661671

help.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void add_cmdname(struct cmdnames *cmds, const char *name, int len);
3737
void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);
3838
int is_in_cmdlist(struct cmdnames *cmds, const char *name);
3939
void list_commands(unsigned int colopts, struct cmdnames *main_cmds, struct cmdnames *other_cmds);
40+
void get_version_info(struct strbuf *buf, int show_build_options);
4041

4142
/*
4243
* call this to die(), when it is suspected that the user mistyped a

0 commit comments

Comments
 (0)