From patchwork Mon Mar 2 23:03:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11416733 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 6ACD5921 for ; Mon, 2 Mar 2020 23:04:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B6AF24677 for ; Mon, 2 Mar 2020 23:04:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MocbKugA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726831AbgCBXEM (ORCPT ); Mon, 2 Mar 2020 18:04:12 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:57110 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgCBXEM (ORCPT ); Mon, 2 Mar 2020 18:04:12 -0500 Received: by mail-pl1-f201.google.com with SMTP id m1so673838pll.23 for ; Mon, 02 Mar 2020 15:04:10 -0800 (PST) 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=XOVEK94ibAWDiwcsIzDovjRx3yjjmSxllhzBsSKMAkg=; b=MocbKugAETRWLbN9oVKGG2xKgqQ67UglDhv8HlPYae3MWi5W1aNPiM3ThoII5eOSPm d6dterI6OpuH3n9YgOOEBUxSGJKacqPwWvYJTqQfaaCUV42xFsS8CfUn60xB50B929R/ r+wRhSCnGR2GuTZ8nN8hRnLILj0HI9a1he93WD8iK+eI1/SJTOVql6EZrFF2KuMBxKCf KQHoO3Qpee2Wx94slSFwt122Ys3qKlqll0D4yKnuOQ1dHmfVX966FpwlpDNjePd27stT JSNtlBQg3b0NK5US7vtpD2unnH51QN3X23H/+to+vN0n5D9I/4Kd17ejEAOOA7ZXVFpM Yz+A== 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=XOVEK94ibAWDiwcsIzDovjRx3yjjmSxllhzBsSKMAkg=; b=ZwpaImJFR12FGEqNi4kDF0HXcBy0X6aL0mNzSk8Psu3QAqjlZvarz06wED9XAEUp/s zqs86rrpDoUX+0pfjcEAkgLliO9KOaWPxFJUiJYEoWv/QVmE/bqoz2sOarj6+9n7d9B1 Fi9gJUwNE77oo16dET6rA9ng9KUf+9lQaR1q9dD/RLRupKyF0zk9vrGO5NU+tJ0m4XAW HbiiD7tmzlT3ePymR9Eka5pB6ygyHlZqqpfPkkAzmnJilAtrzXtGvQB1Q8NbeQuic0pS 1P6253o9zjCBSLAv4IpYPnLXw3bFEv1Ly4FAy9kMu7p0LQURcdcIcfA0qMGHOWAQb7XM jP7Q== X-Gm-Message-State: ANhLgQ1FA0sAqlCpXh12VzJT2Eh9XW1Nmi7Ktj90kPN+IsZQ3CTQo0oS mbf0jC8DBBLMJWTCz/FlQm8TAklnqvHpmTovyQhHIj7bxku5sg82WcrKwZZv732hQ1MJEotNHYc tLYB+Awyl1hgOSF79F2Owsg5klzX4Hk0doofl7FD1xVvH8ag2boByB1kh+PLIp21p42kqPgi85Q == X-Google-Smtp-Source: ADFU+vsFsy4MdQCmY9rbC5SZQOiYc6rh13EkEo6w09+4Jn+y07W/+MXGjaKTo1tkmBpfTO+ATCIBq1L/GPYXz4+9CmI= X-Received: by 2002:a63:354b:: with SMTP id c72mr998402pga.99.1583190249949; Mon, 02 Mar 2020 15:04:09 -0800 (PST) Date: Mon, 2 Mar 2020 15:03:56 -0800 In-Reply-To: <20200302230400.107428-1-emilyshaffer@google.com> Message-Id: <20200302230400.107428-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200302230400.107428-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v9 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 aebe7c0908..ea97de83f3 100644 --- a/.gitignore +++ b/.gitignore @@ -189,6 +189,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 6134104ae6..c552312d3f 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 || \ @@ -2132,7 +2133,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)"' \ @@ -2152,6 +2153,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 @@ -2785,7 +2792,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 @@ -2807,7 +2814,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 Mar 2 23:03:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11416737 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 E85911820 for ; Mon, 2 Mar 2020 23:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDCDF24673 for ; Mon, 2 Mar 2020 23:04:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s1wQjVLl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726876AbgCBXEO (ORCPT ); Mon, 2 Mar 2020 18:04:14 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:35087 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgCBXEN (ORCPT ); Mon, 2 Mar 2020 18:04:13 -0500 Received: by mail-pl1-f202.google.com with SMTP id v24so698795plo.2 for ; Mon, 02 Mar 2020 15:04:13 -0800 (PST) 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=TiHR76D0wbYnOGYOjO4GZ3ROPjhGbzccQjHCOqET6d0=; b=s1wQjVLlrQYydxHrl1zPMD8CZgZaYSmoGl2RS/hjOLRVl7xz4Qalrc7E62/z7mHGWf JNiKldxCW7IlOx+kUIVBfCAhTrI8NarRIoBwX1sULEkQYwYQibb2D37Se2RDmPA5ABOr HbynNzmRVBubKRKjoe2aPNZvYbgyP5gKZ7HHd4uHPMVvFeM+Wfr/TosCYNjNPrxvJsNN OZ2M02I6UVPksBUmCcJ9sArOiGktF2h8+abewSHpM60TI4pUTYGu2MLcYc5iG/v/5bof 1F6cBVvK96aWG64yapps5YLhlmkxwBbbCOb0dtnDBS9j0RIB4R3kEVBKqwPj5BGmbNGp 2nhg== 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=TiHR76D0wbYnOGYOjO4GZ3ROPjhGbzccQjHCOqET6d0=; b=HiXgG9ybDGmM9cbDhogLmoofQ/X8q61kYUlM9t8wlWV9iShXBbMiy4cmR8QdfdPMhT Bwnforleg6O/6R1nq7pbY5wgQqGV787chaHtND/RSA8gw+Q1H0eNiiFRjjZv5IWsaeZx OUcWfAYEyA5RBpaaoDb4L83ap7kvSnfuvXquQ03c/MxcEgNSgo/c+Ll0VMqQJcu8cybQ j/ZZLBiJECaRB5sP6inWGr/OlRaDTBywgl8W0ENn1gGVQ8OcwZr5BjtIW7BXSQy6Y9Gu kHRkDT3ryBjEokxYb+SE1Fj5DRNlmvJ79JyKLP0bKe75dQ0Rbeg8oDTrLnMBcdFAuR8f d7tA== X-Gm-Message-State: ANhLgQ0k9PibF+iXAeLd9yJegFHUyHr1CU5g0culjhYIT/TnYknuW1Fh fE2F5rEizQyxVzB35F97PUO0Mwe/IYwGognE1wl0uSr0KryE5T3I3Ugq8dNlgMl+SSXkR7aD8j7 2MbMc8fsvbJ1kq+XzpLppN9o/Xv8bd45I/YvQlbhs7eSswmeUT9KWr7C8kO/1UIQo5+aSOQtXJw == X-Google-Smtp-Source: ADFU+vsgfKHoty0uM7iLl62ftI8FwCfPLmGQNvTvr2Zbrcl5RK4ppLWVUkjRBVmyhcAvBubf9501+SRDaYk8ueYdtus= X-Received: by 2002:a63:1d18:: with SMTP id d24mr1096611pgd.189.1583190252412; Mon, 02 Mar 2020 15:04:12 -0800 (PST) Date: Mon, 2 Mar 2020 15:03:57 -0800 In-Reply-To: <20200302230400.107428-1-emilyshaffer@google.com> Message-Id: <20200302230400.107428-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200302230400.107428-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v9 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 ea97de83f3..d89bf9e11e 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 c552312d3f..9e6705061d 100644 --- a/Makefile +++ b/Makefile @@ -681,6 +681,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 @@ -2461,6 +2462,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..f473d606f2 --- /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 = "%F-%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 f19da55b07..f1d66c7848 100644 --- a/strbuf.c +++ b/strbuf.c @@ -539,6 +539,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 aae7ac3a82..bbf6204de7 100644 --- a/strbuf.h +++ b/strbuf.h @@ -462,6 +462,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..65f664fdac --- /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' ' + git bugreport -s check-headers && + check_all_headers_populated >git-bugreport-duplicate.txt && + test_must_fail git bugreport --suffix duplicate && + test_when_finished rm git-bugreport-duplicate.txt +' + +test_expect_success '--output-directory puts the report in the provided dir' ' + git bugreport -o foo/ && + test_path_is_file foo/git-bugreport-* && + test_when_finished rm -fr foo/ +' + +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' ' + nongit git bugreport && + test_when_finished rm non-repo/git-bugreport-* +' + +test_expect_success 'can create leading directories outside of a git dir' ' + nongit git bugreport -o foo/bar/baz && + test_when_finished rm -fr foo/bar/baz +' + + +test_done From patchwork Mon Mar 2 23:03:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11416739 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 0ADE5174A for ; Mon, 2 Mar 2020 23:04:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D40AC24673 for ; Mon, 2 Mar 2020 23:04:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wDFvBDPT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726898AbgCBXEQ (ORCPT ); Mon, 2 Mar 2020 18:04:16 -0500 Received: from mail-pj1-f74.google.com ([209.85.216.74]:58274 "EHLO mail-pj1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgCBXEQ (ORCPT ); Mon, 2 Mar 2020 18:04:16 -0500 Received: by mail-pj1-f74.google.com with SMTP id ca1so519094pjb.7 for ; Mon, 02 Mar 2020 15:04:15 -0800 (PST) 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=Zpn/NOdEG/r8l3Vr/mYk2qmngwBLogxV7LJuAfzZPlU=; b=wDFvBDPTEBglmqB+LzKwPCG5lAbGU6Y4NZ04jiVonUSSotHtXuC94JeMq0hFggKPet MxDFVYZ/+9Nmzt+xxKhOcH+rswRKebNNKW0JVdWK2Gl5huyHACSN6oKtfXsKpwG4xEy2 9BKcv+TJefO1FyGXM/aOyDtHC/OmQXgI+hczNv5fS9PFKabE0dqxSB8OU2Skxiek716e 07Q0sw2NNHiohhQW4dODRPt+WfG55WE6nOn67Eqh6R/cPdnUPqWlbFf+/PgFQqZ788t1 L8ypXpJABo4DHbeFvFK+Ov6AYATjPoRhubkTxuLq5S/OYEbz6vBz5YbzD5wMorksMKBF qvhw== 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=Zpn/NOdEG/r8l3Vr/mYk2qmngwBLogxV7LJuAfzZPlU=; b=udZiglWE36jfg55Qi1mVAwvqxeJGjlGCpicpwrHRxPZzvQ0xFRPBaFDnnH2rLs1SRA kDOOgViKv8oYp5Mp2c+zczN3vHL+SwG6UU0gLxlaFdNF/h05gwK+rdnNpjtA5mOuaT5+ pZ1SH1mOqUBrbdA0hwyEZNvC/pZH0qeNYHP8RvonBgCBIry1roykDpmk10siv0NfDZ/4 LVcO9vnpV7czYRBj/SB9ccOr9Y/X5stzNIt8wYSWxgRkIzlZUHzsQx8JrWdcFPznuSST /617mzVfUwJvtQfj8dEMgVzZa2ISvLbr+RY+EiGTtwWN+ePOYF+I4fzmCvJOTGDgVowx ehyg== X-Gm-Message-State: ANhLgQ3KaRu2Iky5PRFTcbS45kAP6kFAXiggBH+C1L/mhinfK5pIcUPL Lgc/xkdDtxN+lqBbtMZdgnB1ODN6aPthIXTOZnUgIQV/3X+eJqKFXfTDGwwp4vp9rHxeRsj4NSn z1S1i7W8zeKLbQdsN/unBojNcOZwk2x/YJRzJd60vo90aNn+EnjT9e5hhAv+xm33NWHeJgLQSWA == X-Google-Smtp-Source: ADFU+vs9rb6cyGJseDxw3SDLMTvMWxhen+IRA4KLsrVgtkeADVQHelmG7uMLKUMRgw+htugbrVzsqZ972mg//ieVpcw= X-Received: by 2002:a63:ef03:: with SMTP id u3mr1103529pgh.77.1583190254795; Mon, 02 Mar 2020 15:04:14 -0800 (PST) Date: Mon, 2 Mar 2020 15:03:58 -0800 In-Reply-To: <20200302230400.107428-1-emilyshaffer@google.com> Message-Id: <20200302230400.107428-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200302230400.107428-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v9 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 f473d606f2..c20437dc6a 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 Mar 2 23:03:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11416741 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 C9586921 for ; Mon, 2 Mar 2020 23:04:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA27524677 for ; Mon, 2 Mar 2020 23:04:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lL+JeGpZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726915AbgCBXES (ORCPT ); Mon, 2 Mar 2020 18:04:18 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:53416 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgCBXES (ORCPT ); Mon, 2 Mar 2020 18:04:18 -0500 Received: by mail-pf1-f202.google.com with SMTP id c17so617469pfi.20 for ; Mon, 02 Mar 2020 15:04:17 -0800 (PST) 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=O8ANs7twFvdaz2j1puYgi2ZFbPsFwdSmhVbUBL9jo+w=; b=lL+JeGpZB5PtH7gjaRyV3oN/10nzFfVBMVJ9MoPd1YfZl4ORpEP83XxeUb+0Ons+CY 5//D8wlafBCiaiNdSAhTT84DemWZQqIpT6O0q2BJaQ2PZr+EjavWtVgtlthtufIg+H9w vUxDIOkqXhYmul144R9zNSLd+unigRnUzRAaadpdA51Q4Ew+wTrjt4N9mfONLqFcCPBV 5pntpFRRrHsEniZdIbu2zyezOprw35HrflWKdF59j1I9cr7OARIr5aGYqVReVvl+iOOs OBEqx/I1hvz+8cMUU3FagpePdkAlJr9C8ZFpTTZsw+MRfiuEmxzTufYpYD2SnrVWZJsf MmMg== 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=O8ANs7twFvdaz2j1puYgi2ZFbPsFwdSmhVbUBL9jo+w=; b=jCh3Tv71S8l5jhB/4hsrqqu8ekFFPmdjnSsZ/lDhBEBGzuz3JrU982qDcP9Oe37CAG kSUDFC4yMIllYzb2/6ljSe3AqhJ1WapxebG1UYlcJWy0UY/g1Y54e//v6HZuuRhgszQT caT2H7+xRx1Y1xVcKcBhf3DCRPecX9Hs1YsEIETvmxRKOWL4Us9+PQIZcnkIMe0A49ih 59Ov/ZnQHUD9CvflsE1vULpl7eC3v46MZL/zwJwVjHepukhD847gJHwD5cIwKnEEq3IP Kn1hGwhbr7U/ErRMl88C7yU5QZA4kRHpZwWA9JnfwNCeoha/Xnrbuwo8QU5dRmckuCHj oH0g== X-Gm-Message-State: ANhLgQ3tgLgm0rPPhTiZlFU7nUXYCe60bzJdqkY/sIrbSvWG0CHbeJdi bzBjUL2YFtLH0nzUD4GL6mV7dCwlAf7e+cuEr87JPFiGbBMV0es/2+l25wdk0BMyedWk/UR/NvZ tFyaMK3fza+KbsELXjlo19jKCi3YH/O8CITzXrXlFACRfE81kRU/pYpnJv18kdMXJkQ+PR9bAbQ == X-Google-Smtp-Source: ADFU+vsGtOLuAQkhJJ4F6lMenfYhPSvGawwC+N1ULMle6KlZnJ+byVSNgH7STg3cNJS1yK8Ppl8nZyK1M6fGf4D8cL4= X-Received: by 2002:a63:b047:: with SMTP id z7mr1115835pgo.431.1583190257211; Mon, 02 Mar 2020 15:04:17 -0800 (PST) Date: Mon, 2 Mar 2020 15:03:59 -0800 In-Reply-To: <20200302230400.107428-1-emilyshaffer@google.com> Message-Id: <20200302230400.107428-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200302230400.107428-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v9 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 c20437dc6a..857b4f712c 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 Mar 2 23:04:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11416743 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 B2FCB921 for ; Mon, 2 Mar 2020 23:04:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91B4A24673 for ; Mon, 2 Mar 2020 23:04:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="adFyJvE9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbgCBXEU (ORCPT ); Mon, 2 Mar 2020 18:04:20 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:43802 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbgCBXEU (ORCPT ); Mon, 2 Mar 2020 18:04:20 -0500 Received: by mail-pg1-f202.google.com with SMTP id o7so838730pgk.10 for ; Mon, 02 Mar 2020 15:04:20 -0800 (PST) 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=CbySq5shLK4cH3Jor0njKSBxSdHRlDv3F5KvpxJ9aC0=; b=adFyJvE99ImpT90WPJvi+9zcySshD/S2JvKtUlrzYWlBhLWa+lBa6wN1+ka+xAKRqP spN7irBIuRD37QLHsZjD9tySNZn6o6UaZ4Tu5oYSMHyi9EDcKlDZA30QLcUhkWM7lUkU maaDrjy1Nul3gQEvvczqaSq0Tb83gyFJ/Adxp+3Ueo9Q4cup52kRRsP3D0YhWEnDdi5n 8h3rWzoAVKtirv01UeQW9wBYEp8jIUYaA12xaCaSq97h0BnchZw3VMnioDiNuLY6V37b MqhG+0ltE+SO0i4xCAcjnf8I5p8taHVBegY+kz9kzHQoJTMAXvPn0aSO3SoKDdZ3R+k1 EqvQ== 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=CbySq5shLK4cH3Jor0njKSBxSdHRlDv3F5KvpxJ9aC0=; b=jmo0if6RP/kcbPKKtw+69jAXJCzDivLneJPsb+9658FzMopePT0uLtoSE8qbrly8HU w9LTElPyd9jnsGsXVbeBnZPIaEvIgZmLgyqfQnNhafmwedn55UtJnuWimM8KihZqBkiw pnqtuirtq2SlL4gtX473j+JLHsIXbbEl2/A05BKtjtB2cv8kl/43S7fPFpUcD+KLsB8y B7jdGpXR+grUvGpjtBwBuW4iTsUZh0jO7N1DSG/j+OX6I/uVP6ovfm6XnV7VhNFVUKZg ZgzBfbCnvtYWQp6NajTZzLfuJqA9kgODACy/b5Kb6zv/oNvrVARUuqMBkba/YsjOlKVR s7hQ== X-Gm-Message-State: ANhLgQ3aZQ5aSB/u8iUDI4ZJA7ouRwPxu7/Yv6lSC43Lo9rqlXMVwsUs d8KCaSWYH2/KVk92l5J7++RpfnOt83JuhcuqYKk9bXvcK9PkXCJA1JliYSFBvEEO8fSX2AzUahG SFqfrBMFFsm3PFYxltxGARoSnlMqL9c0Cyt54YY1/Eo6YK54J+OG3xlWcDZGVkJ/Ex0sY8KEQHw == X-Google-Smtp-Source: ADFU+vuhegx7oT71DpC9VdSIjnmC1iePxoAH05ExPTkZWy+DhJy4NmSlqUqic3iVAQ/W3O6pKGBvLzQbTK8BRNunddU= X-Received: by 2002:a63:b52:: with SMTP id a18mr1190689pgl.130.1583190259438; Mon, 02 Mar 2020 15:04:19 -0800 (PST) Date: Mon, 2 Mar 2020 15:04:00 -0800 In-Reply-To: <20200302230400.107428-1-emilyshaffer@google.com> Message-Id: <20200302230400.107428-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200302230400.107428-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v9 5/5] bugreport: add compiler 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 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 Signed-off-by: Johannes Schindelin --- Documentation/git-bugreport.txt | 1 + bugreport.c | 6 ++++++ compat/compiler.h | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 45 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 857b4f712c..5073c901cd 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..21f098e6a4 --- /dev/null +++ b/compat/compiler.h @@ -0,0 +1,38 @@ +#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 __GNUC__ + strbuf_addf(info, "gnuc: %d.%d\n", __GNUC__, __GNUC_MINOR__); +#endif + +#ifdef _MSC_VER + strbuf_addf(info, "MSVC version: %s\n", _MSC_FULL_VER); +#endif + + if (len == info->len) + strbuf_addf(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_addf(info, _("no libc information available\n")); +} + +#endif /* COMPILER_H */