From patchwork Mon Apr 6 22:45:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11476787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A4B892C for ; Mon, 6 Apr 2020 22:45:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35A8020768 for ; Mon, 6 Apr 2020 22:45:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PTYaGdX1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbgDFWpi (ORCPT ); Mon, 6 Apr 2020 18:45:38 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:47274 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgDFWph (ORCPT ); Mon, 6 Apr 2020 18:45:37 -0400 Received: by mail-qt1-f201.google.com with SMTP id g55so1355547qtk.14 for ; Mon, 06 Apr 2020 15:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Iz4H37WF+UqStNK9dwtx0TbHl8Hb8DJLPp4Q/hINo+Q=; b=PTYaGdX1XlhUnsu19yiMIKby3CbLg4eUosGgJV6snEQ36OiiwVbqEDDi9SyvzZb0Gi zf9w0sNVjbMurDlYmMuMhwsZa05tAOqLJitzCoSCynR1a88GmIfe5I3zV/cCtgnP9GJ6 BwneJP6YC+7c8qAQrKy4s0ooy4o/rOs4r45ox/pnC247IjrbZIx1WT0rilybFkPrELn8 so701SXCqkJ5hdGPgY2rpudqs01sxAA3iv9s1DKk2/LAV9+yh15oWYzJpNOy7x/0Hg8Y h/EyVU5H7mm3ERXvhviZp5vCm1AY3Pp5kWv2D1s+lZNwjV9UcK2Vmtk5dFN3XMuPkMj6 GSnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Iz4H37WF+UqStNK9dwtx0TbHl8Hb8DJLPp4Q/hINo+Q=; b=hVXLcRswc7ZkXE2wicG1nKRdGqOV/fECsv5H3swRZk9X/sguTKezXWhWHTewPz4+Z+ 3t7S9BqLfDV/Attlk2OOboJjYrCgM0AhuIoEfUP9MA1vSWAdqhe74bPe969A67OPDnWl nyV3pcNmZxBpQvSamEAao0PcpVSY3TMgLHdjqs69qJZxB+ZqQJEs55lDN64yqYYkMMGp X8yk4+MlRAVOBs2lgrsnabzBFmoHC9/TaOSc0C9i4bu5f7nQu638A/I5DroPjdE++Wzf cNu/BHHkqGsVTpnCQjzlbDsIon7IpJLBX/wtRGA7uC942Cvm/Huztx1MHdGMcVSGyg2L CAZQ== X-Gm-Message-State: AGi0PuZyp7/YBvukgP+ptehpAfWPq2irlPJtot+IPa4V2rDFb3suB7Wu a6ov+b0euRdgCHyAsQ0filhlo+p1JK/3kJlmQ0xDCoVOyPa8QVdkp7yD+ff/SxJUf02xRUemYzA Sx7gAGdEiY6Y6Mm/YZbZZ2lWg0BcQXB3m3Ut3t1M6EoG++lsNYaqobfyKwjhw6Q61VfjbYtD/JQ == X-Google-Smtp-Source: APiQypLxZykRfgEKWhzUPxc1zda+RhT0IdMBp0dL21ilyv7qwkVX7Cj3E99mwkyVXpg02PnMl2z01GGTzE3OOoRMPsc= X-Received: by 2002:ad4:45e9:: with SMTP id q9mr2090388qvu.199.1586213135718; Mon, 06 Apr 2020 15:45:35 -0700 (PDT) Date: Mon, 6 Apr 2020 15:45:22 -0700 In-Reply-To: <20200406224526.256074-1-emilyshaffer@google.com> Message-Id: <20200406224526.256074-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200406224526.256074-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog Subject: [PATCH v12 1/5] help: move list_config_help to builtin/help From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Starting in 3ac68a93fd2, help.o began to depend on builtin/branch.o, builtin/clean.o, and builtin/config.o. This meant that help.o was unusable outside of the context of the main Git executable. To make help.o usable by other commands again, move list_config_help() into builtin/help.c (where it makes sense to assume other builtin libraries are present). When command-list.h is included but a member is not used, we start to hear a compiler warning. Since the config list is generated in a fairly different way than the command list, and since commands and config options are semantically different, move the config list into its own header and move the generator into its own script and build rule. Signed-off-by: Emily Shaffer --- .gitignore | 1 + Makefile | 13 +++++-- builtin/help.c | 86 ++++++++++++++++++++++++++++++++++++++++++ generate-cmdlist.sh | 19 ---------- generate-configlist.sh | 21 +++++++++++ help.c | 85 ----------------------------------------- help.h | 1 - 7 files changed, 118 insertions(+), 108 deletions(-) create mode 100755 generate-configlist.sh diff --git a/.gitignore b/.gitignore index 188bd1c3de..61bf5142a9 100644 --- a/.gitignore +++ b/.gitignore @@ -188,6 +188,7 @@ /gitweb/gitweb.cgi /gitweb/static/gitweb.js /gitweb/static/gitweb.min.* +/config-list.h /command-list.h *.tar.gz *.dsc diff --git a/Makefile b/Makefile index ef1ff2228f..d4aff7f9b5 100644 --- a/Makefile +++ b/Makefile @@ -815,6 +815,7 @@ LIB_FILE = libgit.a XDIFF_LIB = xdiff/lib.a VCSSVN_LIB = vcs-svn/lib.a +GENERATED_H += config-list.h GENERATED_H += command-list.h LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ @@ -2133,7 +2134,7 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h -builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX +builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ @@ -2153,6 +2154,12 @@ $(BUILT_INS): git$X ln -s $< $@ 2>/dev/null || \ cp $< $@ +config-list.h: generate-configlist.sh + +config-list.h: + $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \ + >$@+ && mv $@+ $@ + command-list.h: generate-cmdlist.sh command-list.txt command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt @@ -2786,7 +2793,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE .PHONY: sparse $(SP_OBJ) sparse: $(SP_OBJ) -EXCEPT_HDRS := command-list.h unicode-width.h compat/% xdiff/% +EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/% ifndef GCRYPT_SHA256 EXCEPT_HDRS += sha256/gcrypt.h endif @@ -2808,7 +2815,7 @@ hdr-check: $(HCO) style: git clang-format --style file --diff --extensions c,h -check: command-list.h +check: config-list.h command-list.h @if sparse; \ then \ echo >&2 "Use 'make sparse' instead"; \ diff --git a/builtin/help.c b/builtin/help.c index e5590d7787..1c5f2b9255 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -8,6 +8,7 @@ #include "parse-options.h" #include "run-command.h" #include "column.h" +#include "config-list.h" #include "help.h" #include "alias.h" @@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = { NULL }; +struct slot_expansion { + const char *prefix; + const char *placeholder; + void (*fn)(struct string_list *list, const char *prefix); + int found; +}; + +static void list_config_help(int for_human) +{ + struct slot_expansion slot_expansions[] = { + { "advice", "*", list_config_advices }, + { "color.branch", "", list_config_color_branch_slots }, + { "color.decorate", "", list_config_color_decorate_slots }, + { "color.diff", "", list_config_color_diff_slots }, + { "color.grep", "", list_config_color_grep_slots }, + { "color.interactive", "", list_config_color_interactive_slots }, + { "color.remote", "", list_config_color_sideband_slots }, + { "color.status", "", list_config_color_status_slots }, + { "fsck", "", list_config_fsck_msg_ids }, + { "receive.fsck", "", list_config_fsck_msg_ids }, + { NULL, NULL, NULL } + }; + const char **p; + struct slot_expansion *e; + struct string_list keys = STRING_LIST_INIT_DUP; + int i; + + for (p = config_name_list; *p; p++) { + const char *var = *p; + struct strbuf sb = STRBUF_INIT; + + for (e = slot_expansions; e->prefix; e++) { + + strbuf_reset(&sb); + strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); + if (!strcasecmp(var, sb.buf)) { + e->fn(&keys, e->prefix); + e->found++; + break; + } + } + strbuf_release(&sb); + if (!e->prefix) + string_list_append(&keys, var); + } + + for (e = slot_expansions; e->prefix; e++) + if (!e->found) + BUG("slot_expansion %s.%s is not used", + e->prefix, e->placeholder); + + string_list_sort(&keys); + for (i = 0; i < keys.nr; i++) { + const char *var = keys.items[i].string; + const char *wildcard, *tag, *cut; + + if (for_human) { + puts(var); + continue; + } + + wildcard = strchr(var, '*'); + tag = strchr(var, '<'); + + if (!wildcard && !tag) { + puts(var); + continue; + } + + if (wildcard && !tag) + cut = wildcard; + else if (!wildcard && tag) + cut = tag; + else + cut = wildcard < tag ? wildcard : tag; + + /* + * We may produce duplicates, but that's up to + * git-completion.bash to handle + */ + printf("%.*s\n", (int)(cut - var), var); + } + string_list_clear(&keys, 0); +} + static enum help_format parse_help_format(const char *format) { if (!strcmp(format, "man")) diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index 71158f7d8b..45fecf8bdf 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -76,23 +76,6 @@ print_command_list () { echo "};" } -print_config_list () { - cat <", list_config_color_branch_slots }, - { "color.decorate", "", list_config_color_decorate_slots }, - { "color.diff", "", list_config_color_diff_slots }, - { "color.grep", "", list_config_color_grep_slots }, - { "color.interactive", "", list_config_color_interactive_slots }, - { "color.remote", "", list_config_color_sideband_slots }, - { "color.status", "", list_config_color_status_slots }, - { "fsck", "", list_config_fsck_msg_ids }, - { "receive.fsck", "", list_config_fsck_msg_ids }, - { NULL, NULL, NULL } - }; - const char **p; - struct slot_expansion *e; - struct string_list keys = STRING_LIST_INIT_DUP; - int i; - - for (p = config_name_list; *p; p++) { - const char *var = *p; - struct strbuf sb = STRBUF_INIT; - - for (e = slot_expansions; e->prefix; e++) { - - strbuf_reset(&sb); - strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); - if (!strcasecmp(var, sb.buf)) { - e->fn(&keys, e->prefix); - e->found++; - break; - } - } - strbuf_release(&sb); - if (!e->prefix) - string_list_append(&keys, var); - } - - for (e = slot_expansions; e->prefix; e++) - if (!e->found) - BUG("slot_expansion %s.%s is not used", - e->prefix, e->placeholder); - - string_list_sort(&keys); - for (i = 0; i < keys.nr; i++) { - const char *var = keys.items[i].string; - const char *wildcard, *tag, *cut; - - if (for_human) { - puts(var); - continue; - } - - wildcard = strchr(var, '*'); - tag = strchr(var, '<'); - - if (!wildcard && !tag) { - puts(var); - continue; - } - - if (wildcard && !tag) - cut = wildcard; - else if (!wildcard && tag) - cut = tag; - else - cut = wildcard < tag ? wildcard : tag; - - /* - * We may produce duplicates, but that's up to - * git-completion.bash to handle - */ - printf("%.*s\n", (int)(cut - var), var); - } - string_list_clear(&keys, 0); -} - static int get_alias(const char *var, const char *value, void *data) { struct string_list *list = data; diff --git a/help.h b/help.h index 7a455beeb7..9071894e8c 100644 --- a/help.h +++ b/help.h @@ -22,7 +22,6 @@ static inline void mput_char(char c, unsigned int num) void list_common_cmds_help(void); void list_all_cmds_help(void); void list_common_guides_help(void); -void list_config_help(int for_human); void list_all_main_cmds(struct string_list *list); void list_all_other_cmds(struct string_list *list); From patchwork Mon Apr 6 22:45:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11476789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 949D51871 for ; Mon, 6 Apr 2020 22:45:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73F6E2072A for ; Mon, 6 Apr 2020 22:45:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ujgPuWZm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbgDFWpk (ORCPT ); Mon, 6 Apr 2020 18:45:40 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:53836 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgDFWpj (ORCPT ); Mon, 6 Apr 2020 18:45:39 -0400 Received: by mail-pg1-f202.google.com with SMTP id c33so818167pgl.20 for ; Mon, 06 Apr 2020 15:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=IBg3D63WUpotcHULrkwOuGqilI/3nimvMQle/XieQf8=; b=ujgPuWZmCzlNjSugyjerD2R0oT2N5MVJr4Z8njbdOcYHsaT5JlR+50h5BrJ5UvkgDC HikjtH4FHHl4tiveEodZoTevKw6UG0Zo17BFI5ogpWVt28xYgoVgeFvVxG025cLE7FUM 8df684sAoFlJHLcsy7xxF1bO5JIrxfXn/p7kZr+d27KupMwChkHIN91WSOxzKAABt/7Y 2bPRaEQVsgs9jSdoVTmKT3jBEoGEDpjPcgwM9b5IGZDTR0aM0kLuHZzeZGwMvTd/CQA7 lqKmK/dbN1N7FccVSsSeMWyHErqT2KdJCW6VCdQSMrE5feIzwBtZ7X0F66/TSYcmUoyt sIww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IBg3D63WUpotcHULrkwOuGqilI/3nimvMQle/XieQf8=; b=JzNUZN+omxNquCDpY/ngFtvRESIho2GJ7iTQBn1ZB69bosT3NHYlTD/r4fMxW2WeOh CXpAHasNoAGnw9wNQalj/50YmFNxaR8a0vUpenzemuqHfMuKHViF4cPbE/Ov8wSmMeQl KSEW+kx1vmeeJREu/HIzN/SpA2ERX8Ox7BiTyUxlabdWu4OkJzBBIxucfQtMqwRB4UHJ 2pqravaV+vSjwDiL/fynli92h7QKA/h8X9k9IhDwZiodvK3YPdp3oC8TkzQfXOeBgBuU bOpRKg9XtKUppvf6Wp1DutWrIDNLLXoFVOxcwgJ4Ak5HkXbN8lblSNbQMTRRHbn36UK/ sPCg== X-Gm-Message-State: AGi0PuaRqY698UAf37wCS0vaVD9j+Km3alpK9TU6sayTyu4LOAvJXpbo phVRkM5KM3jqSFJPgDfIwuSoSrd9z4+dKCeqzyiL+O5tVdm38Bti05XLgZFMAf36fx7PXI0/mKL udSRUfP/js4eAOLftnm4kWInMnbHi0H7c1mykibwcMvbfqqT44fG1J91xOhCMD03HDn98y3hD8A == X-Google-Smtp-Source: APiQypISdaVbQBKgfdtFvENqQvwCTa2vEKKfBkLyplxbms8cH8V9sFxFRDD6/YikubJcfWJJxQsfGx5MhoxeNXjd/ok= X-Received: by 2002:a17:90a:26e3:: with SMTP id m90mr1872781pje.144.1586213138153; Mon, 06 Apr 2020 15:45:38 -0700 (PDT) Date: Mon, 6 Apr 2020 15:45:23 -0700 In-Reply-To: <20200406224526.256074-1-emilyshaffer@google.com> Message-Id: <20200406224526.256074-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200406224526.256074-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog Subject: [PATCH v12 2/5] bugreport: add tool to generate debugging info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach Git how to prompt the user for a good bug report: reproduction steps, expected behavior, and actual behavior. Later, Git can learn how to collect some diagnostic information from the repository. If users can send us a well-written bug report which contains diagnostic information we would otherwise need to ask the user for, we can reduce the number of question-and-answer round trips between the reporter and the Git contributor. Users may also wish to send a report like this to their local "Git expert" if they have put their repository into a state they are confused by. Signed-off-by: Emily Shaffer --- .gitignore | 1 + Documentation/git-bugreport.txt | 46 ++++++++++++++ Makefile | 5 ++ bugreport.c | 105 ++++++++++++++++++++++++++++++++ command-list.txt | 1 + strbuf.c | 4 ++ strbuf.h | 1 + t/t0091-bugreport.sh | 61 +++++++++++++++++++ 8 files changed, 224 insertions(+) create mode 100644 Documentation/git-bugreport.txt create mode 100644 bugreport.c create mode 100755 t/t0091-bugreport.sh diff --git a/.gitignore b/.gitignore index 61bf5142a9..ee509a2ad2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ /git-bisect--helper /git-blame /git-branch +/git-bugreport /git-bundle /git-cat-file /git-check-attr diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt new file mode 100644 index 0000000000..1f9fde5cde --- /dev/null +++ b/Documentation/git-bugreport.txt @@ -0,0 +1,46 @@ +git-bugreport(1) +================ + +NAME +---- +git-bugreport - Collect information for user to file a bug report + +SYNOPSIS +-------- +[verse] +'git bugreport' [(-o | --output-directory) ] [(-s | --suffix) ] + +DESCRIPTION +----------- +Captures information about the user's machine, Git client, and repository state, +as well as a form requesting information about the behavior the user observed, +into a single text file which the user can then share, for example to the Git +mailing list, in order to report an observed bug. + +The following information is requested from the user: + + - Reproduction steps + - Expected behavior + - Actual behavior + +This tool is invoked via the typical Git setup process, which means that in some +cases, it might not be able to launch - for example, if a relevant config file +is unreadable. In this kind of scenario, it may be helpful to manually gather +the kind of information listed above when manually asking for help. + +OPTIONS +------- +-o :: +--output-directory :: + Place the resulting bug report file in `` instead of the root of + the Git repository. + +-s :: +--suffix :: + Specify an alternate suffix for the bugreport name, to create a file + named 'git-bugreport-'. This should take the form of a + link:strftime[3] format string; the current local time will be used. + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index d4aff7f9b5..b0a9073788 100644 --- a/Makefile +++ b/Makefile @@ -680,6 +680,7 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) +PROGRAM_OBJS += bugreport.o PROGRAM_OBJS += credential-store.o PROGRAM_OBJS += daemon.o PROGRAM_OBJS += fast-import.o @@ -2462,6 +2463,10 @@ endif git-%$X: %.o GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(LIBS) + git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(IMAP_SEND_LDFLAGS) $(LIBS) diff --git a/bugreport.c b/bugreport.c new file mode 100644 index 0000000000..f6f53a5e8e --- /dev/null +++ b/bugreport.c @@ -0,0 +1,105 @@ +#include "builtin.h" +#include "parse-options.h" +#include "stdio.h" +#include "strbuf.h" +#include "time.h" + +static const char * const bugreport_usage[] = { + N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), + 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; +} + +int cmd_main(int argc, const char **argv) +{ + struct strbuf buffer = STRBUF_INIT; + struct strbuf report_path = STRBUF_INIT; + int report = -1; + time_t now = time(NULL); + char *option_output = NULL; + char *option_suffix = "%Y-%m-%d-%H%M"; + int nongit_ok = 0; + const char *prefix = NULL; + const char *user_relative_path = NULL; + + const struct option bugreport_options[] = { + OPT_STRING('o', "output-directory", &option_output, N_("path"), + N_("specify a destination for the bugreport file")), + OPT_STRING('s', "suffix", &option_suffix, N_("format"), + N_("specify a strftime format suffix for the filename")), + OPT_END() + }; + + prefix = setup_git_directory_gently(&nongit_ok); + + argc = parse_options(argc, argv, prefix, bugreport_options, + bugreport_usage, 0); + + /* Prepare the path to put the result */ + strbuf_addstr(&report_path, + prefix_filename(prefix, + option_output ? option_output : "")); + strbuf_complete(&report_path, '/'); + + strbuf_addstr(&report_path, "git-bugreport-"); + strbuf_addftime(&report_path, option_suffix, localtime(&now), 0, 0); + 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); + } + + /* Prepare the report contents */ + get_bug_template(&buffer); + + /* fopen doesn't offer us an O_EXCL alternative, except with glibc. */ + report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666); + + if (report < 0) { + UNLEAK(report_path); + die(_("couldn't create a new file at '%s'"), report_path.buf); + } + + strbuf_write_fd(&buffer, report); + 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); + + UNLEAK(buffer); + UNLEAK(report_path); + return !!launch_editor(report_path.buf, NULL, NULL); +} diff --git a/command-list.txt b/command-list.txt index 2087894655..185e5e3f05 100644 --- a/command-list.txt +++ b/command-list.txt @@ -54,6 +54,7 @@ git-archive mainporcelain git-bisect mainporcelain info git-blame ancillaryinterrogators complete git-branch mainporcelain history +git-bugreport ancillaryinterrogators git-bundle mainporcelain git-cat-file plumbinginterrogators git-check-attr purehelpers diff --git a/strbuf.c b/strbuf.c index bb0065ccaf..3bfcaababb 100644 --- a/strbuf.c +++ b/strbuf.c @@ -554,6 +554,10 @@ ssize_t strbuf_write(struct strbuf *sb, FILE *f) return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0; } +ssize_t strbuf_write_fd(struct strbuf *sb, int fd) +{ + return sb->len ? write(fd, sb->buf, sb->len) : 0; +} #define STRBUF_MAXLINK (2*PATH_MAX) diff --git a/strbuf.h b/strbuf.h index ce8e49c0b2..801a3694ec 100644 --- a/strbuf.h +++ b/strbuf.h @@ -468,6 +468,7 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint); * NUL bytes. */ ssize_t strbuf_write(struct strbuf *sb, FILE *stream); +ssize_t strbuf_write_fd(struct strbuf *sb, int fd); /** * Read a line from a FILE *, overwriting the existing contents of diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh new file mode 100755 index 0000000000..2e73658a5c --- /dev/null +++ b/t/t0091-bugreport.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +test_description='git bugreport' + +. ./test-lib.sh + +# Headers "[System Info]" will be followed by a non-empty line if we put some +# information there; we can make sure all our headers were followed by some +# information to check if the command was successful. +HEADER_PATTERN="^\[.*\]$" + +check_all_headers_populated () { + while read -r line + do + if test "$(grep "$HEADER_PATTERN" "$line")" + then + echo "$line" + read -r nextline + if test -z "$nextline"; then + return 1; + fi + fi + done +} + +test_expect_success 'creates a report with content in the right places' ' + test_when_finished rm git-bugreport-check-headers.txt && + git bugreport -s check-headers && + check_all_headers_populated >git-bugreport-duplicate.txt && + test_must_fail git bugreport --suffix duplicate +' + +test_expect_success '--output-directory puts the report in the provided dir' ' + test_when_finished rm -fr foo/ && + git bugreport -o foo/ && + test_path_is_file foo/git-bugreport-* +' + +test_expect_success 'incorrect arguments abort with usage' ' + test_must_fail git bugreport --false 2>output && + test_i18ngrep usage output && + test_path_is_missing git-bugreport-* +' + +test_expect_success 'runs outside of a git dir' ' + test_when_finished rm non-repo/git-bugreport-* && + nongit git bugreport +' + +test_expect_success 'can create leading directories outside of a git dir' ' + test_when_finished rm -fr foo/bar/baz && + nongit git bugreport -o foo/bar/baz +' + + +test_done From patchwork Mon Apr 6 22:45:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11476793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EC5192C for ; Mon, 6 Apr 2020 22:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7C3A2072A for ; Mon, 6 Apr 2020 22:45:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A3yZhJp6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbgDFWpo (ORCPT ); Mon, 6 Apr 2020 18:45:44 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:39338 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbgDFWpn (ORCPT ); Mon, 6 Apr 2020 18:45:43 -0400 Received: by mail-pl1-f202.google.com with SMTP id d11so912854pll.6 for ; Mon, 06 Apr 2020 15:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aw1WoGWu0MS7Y4dR0L6/dxci3fV8LP1WJf8EDxVPStA=; b=A3yZhJp6JU9OncbN+wzvsDXSLd288K+ffJI7VjY/UsyLOZvGOM85wDKIJVLMhjhrm8 809z7EeYkJZNAZZwc1ulF//c7OJVs0nPS7STP7BeQkxfc9SnovlhCXmF+MVshrjoFm0M E3IEEuc927wlrfRYJ03D/yzoR6tRdl36VDRkochVfhsTUXea2bxNuNsjIIQlVrwo2UNI ycvP1Ffl0m0SJELUM6/LV/kmgevtKirXTzcLXA7OVg8nBpMODer+rqdwkJdMrD09c48e IKVxwYovGLFVqvdAHKlL3GbKIq5kSgDMUzadMZ6S2mmoYsj3eBDzYcaMlpPXnZNwufmk YbOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aw1WoGWu0MS7Y4dR0L6/dxci3fV8LP1WJf8EDxVPStA=; b=DfLd9QPepjBPyEWR6GD1YOnlzLmR2TSsQPsI+UAAtn4JUDEtnKQeU3QofmhjblOhCI DC/2OMqIvPIQNmXOIPMVdwMIhlCw34ieJcA2EEI4PML1x/85MfFYHlFXQm7He2Mbu4Va d3xnYFAi88PZWc78JV8DI/l5VpZ4977sqCMQM9w/tP8yI1H7NtxUmOaW7mebEcMntjUr iLFm7jWY3JYX7Zgh0XvqyvTCczHS4+sFcO0fcQijD+jioztC16NY9BLx6AnQjM7h7h54 4bCrWeOnBpJU8aUQRJNTfhKKwpePduIq9lEbkvWNo4UZfz9pPU9Y5yae8bdUSoWZrra5 8YaQ== X-Gm-Message-State: AGi0Pub0Z4MqDVFDJIdZ8sAtF9/+nEYH5zV/HqWJgW7Oo6amFV+3p3Om rbbTpvtq/7Hs9QQjt/oneMEppmva3hY3NBs1dAZ1HYK7quxtyxIkGrwQg/SQBYNOWO6A79AsH2s GgekuW8d8IAeNbdAKRC6TS4ZcByD7Uwr20CSgfEJcb/nw7KQhVmrlR2nOmHhqM30k5BelPp+iKA == X-Google-Smtp-Source: APiQypLqmbTiSPtdQH6t/LBMJ2z5jYwRhW4Kwd3OOQAtwVjyJAjPbs23URw+ihdfp1m6uWtxO2R0AZmT1TS+49k7tS8= X-Received: by 2002:a65:568a:: with SMTP id v10mr1339206pgs.215.1586213140446; Mon, 06 Apr 2020 15:45:40 -0700 (PDT) Date: Mon, 6 Apr 2020 15:45:24 -0700 In-Reply-To: <20200406224526.256074-1-emilyshaffer@google.com> Message-Id: <20200406224526.256074-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200406224526.256074-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog Subject: [PATCH v12 3/5] bugreport: gather git version and build info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- Documentation/git-bugreport.txt | 4 +++ bugreport.c | 19 +++++++++++++- help.c | 46 ++++++++++++++++++++------------- help.h | 1 + 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 1f9fde5cde..f44ae8cbe7 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -23,6 +23,10 @@ The following information is requested from the user: - Expected behavior - Actual behavior +The following information is captured automatically: + + - 'git version --build-options' + This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file is unreadable. In this kind of scenario, it may be helpful to manually gather diff --git a/bugreport.c b/bugreport.c index f6f53a5e8e..4cdb58bbaa 100644 --- a/bugreport.c +++ b/bugreport.c @@ -1,8 +1,17 @@ -#include "builtin.h" +#include "cache.h" #include "parse-options.h" #include "stdio.h" #include "strbuf.h" #include "time.h" +#include "help.h" + +static void get_system_info(struct strbuf *sys_info) +{ + /* get git version from native cmd */ + strbuf_addstr(sys_info, _("git version:\n")); + get_version_info(sys_info, 1); + strbuf_complete_line(sys_info); +} static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), @@ -32,6 +41,11 @@ static int get_bug_template(struct strbuf *template) return 0; } +static void get_header(struct strbuf *buf, const char *title) +{ + strbuf_addf(buf, "\n\n[%s]\n", title); +} + int cmd_main(int argc, const char **argv) { struct strbuf buffer = STRBUF_INIT; @@ -79,6 +93,9 @@ int cmd_main(int argc, const char **argv) /* Prepare the report contents */ get_bug_template(&buffer); + get_header(&buffer, _("System Info")); + get_system_info(&buffer); + /* fopen doesn't offer us an O_EXCL alternative, except with glibc. */ report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666); diff --git a/help.c b/help.c index a21487db77..1de9c0d589 100644 --- a/help.c +++ b/help.c @@ -622,8 +622,32 @@ const char *help_unknown_cmd(const char *cmd) exit(1); } +void get_version_info(struct strbuf *buf, int show_build_options) +{ + /* + * The format of this string should be kept stable for compatibility + * with external projects that rely on the output of "git version". + * + * Always show the version, even if other options are given. + */ + strbuf_addf(buf, "git version %s\n", git_version_string); + + if (show_build_options) { + strbuf_addf(buf, "cpu: %s\n", GIT_HOST_CPU); + if (git_built_from_commit_string[0]) + strbuf_addf(buf, "built from commit: %s\n", + git_built_from_commit_string); + else + strbuf_addstr(buf, "no commit associated with this build\n"); + strbuf_addf(buf, "sizeof-long: %d\n", (int)sizeof(long)); + strbuf_addf(buf, "sizeof-size_t: %d\n", (int)sizeof(size_t)); + /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */ + } +} + int cmd_version(int argc, const char **argv, const char *prefix) { + struct strbuf buf = STRBUF_INIT; int build_options = 0; const char * const usage[] = { N_("git version []"), @@ -637,25 +661,11 @@ int cmd_version(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, usage, 0); - /* - * The format of this string should be kept stable for compatibility - * with external projects that rely on the output of "git version". - * - * Always show the version, even if other options are given. - */ - printf("git version %s\n", git_version_string); + get_version_info(&buf, build_options); + printf("%s", buf.buf); + + strbuf_release(&buf); - if (build_options) { - printf("cpu: %s\n", GIT_HOST_CPU); - if (git_built_from_commit_string[0]) - printf("built from commit: %s\n", - git_built_from_commit_string); - else - printf("no commit associated with this build\n"); - printf("sizeof-long: %d\n", (int)sizeof(long)); - printf("sizeof-size_t: %d\n", (int)sizeof(size_t)); - /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */ - } return 0; } diff --git a/help.h b/help.h index 9071894e8c..500521b908 100644 --- a/help.h +++ b/help.h @@ -37,6 +37,7 @@ void add_cmdname(struct cmdnames *cmds, const char *name, int len); void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes); int is_in_cmdlist(struct cmdnames *cmds, const char *name); void list_commands(unsigned int colopts, struct cmdnames *main_cmds, struct cmdnames *other_cmds); +void get_version_info(struct strbuf *buf, int show_build_options); /* * call this to die(), when it is suspected that the user mistyped a From patchwork Mon Apr 6 22:45:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11476795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39FF31805 for ; Mon, 6 Apr 2020 22:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18CDA2072A for ; Mon, 6 Apr 2020 22:45:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="k4QZ+2+s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726421AbgDFWpo (ORCPT ); Mon, 6 Apr 2020 18:45:44 -0400 Received: from mail-pj1-f73.google.com ([209.85.216.73]:57063 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726406AbgDFWpo (ORCPT ); Mon, 6 Apr 2020 18:45:44 -0400 Received: by mail-pj1-f73.google.com with SMTP id f94so940296pjg.6 for ; Mon, 06 Apr 2020 15:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DOU5MCoYa4zauj6NBGHDdbNf1kW7bolvbPlGx6zsZ8E=; b=k4QZ+2+s6s02Ugx3e6T5EeHw1+Fm0R38mE9axqJboockHzkFs43NTSWwCIVUxsRTN5 ocMgtHZcOCvPI3oZAMv1N8FRK2K3dm71cQxCOm3I255JiKKd9lRJbdNHThU4dbP3+IIe jXCUrOkIYX3dPA2EQsvrRUKP8qZfYCRfCQnHU+feQcSRI5ujxqAoXdVYPf1Q6junVGPj gxIeeWIzWpGyKr4/UFzE7oqVDKxnP0tmyka6U8lmh3y1RoTZxJyenSUc/kQ0HxqahXup hNFVZvKST+jepCWDx2XdLXz05sV/DU+2C6EbGTwnTAaRsUGYtXCAsZuqdJ1InkQBgiwQ j6iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DOU5MCoYa4zauj6NBGHDdbNf1kW7bolvbPlGx6zsZ8E=; b=e+zV2huBIsIY/G6AFKG1YhuIqBX+QrMTxwLf7orgcN8ISnvZeJ2V/9oFnp2My9r1rG ptQWaCdw04NX+2N1Ul4KtttO1jPlJfbZ3wB4fmeEF3jX9fBPgeP6NSS2gtCuUhSkbOea XLfPzSukpahBh+USjTkyP0tqC0DkBjlNWM119dAQHjl/pVhIrr/l5wv3mcEj9aDHZmiB TNtiQywIXxS3/fGNlsLSPYx/g/hpFxa9t1iKNI33TqXQnFxgEW8XaA8ZjpsfqnpFTgyP z5X/Lytr7CcLTwm3sSY9dg6BRwJ6fvk0oxf0TbvQehkI7XrG7hjPZ7zk7x/JSo71lATd 9N3w== X-Gm-Message-State: AGi0PuarGwK+i2D97ZOcZ9VqgULAaTyrmJyurTWypogq8iZesu5XKLiV KJSsjC8kZM9qjGQ25Pg/yfk0gzT6OrkU6xRcuTw89R7v1cIOPt2YTt33dK1YWxdx0lRDBYaFg8/ RTTKi1S3ahhSuXHGy52I3eP9SHfLBpPQyyqnd0LfHvt1I5TEPNO8uVbMDsyaQg+ARp09ZEjceBw == X-Google-Smtp-Source: APiQypKpUqalEhoEdBuahB4l8oA70hC8VuY2jTFXuSJuksQwVlF+TPKbd74PAseOCUdF5bBZ0FGx7+gJ+WMHmEceKCk= X-Received: by 2002:a17:90b:2394:: with SMTP id mr20mr1610638pjb.79.1586213142822; Mon, 06 Apr 2020 15:45:42 -0700 (PDT) Date: Mon, 6 Apr 2020 15:45:25 -0700 In-Reply-To: <20200406224526.256074-1-emilyshaffer@google.com> Message-Id: <20200406224526.256074-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200406224526.256074-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog Subject: [PATCH v12 4/5] bugreport: add uname info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The contents of uname() can give us some insight into what sort of system the user is running on, and help us replicate their setup if need be. The domainname field is not guaranteed to be available, so don't collect it. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index f44ae8cbe7..17b0d14e8d 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -26,6 +26,7 @@ The following information is requested from the user: The following information is captured automatically: - 'git version --build-options' + - uname sysname, release, version, and machine strings This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 4cdb58bbaa..1a3172bcec 100644 --- a/bugreport.c +++ b/bugreport.c @@ -7,10 +7,24 @@ static void get_system_info(struct strbuf *sys_info) { + struct utsname uname_info; + /* get git version from native cmd */ strbuf_addstr(sys_info, _("git version:\n")); get_version_info(sys_info, 1); - strbuf_complete_line(sys_info); + + /* 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); } static const char * const bugreport_usage[] = { From patchwork Mon Apr 6 22:45:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11476797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECEB415AB for ; Mon, 6 Apr 2020 22:45:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBF642072A for ; Mon, 6 Apr 2020 22:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B7rLKlNt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbgDFWps (ORCPT ); Mon, 6 Apr 2020 18:45:48 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:37880 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726406AbgDFWps (ORCPT ); Mon, 6 Apr 2020 18:45:48 -0400 Received: by mail-pf1-f202.google.com with SMTP id n28so912935pfq.4 for ; Mon, 06 Apr 2020 15:45:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+baXNWTKW9hbg6uWr4aCoaog+o9GnOiC+rvOqzis9XE=; b=B7rLKlNtDaExloYFtVNeJ/QSz0VXHGLxqfHi5sbo1bF+IHuBu+ITpvAYUYFPFRrnM8 HLg0kuiguuUOkTL14VTOKR0uL+jTw0xfi3A8L/Q4wfcrmKstw1wub1RVRnWzFsDX0Xc0 wxCvyObRY2ahCO8N89WDaVlcx2E+B4v6qT1j9dALrb1/3w3kC40iczkmNCXuvkcJ4lWY 4TW6tYcGK20Zga/CqaJstMiH1axRwYIeVLvyd9/9hy80DsgRdmS+Bvs1IEw8wXbvsSbq 2BvGFCWwaIoXDZrziMJcSLSLyFG3L5/rBrcjnvP8xRsKR7Jds5Ber0b4aVaEcMsrKkaN bE0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+baXNWTKW9hbg6uWr4aCoaog+o9GnOiC+rvOqzis9XE=; b=nVv5ZZsy987i2hENpkuIj/tpY56gwqTWeC3p9mtb8EW+ag2wJDhr6s7xGlZ1l23jjn Y8ia4RU1DOSN4JKL0XCk3in7L3AF8N4yiidaAIsKWy7tnMEjxs1Oe6FCgc6Je/Kp87oz hLzMBL3Ht2mDOxP63RX30iE+3Awy4JujK7gGN6qByDlZtE97jchlix5BtTSerq8Xh/n9 htvH9wsSpg6ULsrNGXisvPTuwQXdEvpZPHE2ixloiGbBycgknWIluK+qz2w/ALlM3SIK aFUqRdrFrLG6v8aP7v9udcESwFBbZ1Khthdu3x63kFC7puG3UqvFJsqS6MJnIoIIjiBG 5Njg== X-Gm-Message-State: AGi0PuYdq0aedBVrNArnS33lADweUm/2iP9vpNn+++6W+YtBcSYx0q3F JW+IiYwQN/cDGTGY/6GsqJXloSmUxt+wkspSK5uuB5EUK/myyHYnFGS4NDR7fKBPSUgy2T8Clge va2FR8WhR/NLcGPcv7ym0Zke9U/cNJl1aIhgB4rrBM4GFZVs1ehyFhTZjyvXzINym72Kak/djbg == X-Google-Smtp-Source: APiQypJYJ6OTPZ8OmDIlhXVQscvr+yczsomBl/GkaEjZTAQUCwOL0furh0rkRTqx9MDhwOhxQkl9oPZjkjbO3XdHX+Q= X-Received: by 2002:a63:3602:: with SMTP id d2mr1335555pga.138.1586213145090; Mon, 06 Apr 2020 15:45:45 -0700 (PDT) Date: Mon, 6 Apr 2020 15:45:26 -0700 In-Reply-To: <20200406224526.256074-1-emilyshaffer@google.com> Message-Id: <20200406224526.256074-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200406224526.256074-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog Subject: [PATCH v12 5/5] bugreport: add compiler info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , Danh Doan , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To help pinpoint the source of a regression, it is useful to know some info about the compiler which the user's Git client was built with. By adding a generic get_compiler_info() in 'compat/' we can choose which relevant information to share per compiler; to get started, let's demonstrate the version of glibc if the user built with 'gcc'. Signed-off-by: Emily Shaffer Helped-by: Danh Doan Helped-by: Johannes Schindelin --- Documentation/git-bugreport.txt | 1 + bugreport.c | 6 +++++ compat/compiler.h | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 compat/compiler.h diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 17b0d14e8d..643d1b2884 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -27,6 +27,7 @@ The following information is captured automatically: - 'git version --build-options' - uname sysname, release, version, and machine strings + - Compiler-specific info string This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 1a3172bcec..089b939a87 100644 --- a/bugreport.c +++ b/bugreport.c @@ -4,6 +4,7 @@ #include "strbuf.h" #include "time.h" #include "help.h" +#include "compat/compiler.h" static void get_system_info(struct strbuf *sys_info) { @@ -25,6 +26,11 @@ static void get_system_info(struct strbuf *sys_info) uname_info.release, uname_info.version, uname_info.machine); + + strbuf_addstr(sys_info, _("compiler info: ")); + get_compiler_info(sys_info); + strbuf_addstr(sys_info, _("libc info: ")); + get_libc_info(sys_info); } static const char * const bugreport_usage[] = { diff --git a/compat/compiler.h b/compat/compiler.h new file mode 100644 index 0000000000..10dbb65937 --- /dev/null +++ b/compat/compiler.h @@ -0,0 +1,41 @@ +#ifndef COMPILER_H +#define COMPILER_H + +#include "git-compat-util.h" +#include "strbuf.h" + +#ifdef __GLIBC__ +#include +#endif + +static inline void get_compiler_info(struct strbuf *info) +{ + int len = info->len; +#ifdef __clang__ + strbuf_addf(info, "clang: %s\n", __clang_version__); +#elif defined(__GNUC__) + strbuf_addf(info, "gnuc: %d.%d\n", __GNUC__, __GNUC_MINOR__); +#endif + +#ifdef _MSC_VER + strbuf_addf(info, "MSVC version: %02d.%02d.%05d\n", + _MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 100000); +#endif + + if (len == info->len) + strbuf_addstr(info, _("no compiler information available\n")); +} + +static inline void get_libc_info(struct strbuf *info) +{ + int len = info->len; + +#ifdef __GLIBC__ + strbuf_addf(info, "glibc: %s\n", gnu_get_libc_version()); +#endif + + if (len == info->len) + strbuf_addstr(info, _("no libc information available\n")); +} + +#endif /* COMPILER_H */