From patchwork Wed Mar 25 21:24: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: 11458645 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 54E5E17D4 for ; Wed, 25 Mar 2020 21:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 177B52082D for ; Wed, 25 Mar 2020 21:25:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dD+N26ol" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727451AbgCYVZS (ORCPT ); Wed, 25 Mar 2020 17:25:18 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:52807 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbgCYVZR (ORCPT ); Wed, 25 Mar 2020 17:25:17 -0400 Received: by mail-pl1-f201.google.com with SMTP id 64so2627594plf.19 for ; Wed, 25 Mar 2020 14:25:15 -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=PhmXRUx9+MPX3S5MN7dOmnCyJOiiVybbgY+RF9h6I2U=; b=dD+N26olgf3F0BztEJPD6V+6urM2e341YTYcSTnBiqcQ6vbmZvoYrbb5QgZ0AI+36X hlS8EUzDtwNUcT8LggGulBNCnyHVIWT4ZgecY8rPAlpIYdWwMJoNJBWrWAN0Secyfphn ObwUVt8yHQ21yiCg2JQLVrmsEamQ6E80rIAYF2ZrIQ2ybEIcMa28ZUf90DXKj3HIWWcE BvvV8A7FqlbzXoShJIdWF0oTnkbrmqLcsHIebraSTkJdfMGy4oHy6Er1OdWkXaenEiRy CuugwA/FPwMkkSN5ym4ULwQtlGbRNS6Q8cq6JM2NRG8Eiv4ryfYsfu8ZuAlDe716YyH8 Mo/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=PhmXRUx9+MPX3S5MN7dOmnCyJOiiVybbgY+RF9h6I2U=; b=XkXVDgmQXim9vlbPg2ivh+M2fcaA3L7CzaSJuFU7XnG7VnPrgYpgmqXCLe1/f+JzQr Dn+qd91NUJBEbz/TpkJsFJ8qeVmZYwBsboD5hs+X35ZpP6iQDAXaSPuecKrCbIFlTU1I /iLAIxGQ5KleLfCi9hbiVNZ3QrfnBwOQllmSxOH4wiFGkw4jDD5csCWU7eN8TTBAwzIL mlzepyJFvLpk90eg6dmF1e2VGinM2z6AiYwGQQNWX48wq2orwoA2rUN2OhsXHXlTyc6D ZgvhV7sHKS/IfMrDTTLnLtIkjja5HenKhW4ql8dgTLY0qBNKIQCe/MytwYsMI2nXZQgi c6Zg== X-Gm-Message-State: ANhLgQ2fN1E3O0NLHhTUj6kbH2TN1BgPrbNUhbj8g2C+rCsFn+tsx/C1 K8jU2sf5pM+gBbLEP+QpeDb2RVDc4C92r7YWrLTXfRvlOi7SpYwfyrZ+1AcHRNKUX+yv3B8/c8A CWiYquwJP/MMFWzQlfKACAKHeLjFrzggJcUIyEekYNIz0iGLnK8ee+LXwMduiMxpkIILVc23XZw == X-Google-Smtp-Source: ADFU+vvO3YLt62Xfjdf+V37PQGMiCucRbgicRWQTn8hexe3OpK/eM7pCN/N5tQC/gSwKyMHFusDhzh76lidM/u7o+C8= X-Received: by 2002:a17:90a:bf08:: with SMTP id c8mr6030076pjs.150.1585171514842; Wed, 25 Mar 2020 14:25:14 -0700 (PDT) Date: Wed, 25 Mar 2020 14:24:56 -0700 In-Reply-To: <20200325212500.135046-1-emilyshaffer@google.com> Message-Id: <20200325212500.135046-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200325212500.135046-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v11 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 Wed Mar 25 21:24: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: 11458647 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 69AC792A for ; Wed, 25 Mar 2020 21:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FA722082D for ; Wed, 25 Mar 2020 21:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NXT/XdyC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbgCYVZT (ORCPT ); Wed, 25 Mar 2020 17:25:19 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:51469 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbgCYVZS (ORCPT ); Wed, 25 Mar 2020 17:25:18 -0400 Received: by mail-pg1-f202.google.com with SMTP id p13so2850916pgk.18 for ; Wed, 25 Mar 2020 14:25:17 -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=a1gHsKgesXvZ6on9jZutni1fYrs6iLWNRYX08oB8HKA=; b=NXT/XdyCqrhNoxfZS+e0g7u67WhBinIy87xA1N/zTrneRfDzm7BLnuE9xpCzMIdrXL uvK9N+Q5xjDwwzs69mnzMAlxAz1qvxMl3LOjo5p334BjfqdS4qkGbipqUJL6k5F2N6vo hMeBHtPITAkDQLh3rqSZ3srmXyLYqroDWwhubZt87bm1g91ICk6E39HBp3CiciaI4JJB FEutwyu9dzm81kcQX3IQAZG2tgrVZiZhqymoG11AzjmL3RqxHa/2nIG3XGqxdxZ0wN/d PsHxp5IZjWmMdMOxZd3RD10aKHt29cKWJ+UUxp8stDRP4aEYNiDioVgljfLgcvDd5yfL dHng== 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=a1gHsKgesXvZ6on9jZutni1fYrs6iLWNRYX08oB8HKA=; b=i+ZGR5Jzy3+hzBIGtQICPPS2U2SlUzyjF06jRkv3zyKblS26rBaU7SNEtu44Y/uAjt ripG2PoqSbN8PyNxPZKyHjn0RUko7jF4Q1FJ+HTdZhGdksQDGk1GwTZLNZqsSJzkz0sz XiGMNOLKbkmtlsvJQQjIt0mtttCHAyWw30EvcvCHrTPw368lJIc+M8tm7gb+6duBVJfs t4aZxg1rivLrvbYGJZoip0fYVdByGJgKwC3uW0YzIFpQpcog5CMdeIdNrZrS+PxDl663 jvCMoESsiCaAMkrKE9ls/uXydQfMC2T211WwSuQQGSBFLsdO/8Wud5qzhNUjzZ2buQLD 4wNA== X-Gm-Message-State: ANhLgQ0oeGCyw/wjo/Q9D71sxOa09O+6q1h4zePWYq0SHFlbCHQbdIIx 62h6iBspZgFcQvazwHBdCnwEGlT1/GX+OmIi55OSAr+BwGPuWu8awJOsPi0CmkT8foge2SrjEqF t0uctcFAXpDNRehLgJFQ5fwIXGmSrjle/7t6FNIteFE2zRXEAwppmRJdhppk1da4AJWCOsc06UQ == X-Google-Smtp-Source: ADFU+vuGJPmyMDj8AtlUPBmIiJ4oza/Qlj2rRES5LguDmL8PMrrfAJwQqi3CuvH6jupPICMHkns0MCzzH26j6JMUgis= X-Received: by 2002:a17:90a:a484:: with SMTP id z4mr5944141pjp.77.1585171517219; Wed, 25 Mar 2020 14:25:17 -0700 (PDT) Date: Wed, 25 Mar 2020 14:24:57 -0700 In-Reply-To: <20200325212500.135046-1-emilyshaffer@google.com> Message-Id: <20200325212500.135046-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200325212500.135046-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v11 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..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 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 Wed Mar 25 21:24: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: 11458649 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 06D4C92A for ; Wed, 25 Mar 2020 21:25:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1C8D20737 for ; Wed, 25 Mar 2020 21:25:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RDhcctfK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbgCYVZW (ORCPT ); Wed, 25 Mar 2020 17:25:22 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:50653 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbgCYVZV (ORCPT ); Wed, 25 Mar 2020 17:25:21 -0400 Received: by mail-pf1-f201.google.com with SMTP id r13so3273183pfr.17 for ; Wed, 25 Mar 2020 14:25:20 -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=cOcOWx/TGBbCwNH722vWiHG74pNEE+TGR9lWvLDDMic=; b=RDhcctfKgTb1o3J1e8SUmc3fHaT+JqB1UfXQMj1juqOMB27uoz3LotnNdx53aVkXZj 2a/waHGXO+PYBERUsmPXr+Pq+EwFUsvxcstVAQ5cSpnkzD4gxWsC3jALK3zuuqGlZySb 01tW6aBeru2IZwVjgdk8pW6v6SK8Au8B2fYZIXNUsN2U5hmwMoCfRKU+VN3g9mXv8Cv4 olP50MRJWEpGOqg4pI9HZT4CWtLO+jy90sG4Ciky/62e+8uzXd0x/2mNj49xNuselG/x hRR2LdxSFiwwvzjdTAarsVIxCYJktMPJtIeWrvnD2+g0Hr07OLA8e6mXIDS/gNR86z3z bIPA== 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=cOcOWx/TGBbCwNH722vWiHG74pNEE+TGR9lWvLDDMic=; b=EI2VTiXi6P7p73WbtuJD5Kbba4s6uwTDBRDN7PhxosJZ5xuiyRrCaPnWoZpDjo96LT LHKFS4S01hYGEAXpIbHXxosTFw/eLlrf7h6VjRKM4JcPG5XPDpn+E4Mrlz4QiUJ7foVJ P+cLKMast/HIfdVLlrib/2nnX/0MxCYfXqLN4bXvSOIMDRFAihDZjrYYtzLKLZ8k9+TC XD2xuih31cphpI+QuLoixUhc1b/WWV1cL7/A0HBzxv7Ern3oDiqOak7uIf2mqGEyhFLU 7x6GuJg6ogX8IYgNCPtRMuIgFKY51xOp+0zMh8Nsa7/XsKAh8+RZ20XugD/2l/rQyADV J3fw== X-Gm-Message-State: ANhLgQ3+zLrMHVLdMVlZ8CyWapMfhOj3hty67KFpwD/Q6p4TyYQ85Sbk 2D6Xncie+UyeCPK54H5z8ySWX0Ed2QSgYzw2njtbGJjzH1W7wi0HTMgQ9Jm0rKKPn451qZeNjuq 0Rbu7m6mZr3np3opoHVVVdctLgjA6PEmlkBO5pM93uyRaLdl+Kadt7j4OSs9q6cwXZ6T204aQPQ == X-Google-Smtp-Source: ADFU+vtQpP4C354LdyIU9+7rg51bDGy9WT6UOPDnI2x4E5wogVtwvv4rC5WSshA+ptX9hbAiKr4Wo9eac/x8bTbCe1I= X-Received: by 2002:a17:90a:2109:: with SMTP id a9mr5866564pje.12.1585171519367; Wed, 25 Mar 2020 14:25:19 -0700 (PDT) Date: Wed, 25 Mar 2020 14:24:58 -0700 In-Reply-To: <20200325212500.135046-1-emilyshaffer@google.com> Message-Id: <20200325212500.135046-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200325212500.135046-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v11 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 Wed Mar 25 21:24: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: 11458651 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 1CCF417EA for ; Wed, 25 Mar 2020 21:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1F342082D for ; Wed, 25 Mar 2020 21:25:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JqnyPPP1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbgCYVZZ (ORCPT ); Wed, 25 Mar 2020 17:25:25 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:50654 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727406AbgCYVZW (ORCPT ); Wed, 25 Mar 2020 17:25:22 -0400 Received: by mail-pf1-f201.google.com with SMTP id r13so3273265pfr.17 for ; Wed, 25 Mar 2020 14:25:22 -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=1D1XhCEQSedVnIAfF/cOlhdZAMyLLlkKrXaZl+LH0W0=; b=JqnyPPP1n/HGv3jGc+pGqhE9DOLoAZVlQV2DpZ9rtn6h6SKe2peTf59uAplglHFura SxU78FpHQ+MarfMoRafjuTsmH8FzU+Fo45akG4v51p92Bj2WmyX9B889RropZDP112E/ JKKCkcm/RP7PhBNoO4+NiaMtKYIK88NvPRht6LZLemmC8/IVBuRRLEtk+QMKaTDJ5uSn tUMFzE9eHxoiFYFmuTZwleMzYkHc5IRlG1agMo/0Ig9MwaYuB3Mby2Ui7KZgckv8BnT6 dMzWD33+5FIpwjCKjydIu5I/wQZzZhXkLHG+ihKGRb5SOuuARj/QxXjr5RfUkAK3AoAC wsfg== 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=1D1XhCEQSedVnIAfF/cOlhdZAMyLLlkKrXaZl+LH0W0=; b=PV8oWQKTwi5tbcNnR6YDZQTIcNlV5Stpx/nGkJNMQf+Y/eCUeUCiTwbkNaZDYBXRZ4 zjuHVT2Eu5s+l4pRMvtc/zyhAfDcaehQrMmckHQIl1ZaRdsYm478CfodBVGR8ZOR5Ju6 p1dOQ5Scyj+hHcdUNboqGKz8gI7320BQKCPJeamtJyghiMqbutyqdsIvDAgLE0tkHBkh nZqInJbOWE7eytoKPf4oAKOsOr6O3whawkCVERgIpWe+wRkBD5P3InVuDc01nv0oEU3m lDy5MKkVFPODBr/dAdY6p7jdFWPZv3B2XfA9eIj4uSTB/pCe6i21xx0ii9C7sc2CggDz kmvQ== X-Gm-Message-State: ANhLgQ0bDCAsQiMHaJp796KTy15YOw0WH6OytJIQG9kXFlw/p35K97RX ZjcPm5W2KMCUH0PY1MA+VJh5hRwWe6m9WfbxLlqJB35OjwFsLpJL1iij9oHbeFEI1vCKTGcvwKM V5f5OT9gCHNHDSg7ii9/ndHIhIImbKCZ6jGIE9j0Ztty284ZgKcKiZXrB5POsukhNGjSVaMe0cA == X-Google-Smtp-Source: ADFU+vssJsZbKrfRjHL8ook5RoTlTewyhiQmjVqRYzb/bGriOMLTx8aeThUBuwrMi5j5kiL8IxP1NQTMwxFLWeK33BE= X-Received: by 2002:a17:90a:c257:: with SMTP id d23mr6032150pjx.192.1585171521777; Wed, 25 Mar 2020 14:25:21 -0700 (PDT) Date: Wed, 25 Mar 2020 14:24:59 -0700 In-Reply-To: <20200325212500.135046-1-emilyshaffer@google.com> Message-Id: <20200325212500.135046-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200325212500.135046-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v11 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 Wed Mar 25 21:25: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: 11458653 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 5159517D4 for ; Wed, 25 Mar 2020 21:25:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FD5820737 for ; Wed, 25 Mar 2020 21:25:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="S4NDdR5Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727491AbgCYVZ0 (ORCPT ); Wed, 25 Mar 2020 17:25:26 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:32977 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727384AbgCYVZZ (ORCPT ); Wed, 25 Mar 2020 17:25:25 -0400 Received: by mail-pg1-f202.google.com with SMTP id 33so2887832pgn.0 for ; Wed, 25 Mar 2020 14:25:24 -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=N3pZla9aBbZ6D9pNUDwjw2gRD2aRL0fqGUvgcrhCMDY=; b=S4NDdR5Y6F6rHr3WOL/y5rt1Qkn/LiixycI5+lLts4KuDhWaMW0sdloNqEHtK0uLRI Vmel2JeeYdo29/BdqCGfBVaDLNVYsRXSy7+BMIFzxBiOpbONvn5aKZCpqpZmu5cuERTq m66NPv61szLIrRZpPqdB4oDbilduhi4bb0JugVYUkQepP0nYd0Mkte66+ADNY99sWLRQ w8keSMWs+ioB21Hbou/b0EmbLmZI+jVFG+virtH+ln5GwKbR6KXZKmhpvknLFU48jrot FZ1ESKgM1HQHuE7dtbkejYYsFYaXuCuTOOsVE0WxbrFJAQnOdYlbalHvqMuG++OHP89l aUYA== 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=N3pZla9aBbZ6D9pNUDwjw2gRD2aRL0fqGUvgcrhCMDY=; b=kEXcjLd1DAvmWZuD1fo3mK1v7Qg2o0+pr5f32Piq1jRP/VlD9CGAd9Uu2sa62Lrqqb eNRbWHrhXSxfrho/AL1O1lpR7mWYLN/p9ntDnU6Ll1sXJ+UxRGa6659nsEKVeRkSW99Z UrnrIEXXcrt2+EqXzz6XEwGCow9rg8xtn+ABni3bXS6ZNHv1qHGIIlGhphBpY9ZaikrO hAokkPWQymP335GL2uwE8xkDfxgVKaE3k+2jobu5nCbO/SSz8zsVZSYDzG5zy8Ku8ebw 1ptXJGbEE/8dLPtNTd58+r0/8+ibCo/RJQrN0z+WMDjb1THrNsYJd8jWaNN0EZBqb3SA 2gJw== X-Gm-Message-State: ANhLgQ3xcjshX8GveUt0gsp0jWX6QaaUB8nJzZbLQRCjy5IvX0CcVV6Z Fstnu5IAuZyd/c5cMcXdhOMsHaja0pzMDJ1nn+/RRz/IbMXWmfaq+V6fwV1o1kD0f7ZY0JR98ON BQy7d7V0FDX9zCUfZsLpCn3SFShOKigw3zQ+x89fKLnVRt5LPDUN9425wWrX6Qfutr3MZx0dS9w == X-Google-Smtp-Source: ADFU+vtgC9MJuP6wkSTZLQaoDyDtBTZnIrBAI53Jh94EpWnkSAlYB712c/3i8/VU0XZbo/a2g/y5EhfOHnLU9Q6sRrA= X-Received: by 2002:a17:90a:9e9:: with SMTP id 96mr5836242pjo.168.1585171524131; Wed, 25 Mar 2020 14:25:24 -0700 (PDT) Date: Wed, 25 Mar 2020 14:25:00 -0700 In-Reply-To: <20200325212500.135046-1-emilyshaffer@google.com> Message-Id: <20200325212500.135046-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200325212500.135046-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v11 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 */