From patchwork Thu Apr 16 21:18:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11493773 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 30FB9174A for ; Thu, 16 Apr 2020 21:18:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1422222201 for ; Thu, 16 Apr 2020 21:18:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CmAUTQje" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729134AbgDPVSV (ORCPT ); Thu, 16 Apr 2020 17:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728720AbgDPVST (ORCPT ); Thu, 16 Apr 2020 17:18:19 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C69EC061A0F for ; Thu, 16 Apr 2020 14:18:19 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id n23so2622726pgl.11 for ; Thu, 16 Apr 2020 14:18:19 -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=Co3rX8is8Q1ANrVTgOMurvCyxSDmG4LsOzFDoackZ5o=; b=CmAUTQjeWd+F62sy0OLSjVrguNPVxpF/RUsIeGlpJ30oQyoslsMK/viS0zzwbF0/82 eWjzIbjBFrtVAc9p2HqaYw0oeqlnrblRuWt8WTPclml+aI34lQdopQU16SjdY9vGxeKl KxuFjfpwdkg+SjS5iYugr1JctYzZY0q1TOVhfSQUVP/hzBSjGKX4rMzeWJ75zPU99/+9 fzs4wzkvLGG228jK67Lub1bNrPzcMSHZO9JwopLgn1BUkk2KsN6MfzOXJMvxt2N++++B lS2DYS95gDVzYxRcV4WWuLnPvNq0DJzl0PvD9eE+Dpi50Sb0LTPwP4LEfHwiNz4iwQ1A LY+w== 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=Co3rX8is8Q1ANrVTgOMurvCyxSDmG4LsOzFDoackZ5o=; b=L/aODX4g7xpCSgHbm4N5usKVolFiLcrGQMlLD1EU3663EfqCKYzSwBTI4mtpuiVuxw bU/jgTOd0QPxq1AnGNQPr7HDXfIaZ0SwtGfgcWCSQdDI4A2oN2h2rY1pPkpbNnYVf1OR aGeajrITjERwKS0XOr0AkLLWJirYX5HNmtZzuHhJ1HQVKA4iQKW9cpn3fABiXxSeySMd otcFfiB5bb0mKhf/xSOwtXJUI7PdzDqHQF8uVWQZq/2PtUUrGJe2bSq2T5jlMmN84lKv RmUNCvHGe3hEsmpNOVoKR468AT9Z3mybPoog46xLu+9InOeDY5w57J4CrO27utCIoY0Q J/7g== X-Gm-Message-State: AGi0PuaECAyySVvuzlx0LwgFjreH8PO/x+E40IGDF+gaKTPUaGVhIyry RiXANwJJhapo2CQ8paOkTVVYg28K61P28Cos8vEcVGZ48Ziv/OglPtdPX3LmxdW5rdbbBumLbQn mMpghk7aVuz4mlROaje3lgP+WI/TGdGtSsWAuMu+2CeEJuEJX3oXlX1reMjZ6VP6OJMJZPc75RA == X-Google-Smtp-Source: APiQypLTSoMpMU1fJJA2VkkctI502YLCnVRcoE86W5KENLgIlb85WhIVuN4TaHNfuquylm6O1EGjirBqsHlB/+ab59o= X-Received: by 2002:a17:90a:8d12:: with SMTP id c18mr349701pjo.144.1587071898878; Thu, 16 Apr 2020 14:18:18 -0700 (PDT) Date: Thu, 16 Apr 2020 14:18:03 -0700 In-Reply-To: <20200416211807.60811-1-emilyshaffer@google.com> Message-Id: <20200416211807.60811-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200416211807.60811-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v13 1/5] help: move list_config_help to builtin/help From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , Junio C Hamano 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 msvc: the bugreport topic depends on a generated config-list.h file For reasons explained in 976aaedc (msvc: add a Makefile target to pre-generate the Visual Studio solution, 2019-07-29), some build artifacts we consider non-source files cannot be generated in the Visual Studio environment, and we already have some Makefile tweaks to help Visual Studio to use generated command-list.h header file. As this topic starts to depend on another such generated header file, config-list.h, let's do the same to it. Signed-off-by: Junio C Hamano Signed-off-by: Emily Shaffer --- .gitignore | 1 + Makefile | 13 +++++-- builtin/help.c | 86 ++++++++++++++++++++++++++++++++++++++++++ compat/vcbuild/README | 4 +- config.mak.uname | 6 +-- generate-cmdlist.sh | 19 ---------- generate-configlist.sh | 21 +++++++++++ help.c | 85 ----------------------------------------- help.h | 1 - 9 files changed, 123 insertions(+), 113 deletions(-) create mode 100755 generate-configlist.sh diff --git a/.gitignore b/.gitignore index 188bd1c3de..61bf5142a9 100644 --- a/.gitignore +++ b/.gitignore @@ -188,6 +188,7 @@ /gitweb/gitweb.cgi /gitweb/static/gitweb.js /gitweb/static/gitweb.min.* +/config-list.h /command-list.h *.tar.gz *.dsc diff --git a/Makefile b/Makefile index ef1ff2228f..d4aff7f9b5 100644 --- a/Makefile +++ b/Makefile @@ -815,6 +815,7 @@ LIB_FILE = libgit.a XDIFF_LIB = xdiff/lib.a VCSSVN_LIB = vcs-svn/lib.a +GENERATED_H += config-list.h GENERATED_H += command-list.h LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ @@ -2133,7 +2134,7 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h -builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX +builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ @@ -2153,6 +2154,12 @@ $(BUILT_INS): git$X ln -s $< $@ 2>/dev/null || \ cp $< $@ +config-list.h: generate-configlist.sh + +config-list.h: + $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \ + >$@+ && mv $@+ $@ + command-list.h: generate-cmdlist.sh command-list.txt command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt @@ -2786,7 +2793,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE .PHONY: sparse $(SP_OBJ) sparse: $(SP_OBJ) -EXCEPT_HDRS := command-list.h unicode-width.h compat/% xdiff/% +EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/% ifndef GCRYPT_SHA256 EXCEPT_HDRS += sha256/gcrypt.h endif @@ -2808,7 +2815,7 @@ hdr-check: $(HCO) style: git clang-format --style file --diff --extensions c,h -check: command-list.h +check: config-list.h command-list.h @if sparse; \ then \ echo >&2 "Use 'make sparse' instead"; \ diff --git a/builtin/help.c b/builtin/help.c index e5590d7787..1c5f2b9255 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -8,6 +8,7 @@ #include "parse-options.h" #include "run-command.h" #include "column.h" +#include "config-list.h" #include "help.h" #include "alias.h" @@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = { NULL }; +struct slot_expansion { + const char *prefix; + const char *placeholder; + void (*fn)(struct string_list *list, const char *prefix); + int found; +}; + +static void list_config_help(int for_human) +{ + struct slot_expansion slot_expansions[] = { + { "advice", "*", list_config_advices }, + { "color.branch", "", list_config_color_branch_slots }, + { "color.decorate", "", list_config_color_decorate_slots }, + { "color.diff", "", list_config_color_diff_slots }, + { "color.grep", "", list_config_color_grep_slots }, + { "color.interactive", "", list_config_color_interactive_slots }, + { "color.remote", "", list_config_color_sideband_slots }, + { "color.status", "", list_config_color_status_slots }, + { "fsck", "", list_config_fsck_msg_ids }, + { "receive.fsck", "", list_config_fsck_msg_ids }, + { NULL, NULL, NULL } + }; + const char **p; + struct slot_expansion *e; + struct string_list keys = STRING_LIST_INIT_DUP; + int i; + + for (p = config_name_list; *p; p++) { + const char *var = *p; + struct strbuf sb = STRBUF_INIT; + + for (e = slot_expansions; e->prefix; e++) { + + strbuf_reset(&sb); + strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); + if (!strcasecmp(var, sb.buf)) { + e->fn(&keys, e->prefix); + e->found++; + break; + } + } + strbuf_release(&sb); + if (!e->prefix) + string_list_append(&keys, var); + } + + for (e = slot_expansions; e->prefix; e++) + if (!e->found) + BUG("slot_expansion %s.%s is not used", + e->prefix, e->placeholder); + + string_list_sort(&keys); + for (i = 0; i < keys.nr; i++) { + const char *var = keys.items[i].string; + const char *wildcard, *tag, *cut; + + if (for_human) { + puts(var); + continue; + } + + wildcard = strchr(var, '*'); + tag = strchr(var, '<'); + + if (!wildcard && !tag) { + puts(var); + continue; + } + + if (wildcard && !tag) + cut = wildcard; + else if (!wildcard && tag) + cut = tag; + else + cut = wildcard < tag ? wildcard : tag; + + /* + * We may produce duplicates, but that's up to + * git-completion.bash to handle + */ + printf("%.*s\n", (int)(cut - var), var); + } + string_list_clear(&keys, 0); +} + static enum help_format parse_help_format(const char *format) { if (!strcmp(format, "man")) diff --git a/compat/vcbuild/README b/compat/vcbuild/README index 1b6dabf5a2..42292e7c09 100644 --- a/compat/vcbuild/README +++ b/compat/vcbuild/README @@ -92,8 +92,8 @@ The Steps of Build Git with VS2008 the git operations. 3. Inside Git's directory run the command: - make command-list.h - to generate the command-list.h file needed to compile git. + make command-list.h config-list.h + to generate the header file needed to compile git. 4. Then either build Git with the GNU Make Makefile in the Git projects root diff --git a/config.mak.uname b/config.mak.uname index 0ab8e00938..f880cc2792 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -721,9 +721,9 @@ vcxproj: echo '') >git-remote-http/LinkOrCopyRemoteHttp.targets git add -f git/LinkOrCopyBuiltins.targets git-remote-http/LinkOrCopyRemoteHttp.targets - # Add command-list.h - $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h - git add -f command-list.h + # Add command-list.h and config-list.h + $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 config-list.h command-list.h + git add -f config-list.h command-list.h # Add scripts rm -f perl/perl.mak 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 Thu Apr 16 21:18:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11493775 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 73E051392 for ; Thu, 16 Apr 2020 21:18:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52700221F4 for ; Thu, 16 Apr 2020 21:18:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MgZC985g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729279AbgDPVSY (ORCPT ); Thu, 16 Apr 2020 17:18:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728720AbgDPVSW (ORCPT ); Thu, 16 Apr 2020 17:18:22 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01354C061A0C for ; Thu, 16 Apr 2020 14:18:22 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id h16so4324770pgb.16 for ; Thu, 16 Apr 2020 14:18:21 -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=e8HNoWowZxAZsZnwQqY9TdtqFsIyvnERIuhflByXzR4=; b=MgZC985gtEnbJkjk55sKG+xqkxWm1YRHu4KtOsYB0xX/AozKZQLccY7lJSZQ4khSH/ vAWDefzBpcc3IDCjdWyjqCIycPcgBOojJjTbCzgrK5xYWwxFvAvgXZaXxrSbeN+Knaac +zSmeHCMgXcvu7oYFN9910rX1iN5OFRtXlQgTdae/pS9pAHIVLXwyFniwyb25q5q09cG mklfcwAANsS7CnwwMOrxXjMqy7vrS1hYlJ8KUeTDNJ0iQnnREgky1KCyIJyOSK5fVBu/ hVl6XNB4pxS/5mnqju7Dvp543VTWhJjO2zV8N7ZeLGWEK4KxGOHsYwDr/FEEZOMM+yof 6NbA== 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=e8HNoWowZxAZsZnwQqY9TdtqFsIyvnERIuhflByXzR4=; b=VQVuXd3JIPW6sppDreVi2bhvMDikUITJzmxB7PKOFDPyW+TVzqZjlEKwDoh3C0DQla Tqfzg47j3qxeWQO+rS8Tz5SSC4qu4CgJla1jTF/VHuw88kMqYC5PKJ8zqTJXgmIMchfh 27CtyC1Hp4aFlS1ySFdZr2yiWqqfiUs4UIX5zDva1jb5o7GESKUsfZf5sW/bUAPfcE+a AIAhEv+bhF15Qp4I5eAcRUk6x4ZRO/PCmCzRDt04/NP+pXkaoi1/IbLWEqsumjZtR6YZ K7mxNod9gBrAEW+GCdV9NluvvXIGFcS7GiNefx7VPNh3JsFe7lV5JxjxfBXxPJvYOsR4 wO+A== X-Gm-Message-State: AGi0PuYnlNz7cEPiDo4/bJrJUCUEVfeguZJBJNjzbUz5yXfQVsUqTRqz gsryV37iPJDhVvXpE42EEsNpcm6SalB2amISjtBNQvWWJxQ55f8pZhTPNh+ffIRsD8dqb49Hute 6tTno+1xrT0fBrAB8dfQzNWXAo2wuR7MxQDFcVW6W8I1skQFGxaNJQpSrhSQ8wAvtPRxMEY7+7w == X-Google-Smtp-Source: APiQypI+xjBSi34OftkdyVvNFbU6xe2sS8C4ywm9NYTrjiIBOjWRMV9M6wrvd+3kMNAcKRsiY0kyb3y1I59lTEMK1Bs= X-Received: by 2002:a17:90a:c78b:: with SMTP id gn11mr298954pjb.147.1587071901391; Thu, 16 Apr 2020 14:18:21 -0700 (PDT) Date: Thu, 16 Apr 2020 14:18:04 -0700 In-Reply-To: <20200416211807.60811-1-emilyshaffer@google.com> Message-Id: <20200416211807.60811-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200416211807.60811-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v13 2/5] bugreport: add tool to generate debugging info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach Git how to prompt the user for a good bug report: reproduction steps, expected behavior, and actual behavior. Later, Git can learn how to collect some diagnostic information from the repository. If users can send us a well-written bug report which contains diagnostic information we would otherwise need to ask the user for, we can reduce the number of question-and-answer round trips between the reporter and the Git contributor. Users may also wish to send a report like this to their local "Git expert" if they have put their repository into a state they are confused by. Signed-off-by: Emily Shaffer --- .gitignore | 1 + Documentation/git-bugreport.txt | 46 ++++++++++++++ Makefile | 5 ++ bugreport.c | 105 ++++++++++++++++++++++++++++++++ command-list.txt | 1 + strbuf.c | 4 ++ strbuf.h | 1 + t/t0091-bugreport.sh | 61 +++++++++++++++++++ 8 files changed, 224 insertions(+) create mode 100644 Documentation/git-bugreport.txt create mode 100644 bugreport.c create mode 100755 t/t0091-bugreport.sh diff --git a/.gitignore b/.gitignore index 61bf5142a9..ee509a2ad2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ /git-bisect--helper /git-blame /git-branch +/git-bugreport /git-bundle /git-cat-file /git-check-attr diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt new file mode 100644 index 0000000000..1f9fde5cde --- /dev/null +++ b/Documentation/git-bugreport.txt @@ -0,0 +1,46 @@ +git-bugreport(1) +================ + +NAME +---- +git-bugreport - Collect information for user to file a bug report + +SYNOPSIS +-------- +[verse] +'git bugreport' [(-o | --output-directory) ] [(-s | --suffix) ] + +DESCRIPTION +----------- +Captures information about the user's machine, Git client, and repository state, +as well as a form requesting information about the behavior the user observed, +into a single text file which the user can then share, for example to the Git +mailing list, in order to report an observed bug. + +The following information is requested from the user: + + - Reproduction steps + - Expected behavior + - Actual behavior + +This tool is invoked via the typical Git setup process, which means that in some +cases, it might not be able to launch - for example, if a relevant config file +is unreadable. In this kind of scenario, it may be helpful to manually gather +the kind of information listed above when manually asking for help. + +OPTIONS +------- +-o :: +--output-directory :: + Place the resulting bug report file in `` instead of the root of + the Git repository. + +-s :: +--suffix :: + Specify an alternate suffix for the bugreport name, to create a file + named 'git-bugreport-'. This should take the form of a + link:strftime[3] format string; the current local time will be used. + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index d4aff7f9b5..b0a9073788 100644 --- a/Makefile +++ b/Makefile @@ -680,6 +680,7 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) +PROGRAM_OBJS += bugreport.o PROGRAM_OBJS += credential-store.o PROGRAM_OBJS += daemon.o PROGRAM_OBJS += fast-import.o @@ -2462,6 +2463,10 @@ endif git-%$X: %.o GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(LIBS) + git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(IMAP_SEND_LDFLAGS) $(LIBS) diff --git a/bugreport.c b/bugreport.c new file mode 100644 index 0000000000..f6f53a5e8e --- /dev/null +++ b/bugreport.c @@ -0,0 +1,105 @@ +#include "builtin.h" +#include "parse-options.h" +#include "stdio.h" +#include "strbuf.h" +#include "time.h" + +static const char * const bugreport_usage[] = { + N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), + NULL +}; + +static int get_bug_template(struct strbuf *template) +{ + const char template_text[] = N_( +"Thank you for filling out a Git bug report!\n" +"Please answer the following questions to help us understand your issue.\n" +"\n" +"What did you do before the bug happened? (Steps to reproduce your issue)\n" +"\n" +"What did you expect to happen? (Expected behavior)\n" +"\n" +"What happened instead? (Actual behavior)\n" +"\n" +"What's different between what you expected and what actually happened?\n" +"\n" +"Anything else you want to add:\n" +"\n" +"Please review the rest of the bug report below.\n" +"You can delete any lines you don't wish to share.\n"); + + strbuf_addstr(template, _(template_text)); + return 0; +} + +int cmd_main(int argc, const char **argv) +{ + struct strbuf buffer = STRBUF_INIT; + struct strbuf report_path = STRBUF_INIT; + int report = -1; + time_t now = time(NULL); + char *option_output = NULL; + char *option_suffix = "%Y-%m-%d-%H%M"; + int nongit_ok = 0; + const char *prefix = NULL; + const char *user_relative_path = NULL; + + const struct option bugreport_options[] = { + OPT_STRING('o', "output-directory", &option_output, N_("path"), + N_("specify a destination for the bugreport file")), + OPT_STRING('s', "suffix", &option_suffix, N_("format"), + N_("specify a strftime format suffix for the filename")), + OPT_END() + }; + + prefix = setup_git_directory_gently(&nongit_ok); + + argc = parse_options(argc, argv, prefix, bugreport_options, + bugreport_usage, 0); + + /* Prepare the path to put the result */ + strbuf_addstr(&report_path, + prefix_filename(prefix, + option_output ? option_output : "")); + strbuf_complete(&report_path, '/'); + + strbuf_addstr(&report_path, "git-bugreport-"); + strbuf_addftime(&report_path, option_suffix, localtime(&now), 0, 0); + strbuf_addstr(&report_path, ".txt"); + + switch (safe_create_leading_directories(report_path.buf)) { + case SCLD_OK: + case SCLD_EXISTS: + break; + default: + die(_("could not create leading directories for '%s'"), + report_path.buf); + } + + /* Prepare the report contents */ + get_bug_template(&buffer); + + /* fopen doesn't offer us an O_EXCL alternative, except with glibc. */ + report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666); + + if (report < 0) { + UNLEAK(report_path); + die(_("couldn't create a new file at '%s'"), report_path.buf); + } + + strbuf_write_fd(&buffer, report); + close(report); + + /* + * We want to print the path relative to the user, but we still need the + * path relative to us to give to the editor. + */ + if (!(prefix && skip_prefix(report_path.buf, prefix, &user_relative_path))) + user_relative_path = report_path.buf; + fprintf(stderr, _("Created new report at '%s'.\n"), + user_relative_path); + + UNLEAK(buffer); + UNLEAK(report_path); + return !!launch_editor(report_path.buf, NULL, NULL); +} diff --git a/command-list.txt b/command-list.txt index 2087894655..185e5e3f05 100644 --- a/command-list.txt +++ b/command-list.txt @@ -54,6 +54,7 @@ git-archive mainporcelain git-bisect mainporcelain info git-blame ancillaryinterrogators complete git-branch mainporcelain history +git-bugreport ancillaryinterrogators git-bundle mainporcelain git-cat-file plumbinginterrogators git-check-attr purehelpers diff --git a/strbuf.c b/strbuf.c index bb0065ccaf..3bfcaababb 100644 --- a/strbuf.c +++ b/strbuf.c @@ -554,6 +554,10 @@ ssize_t strbuf_write(struct strbuf *sb, FILE *f) return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0; } +ssize_t strbuf_write_fd(struct strbuf *sb, int fd) +{ + return sb->len ? write(fd, sb->buf, sb->len) : 0; +} #define STRBUF_MAXLINK (2*PATH_MAX) diff --git a/strbuf.h b/strbuf.h index ce8e49c0b2..801a3694ec 100644 --- a/strbuf.h +++ b/strbuf.h @@ -468,6 +468,7 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint); * NUL bytes. */ ssize_t strbuf_write(struct strbuf *sb, FILE *stream); +ssize_t strbuf_write_fd(struct strbuf *sb, int fd); /** * Read a line from a FILE *, overwriting the existing contents of diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh new file mode 100755 index 0000000000..2e73658a5c --- /dev/null +++ b/t/t0091-bugreport.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +test_description='git bugreport' + +. ./test-lib.sh + +# Headers "[System Info]" will be followed by a non-empty line if we put some +# information there; we can make sure all our headers were followed by some +# information to check if the command was successful. +HEADER_PATTERN="^\[.*\]$" + +check_all_headers_populated () { + while read -r line + do + if test "$(grep "$HEADER_PATTERN" "$line")" + then + echo "$line" + read -r nextline + if test -z "$nextline"; then + return 1; + fi + fi + done +} + +test_expect_success 'creates a report with content in the right places' ' + test_when_finished rm git-bugreport-check-headers.txt && + git bugreport -s check-headers && + check_all_headers_populated >git-bugreport-duplicate.txt && + test_must_fail git bugreport --suffix duplicate +' + +test_expect_success '--output-directory puts the report in the provided dir' ' + test_when_finished rm -fr foo/ && + git bugreport -o foo/ && + test_path_is_file foo/git-bugreport-* +' + +test_expect_success 'incorrect arguments abort with usage' ' + test_must_fail git bugreport --false 2>output && + test_i18ngrep usage output && + test_path_is_missing git-bugreport-* +' + +test_expect_success 'runs outside of a git dir' ' + test_when_finished rm non-repo/git-bugreport-* && + nongit git bugreport +' + +test_expect_success 'can create leading directories outside of a git dir' ' + test_when_finished rm -fr foo/bar/baz && + nongit git bugreport -o foo/bar/baz +' + + +test_done From patchwork Thu Apr 16 21:18:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11493779 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 C6D05174A for ; Thu, 16 Apr 2020 21:18:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AACC622201 for ; Thu, 16 Apr 2020 21:18:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZtpU7jtF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729297AbgDPVS2 (ORCPT ); Thu, 16 Apr 2020 17:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728720AbgDPVS0 (ORCPT ); Thu, 16 Apr 2020 17:18:26 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD2CC061A0C for ; Thu, 16 Apr 2020 14:18:24 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id n205so4999229ybf.14 for ; Thu, 16 Apr 2020 14:18: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=pHXVx7heMiFh/UuvWD7sFgmkxFeXgOKDExum0QxHTNw=; b=ZtpU7jtFbiZqg8e0sfO0DzvJqiXC7uQgu9xEAUtyNpS9++X4qhdGJ8+PNiJX9n4yvw P9VgzKsPabhvxTtG0WgPkaOq8UR6fzC3NbaMVBwZC5lfVAojsV1UR8qM3RTxFefLB3/Y xoYB0V639/H1n0P7axB+NgOJuFBZ7TpFapiGll+0gAG+LCZxPckJIljjcFyhdkPYK/ag +I7DqpAXTp1MNN9IETneyeGBJ3XVmgCyDuXwzIgUu8IoELPU/bg5jXZcVM6G7LaR5+B1 wcfxhdpHvujejHg6sJTVgOVGsXuTdjxChZPXr//XHixkFNkzGEr+c2vpGhwHjnwwn2pC HRQg== 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=pHXVx7heMiFh/UuvWD7sFgmkxFeXgOKDExum0QxHTNw=; b=gHU90MZYumAh7NUTXBxE+r8PbYY3fiXDJhnGG+rb4WL2QJN64wTTi2nkpMmD3J+lIz BeDYdj57fTknB/X7XBU36Bqw5JYUmc4EusKQFtaReZJh3lNx4VIO1yY/MNrh3Va02ab8 VPkfv/uWUyToqCr50h59TvwJvd9bNGFsiZertUV36XPJ0r8xLbLcR3k3rNyiQlJBHr+q XTqc1ZY/HeSD8j0HZppamnVxuXR006wjHqXwMVbf8+LKMxa+hw+XcOxCZeMy8d4iFLuW mNl0XOI1YtJScTaAQRfB/l/V3xFu9Chw7+JfirFlPjcVtMPbYk1Z+vBHf9H2QsgMShPf O65g== X-Gm-Message-State: AGi0PubCtc6TtsCvayda8ayxiiSf/3dJLzwA4Q4O0wVlLNbxAW8YW0eO SG7KfmKNB+5HmJ6w5r4rQQ6fZamdLzx2ZXHdz0qdSs2G3K5zWz4vbIfjG+9PL850ulnXPXelm48 SAFKvGESUGPFKoLcgKwX1nbn7Jm2GpfTi479XXVs1gRqkZs+2FezioW/fN6RQRdEfhtoKyN5T2Q == X-Google-Smtp-Source: APiQypLUr5jR+sSMZGppVZCe0jlj08ZyWIShwDlr8gL/QD3nkZ9OsmQ7xtXRNl439WzTVTsxkUvN3zwoRE8twdaYx8E= X-Received: by 2002:a25:d890:: with SMTP id p138mr459441ybg.477.1587071903952; Thu, 16 Apr 2020 14:18:23 -0700 (PDT) Date: Thu, 16 Apr 2020 14:18:05 -0700 In-Reply-To: <20200416211807.60811-1-emilyshaffer@google.com> Message-Id: <20200416211807.60811-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200416211807.60811-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v13 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 Thu Apr 16 21:18:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11493777 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 C94B5174A for ; Thu, 16 Apr 2020 21:18:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1BFD22201 for ; Thu, 16 Apr 2020 21:18:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aYIA9dRA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729321AbgDPVS2 (ORCPT ); Thu, 16 Apr 2020 17:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729283AbgDPVS1 (ORCPT ); Thu, 16 Apr 2020 17:18:27 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E7AC061A0F for ; Thu, 16 Apr 2020 14:18:27 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id q57so90771qte.3 for ; Thu, 16 Apr 2020 14:18:27 -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=qrpJTHHFiNdCKtGrX5QcOu6SRNlpkXP+w4r4LTZUAPg=; b=aYIA9dRA5UbD4qwIHfKCajSQkoraY6wffgS61I7WV9BNgd5/7jQOy2QeB8/h82b+mB T4VOVuJVSNPpFASUnT3Hm0oL8rx7rknPJJxq2xkIQIq3swqLiGIm/303CMfJBFdrCPV1 DDR+ZkQDdwLr5K3ymPzeD5IA6CTCxDINsdIMRdlma6lil0SEBcAG4xHrw2lsyhVnxZBL q1WPtBDSgw7UY1XOdUAqtcXIF10CNueBhfZw1Hrj8Sn/OGhvrfLInF7vgpTzd3k3uVRQ +KpFaDLPD74qIHvhqBD+oDkxm8HExyJ3vsI6FW8ESVhG+tai444oUw1ifxrN+XXkasE6 RNog== 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=qrpJTHHFiNdCKtGrX5QcOu6SRNlpkXP+w4r4LTZUAPg=; b=i0YbaFsh3lZTbE11RSXc0mAkDLvU4eZNm5SfhvCPTb5Y7tTbgKWTryyC1suKCUntaR 6O755QZ+4ubYnowKs0FzC+a+3zJYvGt5xzmydPGfmti96kpVxIduAU490RJ7tLXJYmvx /1MR9iCFWtb98Us4dGIaVmQsmXB4sSTn8FLRrdtyXbCZO3g3B0xgwFxa+DKvF1rDW6/m HugIZNzXrfVAUZdiSXXe4PbG4QW7j0BO0o6cHfxWp/nArHs77BFnJ4auUtw654wmtIOz ZMCK6h1uV/AdVAuzf+tzVqHhWo7BvXKE9TrgEjYu5cZcH0gTZIbYKxFNx0tdcdQzrwiM GFhw== X-Gm-Message-State: AGi0PuZfn2fvOoukmRJshJpjgAnoDcGcaNRPJCqfRohiO1agmp6ILDMw Sz8PtEezdRs0rFr7W0oqYZdmdOuyRbePlXyp/CjIiAZx8+y2eOIjgNOc7Bl814zp7iU31qv5FIi vdRe4J2BfNl5MZptIz2p+MC8uW0fipr1y7q5k42Ef9H2F1bZu7fS9zjCykrgNzhlu4VBJz4bDjA == X-Google-Smtp-Source: APiQypLdj4bc1p1UVtw4bHtseNm+MgiraD/mB5hPZCXh26CYXcSobOBfFGropz7tZ/mwvvhGf3/7H1o4upJbjPLrdeg= X-Received: by 2002:ac8:514d:: with SMTP id h13mr28633990qtn.226.1587071906417; Thu, 16 Apr 2020 14:18:26 -0700 (PDT) Date: Thu, 16 Apr 2020 14:18:06 -0700 In-Reply-To: <20200416211807.60811-1-emilyshaffer@google.com> Message-Id: <20200416211807.60811-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200416211807.60811-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v13 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 Thu Apr 16 21:18:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11493781 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 890801392 for ; Thu, 16 Apr 2020 21:18:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DE952078B for ; Thu, 16 Apr 2020 21:18:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YvINIn2W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729342AbgDPVSc (ORCPT ); Thu, 16 Apr 2020 17:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729283AbgDPVS3 (ORCPT ); Thu, 16 Apr 2020 17:18:29 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 872D6C061A0C for ; Thu, 16 Apr 2020 14:18:29 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id t9so66874plq.10 for ; Thu, 16 Apr 2020 14:18:29 -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:content-transfer-encoding; bh=ryKk4rkw525L/geiZOSEDNqFNXRgcA1LUGZARUviQFU=; b=YvINIn2W8dEYBiBxjs9DZM05oRm+5HTP7gvKXkD/ic6YcHECNvUbWhO3OYFcIVd5qu xOc6k1I027ksUWHTzN/2q5bubkVLkqPxB4qOmk43TKL+g8i8bMEgRnN1GtTAhYOfc8qJ mrP+ttJz055WXONkLnOp+W7BVlWUGV7Q/RLgTjrlryirHrKGVkv/WC3vAvKZEv/J1DbD exMx+o0zeJuSCunA+rmO6PYMy+TAZ+y0SmurwQ81vbDGZZhRva1PQH5x4/UaU6x6rxeT UGaYCt5o5FaXadUoMmid6bBuMDg3y89jaNNL+uRp8xhPC8pZ9xeiTQcfXyL34Md/PksJ MvQA== 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:content-transfer-encoding; bh=ryKk4rkw525L/geiZOSEDNqFNXRgcA1LUGZARUviQFU=; b=blb9c5vqAlRBY+oNX8+alrezDQFurL1vi9Baq8LYNsU6hX6gWeU4kBtueu3/nRpv7y Cwt2+wcs9HpSO65hdeewtdpgPZHaD6GPxunYQXZQz4KtUvKsCLCRZri0PcU/BF9eXpfe pP/V2V39iFd2mln3MMliBE+wwMTYYv6M/FuJvYMxoXQ8/nvEp45mbkbJwqTX96VsttGk lw3vpVYhYuWhsEPyP/ki0TNCE6HEwWYBa+PUl1Fw5whQq7Zs9gfhFayDIjJnl30OiWme qf8q6WwMk0SyhR7gmuMS1KMcbv0OKkq5lKGlHwxP3lxxlsASGb5Hqyyuptl3D0QgEliL DAmQ== X-Gm-Message-State: AGi0PuY4xiF6b9z9df8HmqlckIJCfkVv+QmF/CXyKunAVWptrx+ynbIu Qf/a0g1XFIihuGQbKFEw7pkUne3iuJrkCR3EK7jK8dVUn9bTDKikXlX0Cke6xsedjiPRL/E7Hii 6jMLUL9Ym2xLOzWgKh0Snl3jVYYmMHKfOc5FJqIADBYIxqKtZGoqLzFnkNDse/Hza9kbb8TXeLQ == X-Google-Smtp-Source: APiQypLJE4/YZn0y9Vrf8rDMbdkR3xIY6BoKPdrc4CExpfClN1DrrmlU4jcax4DDIg8mM8uK8+2FT+0dVBPUA1aq5KA= X-Received: by 2002:a17:90a:284e:: with SMTP id p14mr374837pjf.10.1587071908789; Thu, 16 Apr 2020 14:18:28 -0700 (PDT) Date: Thu, 16 Apr 2020 14:18:07 -0700 In-Reply-To: <20200416211807.60811-1-emilyshaffer@google.com> Message-Id: <20200416211807.60811-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200416211807.60811-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v13 5/5] bugreport: add compiler info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , " =?utf-8?b?xJBvw6BuIFRy4bqn?= =?utf-8?b?biBDw7RuZyBEYW5o?= " , 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: Đoàn Trần Công Danh 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 */