From patchwork Mon Mar 23 21:43:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11454055 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 66D3F92A for ; Mon, 23 Mar 2020 21:43:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E44B20753 for ; Mon, 23 Mar 2020 21:43:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ApSSkVcy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbgCWVnx (ORCPT ); Mon, 23 Mar 2020 17:43:53 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:45642 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727025AbgCWVnx (ORCPT ); Mon, 23 Mar 2020 17:43:53 -0400 Received: by mail-pl1-f202.google.com with SMTP id s6so10480084plp.12 for ; Mon, 23 Mar 2020 14:43:50 -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=ApSSkVcyj7kXqZTU8rBCKlwDI6b9MtjgQtUVLz33tGFJOOnDjAJTZH82zdmpILoac6 OOunFtAZ4GrOEllLSHjR8a8LFQkn2BHuE3Y+Sd7S67F6xkc2tn5f7Nc1hCEFIwyDrNC4 KZbmcmezDlFJVJj7/sgR3JTO6Qa3/KD830zdGVcBtVxTApI3wm07jyolr2gB6Tl78QWo CRwK9L09h40cVLFSftUUCpZyWu4TSuNjfeH5jTGwKdpRB+nupiUDYeG5zIYxzbjviJB3 SodR9j1WlI6yXLWF+8/EsXN/kG2qWcLKnZHdQj4G5xODRCliJH0azHzvZzrE3nIV1NYg N/bw== 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=ctsDgKg9qx6AYJDfG7Qcp0yPotBdVEXXJU7rhexYgLhfvlPvJXW22z1DvhsetR1t3y oij2aQIFHcBCMB8cNoz0CZlDcGkd6yi+8oNZSBv5x3fvlbIha4xLsyDIoesys1yAjR9O z+rujuchOwSTYs0SgzhMs6mDxU4WZGjMetlqGzn+/98qIHc4HFESBx99gieEmmjPB8u9 yyxUraDQHaaTB/hLiI4bevntqHKKHaY0xFMnKy42Pa9brf0MBm7t+GhZw6jk9Yr2+gN2 z1mb41BUVrASJ5OgelbkX3OLRP0dnWRQ9ViWFpYWGExBfBDyooJonGnmUGr5lZY2hPCy EolQ== X-Gm-Message-State: ANhLgQ0V9zIijopqtJ/Qzqw4ksA9dI+5Fsv6HyLocSb4tdx5BPlpKuCT NSQ9Brz0rSinEbiZr5Had0onXuGA+z0ozcoepuB6ELPPwSIdVEpc28VY4Ar2LY8DkJUkB/Ily/Z yCGEl5RKQIeWEOw2pvBjyfGZ8+cNjHEcQkWmpEP2kqnLXpZ3KMAVw8Xf/BovG3rJ8Vd9G80bHpg == X-Google-Smtp-Source: ADFU+vsaMVodQrt8fK7Xeo77EHHhgaGJzxfM6FRj/fsYav29Hjp4KAQ7ePWiYXBNyh3DAxVWZyywGoXDdk8j26c6ilY= X-Received: by 2002:a17:90a:5a42:: with SMTP id m2mr1457381pji.165.1584999829660; Mon, 23 Mar 2020 14:43:49 -0700 (PDT) Date: Mon, 23 Mar 2020 14:43:36 -0700 In-Reply-To: <20200323214340.182724-1-emilyshaffer@google.com> Message-Id: <20200323214340.182724-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200323214340.182724-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v10 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 23 21:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11454059 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 482AB913 for ; Mon, 23 Mar 2020 21:43:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B82C20753 for ; Mon, 23 Mar 2020 21:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q4md4hS1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbgCWVnz (ORCPT ); Mon, 23 Mar 2020 17:43:55 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:41267 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727093AbgCWVny (ORCPT ); Mon, 23 Mar 2020 17:43:54 -0400 Received: by mail-pl1-f202.google.com with SMTP id m9so10505392plt.8 for ; Mon, 23 Mar 2020 14:43:52 -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=Q4md4hS1BaCvtzF6pCjkPcvF0vb/R48PTzvAX3AC30yB9ghif2Cs6pI7waGmeQ/f1D XcuQI3zSndjlzOJRqXnnidHpCFPVy43ofOkQVOG0r4KbstwJfioYCaUTtVcW3mjQWZyz Q4sYT8Vuf73W/wdoY1PtVLf8Ovdsz3pp6ADm2nq/8/nWzZnWu29DxJHN7Z33Ext1kMFd bToF3YeiIwHMti093KXpzqAIHfLdBP3tBtRO/s2UxZy0LGuPQd22tBy4Y/gRwLxBPnLH +DMqG/Y+xGnWe1R2qBBcp8+maELXmftem0o/y4HU44YVUzxjnFBoyVm/WY01KXzre1oU PjWA== 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=NtQf/ycN7PYlIHomP6Xkvdc/c9O+FaHfHrVblpXqhopqeCKTjgUtEuJ3X9wSeHusBt 11uEsT0DqynDr0HNjpSSErJXvd4IDK2jgtaGPXVOfYSHRRYx89OrBeNlJeT6MV4LAk3A mdeNkZpayCcUljgQXFpXX7i7qpxXxvKuSyPuDNzCVAWTHZv3LIDV82Le9PNZlQQVDeEc RzRwBUXoAUX3inloPh7R1UuwXuug3PCcKr20fqahyWNqn4/Ji1xMpFFJPuu44TxJoZ6X t1qFGV0LHpMZELdXs9ZXR7qNu+loPtMROY+YDAEEUipTD5m7CyVIxMzeSZl70Lt0fKQk biJA== X-Gm-Message-State: ANhLgQ3gX2bY/UfZpn5+TqvAFeUYcEwdVRXjTGaWQkhzn8jHvbkW0fiH kBVzocn861xuQrcgQLISWb6rPNxHE1amUoK1n2AxHiDFsAUJgdpxxDYNurw/XDV/sf483Xm+OuV ugxT04aHWEXE+uMFz1T6rASg+pvq0xscvQDK4l04AEMsVBHAjsDbrDaQz8zbsVTcFmGHnkhJmOw == X-Google-Smtp-Source: ADFU+vuaskbQExRg8v+jTTZQA6wUsmcIdTioPk34swXJ5ccDWRG1IQVaXxXNdSjzGoJjdn/cEFlbkyrb7WZAabJR+Hs= X-Received: by 2002:a65:60d7:: with SMTP id r23mr19753271pgv.321.1584999831878; Mon, 23 Mar 2020 14:43:51 -0700 (PDT) Date: Mon, 23 Mar 2020 14:43:37 -0700 In-Reply-To: <20200323214340.182724-1-emilyshaffer@google.com> Message-Id: <20200323214340.182724-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200323214340.182724-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v10 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 Mon Mar 23 21:43:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11454061 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 B5716913 for ; Mon, 23 Mar 2020 21:43:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8DAFD20753 for ; Mon, 23 Mar 2020 21:43:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WRvnaND+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727105AbgCWVn6 (ORCPT ); Mon, 23 Mar 2020 17:43:58 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:52264 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727093AbgCWVn6 (ORCPT ); Mon, 23 Mar 2020 17:43:58 -0400 Received: by mail-pl1-f202.google.com with SMTP id 64so10507021plf.19 for ; Mon, 23 Mar 2020 14:43:55 -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=WRvnaND+WCgcijZjaYgFSs4sIWXXUYRGHT3gtyL9HUqIM1V6poCU5sz9hSJiw80xjl T0AomMb/n1OW0TXNE5f/1K3CL5pL4KIO4xQe2qo4agCwMzs1bNlauq86ZioWWy9jyunz VG68g930TopIKIMpgp+iG0vwrknlD60rCxNIFVsk6eIJVUGHKo1Sqh31HGBXylVw4h0E ovIx8P0tfGQaYtyiEUTbF0fhO3RQQ4zZugQmvJz0kb7wP+KZwB+qNrBi73+RPo2sV08w m7ZnEjv0xeER4jRgWqaZ/YRJjO0otbQLcCCM31JKMR3UEvQPtxAJTcl4D7XcLak6pFtO aGUQ== 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=uIRSmGYbKdz4akuhenQzCapmPss4u5sCiXrZbCzB8YIuMHHhMlWlVjTEFHsRLtkMmF lIwHRmPiqPnRv7o/ZQdkIxEY0p9Vck23CSGjF8dvPnD2uQbGve8424+DpkvdQtMDgXtU ile4/KuVK4s9NQxtR/J1VzXjbu9M03jl648k6Fh3Th6OZaNpUr4L5E9fABfNu4WRTojI otpAuNKCNCwlJFbZP7uBml6++7Os85xh6wyQhOkkmYWosbIpAo1fIJsdpdTtUerlxx1H 5ikt5hA0+VzEKsjgkPb7vBD7LCgyQUCH6ku/Hv310y8egi+YYNnwp0aWh721iWmT+wBV gYEg== X-Gm-Message-State: ANhLgQ3eYup+PEE8xInqs3r0qLTXe6D6T6RLJGR9VkECJRoBPbaStgM5 fkg9yo0uuufKQwfe7CGFxJmkqtSV7uFIYA7Esfa29Id3uppWU/lmwPWCYFQUkyBlQlzabAqFexY O0QqTLwgkzdjK6wz/a2QP/Xi/95hk1BrtCQ0QKiv0AifwHZq4yJWwRXE6zuLdE36mjHB+iJJMZQ == X-Google-Smtp-Source: ADFU+vufPEHUvpKBpV6J8/AryqpI/k9om6DATT2DDKTTLbsN905+FUsk5nSBipSFhf3j4SqgEnSvjILRG+g7YAIQKkw= X-Received: by 2002:a17:90a:3a8c:: with SMTP id b12mr1599858pjc.48.1584999834554; Mon, 23 Mar 2020 14:43:54 -0700 (PDT) Date: Mon, 23 Mar 2020 14:43:38 -0700 In-Reply-To: <20200323214340.182724-1-emilyshaffer@google.com> Message-Id: <20200323214340.182724-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200323214340.182724-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v10 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 Mar 23 21:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11454063 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 BDF37913 for ; Mon, 23 Mar 2020 21:44:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9FE3B20753 for ; Mon, 23 Mar 2020 21:44:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="t9wD3ONT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgCWVn6 (ORCPT ); Mon, 23 Mar 2020 17:43:58 -0400 Received: from mail-pj1-f73.google.com ([209.85.216.73]:51399 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbgCWVn6 (ORCPT ); Mon, 23 Mar 2020 17:43:58 -0400 Received: by mail-pj1-f73.google.com with SMTP id gx19so897833pjb.1 for ; Mon, 23 Mar 2020 14:43:57 -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=t9wD3ONTc4s79KBEXzVllxSLSaythSSoF4buAAUO7aFVy48qDa4c4g5hurpMv5EedY i9tjq8ECXbSBtZLALHl2KkEh1z9KmH/Hj/hk0d7GvKfiwuFFw83UNjI+BiPel72aQM2o rHjwlWzsG4wQc7MvIkodGdL4+BnAZikNaWx4GaRAI/rbGqEzUFl1zqm2QImF41a2z2gl KHoG5p0PaNc/yUrVOnn8JV0yXsoxrRbYw/Epv1VVkEhHJnzFND9/1/vPWLB2WK5IW1TW lP3o0bvs8qFQznyAzSzdJaqkWDCFYSzwI9mUKK1hpF4CYA5yUt0TF9C56yjxRuZsncTV dLzQ== 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=nlh39auEaxBObIyKdHLwM2qaOeomueA4pHALr7RiYXbCmfTXtSfrT2X1Fxun+W7BOR jqUTU76Y/J/s8rTV9+Xca0UrYkBZF46saElKA2QhC+Kx324bQUiL0F5yqOJwuZnvysJK MEnSyEhrZB3Q/b4g1HRhIX5pxhoj2j/2ItZ19JPXRK+sR4BJBUuwp3Xse9iN19rWIbRF NZ9icubXbYWWvyzh9Ga9Z04BIAWYU5IynwT8UbcPFF522/K6p/uMotZV6GAuVX1RKviI /Hn16uZ6I/3VU26GGywzgG7qlTXhjMD4UBqa1gKInaZkESYYwGYyoE5zjEdVYh51MSmJ MOeQ== X-Gm-Message-State: ANhLgQ3IDqY4jSBOqp+JnuM4jAuawWTZ7JUZMnRgryQVNXUHsMQgJAYd ooOIm7fgfY44AsUlnR3mjTNthGyP7zQVflnv/BtfgAPrSx2rhuvvGx1kTvntjj2ixSoxWGB1Gqs FnapE+EPSnR1ljb5EBxKqe6Xf13vVf9SWtFEHN8/TjFo2lvYhoILjOBvicYaW8lfOa+UsBWClWg == X-Google-Smtp-Source: ADFU+vs3xAJEYgoVIU+i7AcKoiV2xrWc/UkYd3acVeqoek+kumQ5hewexrpPebcnbLjRFqZC+a8YyuUO6OsIR08fECU= X-Received: by 2002:a17:90b:1257:: with SMTP id gx23mr1584772pjb.14.1584999836712; Mon, 23 Mar 2020 14:43:56 -0700 (PDT) Date: Mon, 23 Mar 2020 14:43:39 -0700 In-Reply-To: <20200323214340.182724-1-emilyshaffer@google.com> Message-Id: <20200323214340.182724-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200323214340.182724-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v10 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 Mar 23 21:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11454065 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 A4690159A for ; Mon, 23 Mar 2020 21:44:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 867E920774 for ; Mon, 23 Mar 2020 21:44:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VI9Val5r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727093AbgCWVoC (ORCPT ); Mon, 23 Mar 2020 17:44:02 -0400 Received: from mail-qv1-f73.google.com ([209.85.219.73]:43189 "EHLO mail-qv1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbgCWVoA (ORCPT ); Mon, 23 Mar 2020 17:44:00 -0400 Received: by mail-qv1-f73.google.com with SMTP id h12so6153794qvx.10 for ; Mon, 23 Mar 2020 14:43:59 -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=NM4VxWFJxVfID7wVIFcg2NA8ECmuRaM6FxbEcYtXvyk=; b=VI9Val5rcazAVjukgZTBQVlWc5QRzC0LLTDmbYQnZYQtBzF2J7ZEBdZZp0ilgVZT64 9H+ko57IFLWNjCGkSwz8mdwhJJjK72mNA9Z6D1AvPFxL0CMylO77qqC9QPMdf7GZ6wD7 1QJF/myJv+X5GckYlTaMfyY8RXt+WYbfKC4p92Op6e2rEod4qMwtFWdOuXSFYp8u+cqb bYHp2rx0KIdROGmlSzmhKC2yzfZulGzJFERJr8t5yIP0W5jAzXhru5Kp/ucEYxU7PMDt nF7n4WuXRvrHFo221ocWdySJsjGXIWartVyMsfaxs7xGHVqotooryH+dImE49iL01rSs 3IgA== 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=NM4VxWFJxVfID7wVIFcg2NA8ECmuRaM6FxbEcYtXvyk=; b=sUpPSHmpDhUXlKt3N8e7W4S79qgSvAu33A2UnQJlh9tQiHJNZ6hc9cFrfrDeX/3DoY ktHwUhUTgTz4nvAzY4n7yQ3GOuI3oo3KKqdafZWJcaXSUv3KlCjnTyVIJZYmA6Io+H+h cZRnq8xg4D4EkIfewHqx558imbpxu07dtGI+K0KNu/xk8ahiEQ23WSoUDKLtQ7l2kyHc FWZ+/khiQVPLwwzg3HOtCCGm2AsDeYc9iwQtsyGX7eWwHIvb5Pb8nCrFbSzB/4hWHBhv I65gOpZG3ApIzb7YDCwZlksilkiythmcvREEfpezo3tsJ0QVZGOcc7ju75W7ktOlltst lsNQ== X-Gm-Message-State: ANhLgQ2pqoZNtsf7SXvG+peu4tW2MgXV1JhhYux5UofzDFoxUTaguox7 BF3atlFwTYFeOclcvpcQp1vGsZEt92llTCQ2X1FfKe5pm6IrTx3FZrQp2PkCHxEEFUcxRoQ9bba qByFVKftBfvH7S5Qgxs1vUbKdilUCqqVcbV8kKz0jr5XbcJGr/6P679E8IQ3BEta50R5r3aosSg == X-Google-Smtp-Source: ADFU+vu9b30XLqCyfcV9AaO7QIdDb3DhId9zO/AsHDHhBy2MDSTG393RkGdHly6bsH+F5ywiNEmOF/8l2xAQw9RvalI= X-Received: by 2002:a37:9ecc:: with SMTP id h195mr21285916qke.448.1584999839222; Mon, 23 Mar 2020 14:43:59 -0700 (PDT) Date: Mon, 23 Mar 2020 14:43:40 -0700 In-Reply-To: <20200323214340.182724-1-emilyshaffer@google.com> Message-Id: <20200323214340.182724-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200323214340.182724-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v10 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 --- 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 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..ce6a7f6de9 --- /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_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 */