From patchwork Fri Feb 14 01:53:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381503 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 35B55921 for ; Fri, 14 Feb 2020 01:54:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B6CE20848 for ; Fri, 14 Feb 2020 01:54:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Os/PfQCs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728261AbgBNBx6 (ORCPT ); Thu, 13 Feb 2020 20:53:58 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:52253 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727988AbgBNBx6 (ORCPT ); Thu, 13 Feb 2020 20:53:58 -0500 Received: by mail-pg1-f202.google.com with SMTP id h21so5018446pgl.19 for ; Thu, 13 Feb 2020 17:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=iQhhKDtHVWPnk1bWYAryKauEwUz6R7Mm93lyAiDFL58=; b=Os/PfQCsdNBhPbARUIGuk4pblCZTg1JBesyrWpq7jbau2lRVuWUQVBWnJDOqMHMjof FXvRjr/rz1k3DeKhhbLmwKaeO1B0y3rYX1vEOYQwZMPEuJVZ/g2UOuhqhqOqSyMg2K9n 6fTawj8/w0ILDYIjU+wSmEs1dyez06JXO2O1at5XsEsh78flYToUqE4PaneZFYH+gmN6 nJ5aGZodLujRKUlzngFmmYN+Y/hdgQSaxeib3rX5GYvnTRTx9AajjblrS40avFxz31zq qRldzULWhy3aLfax4GrsC8WKopXJvZJ2RCDG+d4yLlPK44C/iG/7h3SxiDAxEbHH2CzM pfbQ== 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=iQhhKDtHVWPnk1bWYAryKauEwUz6R7Mm93lyAiDFL58=; b=QNfzfaWAFgdLnQsnhPe4tpUM7w/pWp68hmv4idBgNADmNXD1asMK+HCZuTLT7TEAR9 6t+iK8g1C+IigaPnEWzQ9hZOn5LMTGIJ6KtIOPB/18tfFXcUXrswPF2NTLR83LLjU4eX YI8EhsU2HrRPtIAGoqccqd6Sp6YNq20UjwaAGtWFmBfXT8VVokGqdlnIRyoRd5DcGKcq k1+8IVIwX2ffpbrVEx1/uLExWQgs738/KTSt8kFxNEKH0cnulKXgkuz/aATrxR6/mWUP z1n3E93VSCKS2rBAzgidAztBH5xk0R/+HBWdXqhc3ug20HE1ugNKBeFpXuoGancYu2yM eQeA== X-Gm-Message-State: APjAAAULkfqbmDtSOP7g/5RPmF9/1kyKjf/NR/InB6IYKWocoDkEf552 QMhWIsTMPM95HxEPJvqp/m9mJvKCc1Q7T/u1lej6Lx3GXtoZgweahYiHfKXMy0paj6GbVfyVzCn 7COzWHuk1iUNuwAm34WhNf7j4ZLEeI+NeIcUJsrwwIMty1Zn03OpdVoIPhoCcL2RIcRP5b3sc0Q == X-Google-Smtp-Source: APXvYqy3fuQrGYkLwA68GCZ6kjXCdR8AptJs53eTCZdI1cyjlzgsGo5roBWRvCDzUbIsfjq6Rywz9oXaI7xhg/u5i8Q= X-Received: by 2002:a63:3308:: with SMTP id z8mr881823pgz.230.1581645234018; Thu, 13 Feb 2020 17:53:54 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:29 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 01/15] 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 09f98b777c..5a022367d4 100644 --- a/Makefile +++ b/Makefile @@ -814,6 +814,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 || \ @@ -2128,7 +2129,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)"' \ @@ -2148,6 +2149,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 @@ -2781,7 +2788,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 @@ -2803,7 +2810,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 Fri Feb 14 01:53:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381501 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 02C441820 for ; Fri, 14 Feb 2020 01:54:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5D8020848 for ; Fri, 14 Feb 2020 01:54:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ktMQoQWf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728275AbgBNBx6 (ORCPT ); Thu, 13 Feb 2020 20:53:58 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:36319 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728193AbgBNBx6 (ORCPT ); Thu, 13 Feb 2020 20:53:58 -0500 Received: by mail-pl1-f202.google.com with SMTP id bg1so4254424plb.3 for ; Thu, 13 Feb 2020 17:53:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=cX0wSw+SUUTI4SBcSf/co+qSodXsGSCbZOly9kNlUfg=; b=ktMQoQWf2j8O/iVPyzTDyZXeDCIPrntyjqomR8YG/0o40Rrb8ZDeIgvFzJwZV4vbBB vwQwwJGBrzipndOzhd4bcon9Xw8ONPmiXY6Ms861RXFGkTigZLEVXP8y1ntRxWndhd1t TkvcfY18Fus3Jl4wJjYF5Vg/EgEViDAZXmOeebsHEmsHEhN6rrfyZqVkc9RJoHSSvCb1 WnWFWFBS7Nv0WcEiB1FuPVUw9VSI87Yd97I0uLy9rb53Z2ppKtRXcx5W9jPK9bHxW5kr 2K69+7DFSekF1/Kl93x3G9A9ZrosZtnfDapk3v5qTVMHpYVwZraZkLMHxs82ES1ycp71 x5xg== 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=cX0wSw+SUUTI4SBcSf/co+qSodXsGSCbZOly9kNlUfg=; b=lRfe3IZBQNq2O1RA19yK6A8Nrt5sTYyh5derOkv0pkofhA/uUY1EgZwKGD5VVV24N4 FPKagc3sUw1JoIjYGJxWG+JIMphabrN0RXK0+CkCpWXT6bggaNTLUobJKoIW+1rFt+SB 5BDKlu2CgLUY/oyoovdEfRsG0UcErCQLTJnsRMJczIL7t2M7qcwZWnlgUytt9YHtFiyr Cb2QivcfsfXzAqiJJ1kMVn8VVYIAzeSuYITdHdm6L9qWB26fGYaaTChzGb2m3/4ojorC xkP7RU+yilT48/JT07iqAUcK3LhZ/2ZqNFlfBNhZ59UDjjNP/oi1gfVLz6x/y8VnXHao g7iw== X-Gm-Message-State: APjAAAX5IHJ3mQIzvUWF6IHbNfX5To+OWA8SbCLQLZy8qYH2GmKFyxjS KkbXOomTys+0cvq4vY4sa8Z7Bs4dmLlZbJLQzWIC0H8De4Y6kj/QQeQy73Cxr+8q7lJ7eyzPM8m ch5gQ+MZd1SSIfKbO5j44lIPhLvbrTSYCFuqFHTQED04YiJ0WtTJezUEz8lb+2cwYvJ1AC58OTA == X-Google-Smtp-Source: APXvYqx90i9mgYEZAFqIonWjINlOwDX/N+ImjhGZhAqIyK/h7Qa/4C/EukzY03ZU0AY+X1NNRf7HVojaWMjr848tp+E= X-Received: by 2002:a63:3e8f:: with SMTP id l137mr871749pga.360.1581645236297; Thu, 13 Feb 2020 17:53:56 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:30 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 02/15] help: add shell-path to --build-options 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 It may be useful to know which shell Git was built to try to point to, in the event that shell-based Git commands are failing. $SHELL_PATH is set during the build and used to launch the manpage viewer, as well as by git-compat-util.h, and it's used during tests. 'git version --build-options' is encouraged for use in bug reports, so it makes sense to include this information there. Signed-off-by: Emily Shaffer --- help.c | 1 + 1 file changed, 1 insertion(+) diff --git a/help.c b/help.c index a21487db77..190722fb0a 100644 --- a/help.c +++ b/help.c @@ -654,6 +654,7 @@ int cmd_version(int argc, const char **argv, const char *prefix) 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)); + printf("shell-path: %s\n", SHELL_PATH); /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */ } return 0; From patchwork Fri Feb 14 01:53:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381505 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 5FA9018B8 for ; Fri, 14 Feb 2020 01:54:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EA2720848 for ; Fri, 14 Feb 2020 01:54:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ouLE294c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728297AbgBNByA (ORCPT ); Thu, 13 Feb 2020 20:54:00 -0500 Received: from mail-pj1-f73.google.com ([209.85.216.73]:51442 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728193AbgBNBx7 (ORCPT ); Thu, 13 Feb 2020 20:53:59 -0500 Received: by mail-pj1-f73.google.com with SMTP id z5so4774366pjt.1 for ; Thu, 13 Feb 2020 17:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=yx7G+XXlQ+ditWfSOivUnzKInA16uK7KS/3Amg6vdTM=; b=ouLE294cVJnMARew+0VgmrMXoCeEknH2H9y6d+LRGLmCu3iUAOAz8+8HjoRJ5ib/4T z0973FjU55N+MH/a2VfcL3E7BXDULtxJQOk6ygoLzquX9ADH0tq16RemSfPdhosq3kw8 XUlg+WVFfkDcAlOjGQPnvLxawaXMyL0n7GvmZHqLDmGuRUw2Mgx1I6Q5bwMJcln6uVhT G1mif2T3CszXqokplB0Jy4oIDhw5qUC+A+XUizMHXBvKDsLy4hVFY3S9TaZTQjmIL26u R94HZwYX4q58llLRk1mKu/CnEqw4duTlFGne6MpW0KC3TG5Soc2zqNoexsRwLROL8p6t peDA== 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=yx7G+XXlQ+ditWfSOivUnzKInA16uK7KS/3Amg6vdTM=; b=TQi+PDoNJDTa/UmlEzBhranr4Db7OAMTiCaq1qN/ECobDZ8NnuaXUg9aS54jDuex8Y fYrmAXxc9I5uxqPDRa0RKBMmHe0W3S1Oy79ZFZZ8xUiVplzXw5xqzw9yRRVEUcsAED7Z tdwjk5crg/9s2zs8PdQ6nzsN0rAAx22k5+7AUsSUCULjaNuAf8+5OqoZuedQ/6QOlSL3 lm0Pi/AF5vr//xcAtPaBanL+wida/q7cgEsRGcSf49WiO6+Rk7AsKKoaUdAb8GQbKFmE 6qvBNUDSwouRW3MBF/5+cO1uWuJFxhH8hPaZ/OsIvGM8/uGHV9ZHQ2BbacT1tsTlCqFY fTsA== X-Gm-Message-State: APjAAAWiEpw3nWWZfNkUYiQcx4nc5ZBT6mAXeG5ckHeIE5FWHatsx/2k rn6eyUf/bh9VbLoEGivmOGx7rxJTgGhhM0R47mLs1qCi/SYO9rGXZq7P316mO4bSN0tkzHHs9cL 6iYFxbeXaMn811Iyz2SugIJNxWSmI0mp5NtvhAEImk9RNr5hffpqeUYLORLmJcObDH4K4wmNj0g == X-Google-Smtp-Source: APXvYqxSsx7AuPhBNj/+GapxPjJcJScoAxhwfNezbJ69k1kS7pCr+3qmvtpZ/A2MK2YRPbfyQR1z2fwacmAliPj5hc4= X-Received: by 2002:a63:f648:: with SMTP id u8mr918413pgj.148.1581645238731; Thu, 13 Feb 2020 17:53:58 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:31 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 03/15] 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 | 41 ++++++++++++++ Makefile | 5 ++ bugreport.c | 94 +++++++++++++++++++++++++++++++++ command-list.txt | 1 + t/t0091-bugreport.sh | 55 +++++++++++++++++++ 6 files changed, 197 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..52d49ed7aa --- /dev/null +++ b/Documentation/git-bugreport.txt @@ -0,0 +1,41 @@ +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 + +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 5a022367d4..a01a050aa3 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 @@ -2457,6 +2458,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..a9398e6a2a --- /dev/null +++ b/bugreport.c @@ -0,0 +1,94 @@ +#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; + FILE *report; + time_t now = time(NULL); + char *option_output = NULL; + char *option_suffix = "%F-%H%M"; + struct stat statbuf; + + 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() + }; + argc = parse_options(argc, argv, "", bugreport_options, + bugreport_usage, 0); + + if (option_output) { + strbuf_addstr(&report_path, 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"); + + if (!stat(report_path.buf, &statbuf)) + die("'%s' already exists", report_path.buf); + + 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); + } + + get_bug_template(&buffer); + + report = fopen_for_writing(report_path.buf); + + if (report == NULL) { + strbuf_release(&report_path); + die("couldn't open '%s' for writing", report_path.buf); + } + + strbuf_write(&buffer, report); + fclose(report); + + fprintf(stderr, _("Created new report at '%s'.\n"), report_path.buf); + + 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/t/t0091-bugreport.sh b/t/t0091-bugreport.sh new file mode 100755 index 0000000000..6585a2d144 --- /dev/null +++ b/t/t0091-bugreport.sh @@ -0,0 +1,55 @@ +#!/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_done From patchwork Fri Feb 14 01:53:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381507 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 BEA1F921 for ; Fri, 14 Feb 2020 01:54:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92EB4222C2 for ; Fri, 14 Feb 2020 01:54:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cyP07kSu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728305AbgBNByE (ORCPT ); Thu, 13 Feb 2020 20:54:04 -0500 Received: from mail-pj1-f73.google.com ([209.85.216.73]:52323 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728300AbgBNByD (ORCPT ); Thu, 13 Feb 2020 20:54:03 -0500 Received: by mail-pj1-f73.google.com with SMTP id u10so4775884pjy.2 for ; Thu, 13 Feb 2020 17:54:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Iog73yocHVxDTujOdRes8en9G+RNUA1HswEzmsaeJck=; b=cyP07kSukMeZU5DP8aawFC37N5kgnjAbkNR0uQGUpjcGziW0mtoY8wdp3G4l86W+Or yPdvp0eLTJFI4eB6ed2Wi6fQ+kI3HtC9zq5SvIn83eTFS21IWhnfr7rhsXZDKnPTf17y OFp3PSbrkjJRFxAZqWxF0DTmP5ewHziQSGPYeQ3mn3c+0Xc7xf2SdPCNet1LkMx4ER/Y LF01yPjihg4JiU/qdhY9/RJOLXkqeK7xGDO031reeDCqPewKWseovvYQuPhQVfCjObAO sHXGhOG4TncoM2v7tMjWdBgukt/lxU40+LsAIy7wmvCZUtYTKcPC7kvNOPMcfyhpTnPU Dprg== 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=Iog73yocHVxDTujOdRes8en9G+RNUA1HswEzmsaeJck=; b=SZHjJPSOT/HzcVmJM1+r+SpPtvzxiUOXFk9VoAvnEr/HqeoJFmZnKDpfYVBSlT3Zwf w7CN8jamKxcRlubz+ImEcPfJcfEJikAMyoFvQE2YJES6VfTA9l/jtwut8J6P73kpRDDH 0FZXbBZChlK7H+P8L5BX+GS6x9s/JGaVsUdsqi2T8hT5ufOE6LieP2hU0YWqfXmUsHBy pWZxyihjC5aA+1t3rO0NrRaQ/KW3lYdZxomQ7otooGsc7PzfTt804X/eb7sX4H6j3pI3 KbFgpORnABnUXqdjrIxMSKaaDncMauQIL138V8vvPYZixDt/lnXmRewc6npqebrEcsuw PJdw== X-Gm-Message-State: APjAAAUxjVZdkaVgN8GQb3wOXd38SoMyiqf476eMIFg3dQGJ7flCR1uW +3hzhFGdoJHj/byQc5Zj23uU6xa1fOlgT2De0h6731HopZn7RTOVmqfZf9U+fvCNI6kNqCTNOtt BtCSjlHj74PMCKm+1/2612PqGQVqx48kJL5geLVSLtci4kcpDpAatWTHRSkMqIO02RZ6WRaxdCw == X-Google-Smtp-Source: APXvYqxBH7Hr5qAjiiybMo+tZOvcxzuo52QQsUk0UKQ3cuwCtkDNHouDzmwijcE9+QFd3kgd3QrySj8Ioox1kcFPRag= X-Received: by 2002:a63:7412:: with SMTP id p18mr818419pgc.361.1581645241119; Thu, 13 Feb 2020 17:54:01 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:32 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 04/15] 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 | 48 ++++++++++++++++++++------------- help.h | 1 + 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 52d49ed7aa..6ce2ae2eff 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' + OPTIONS ------- -o :: diff --git a/bugreport.c b/bugreport.c index a9398e6a2a..b7504fe322 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; @@ -76,6 +90,9 @@ int cmd_main(int argc, const char **argv) get_bug_template(&buffer); + get_header(&buffer, "System Info"); + get_system_info(&buffer); + report = fopen_for_writing(report_path.buf); if (report == NULL) { diff --git a/help.c b/help.c index 190722fb0a..44cee69c11 100644 --- a/help.c +++ b/help.c @@ -622,8 +622,33 @@ 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)); + strbuf_addf(buf, "shell-path: %s\n", SHELL_PATH); + /* 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,26 +662,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)); - printf("shell-path: %s\n", SHELL_PATH); - /* 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 Fri Feb 14 01:53:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381509 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 E847B1820 for ; Fri, 14 Feb 2020 01:54:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7CBA222C2 for ; Fri, 14 Feb 2020 01:54:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aWOUcAAv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbgBNByG (ORCPT ); Thu, 13 Feb 2020 20:54:06 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:41235 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728193AbgBNByF (ORCPT ); Thu, 13 Feb 2020 20:54:05 -0500 Received: by mail-pf1-f202.google.com with SMTP id e16so4978955pff.8 for ; Thu, 13 Feb 2020 17:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gQ3tMQClfO9NRhDHuTTv3sshyVDNk3yEHLSJCyjQC4o=; b=aWOUcAAv6VR08Z4mJoJaNxvnmKd91bx6AUtX28SWNXB4rCYy2CS0sEKjkFpcqfmu4F xp596dhQe+JB+lm1Z2E75jTy5ms7YRsCShwYPQx2HpUszGW/bo8yDIHNYZePlJ1006tM 57yAnip+i9MaoWhEZyCeRIgcvsOxJJ3/XocpScUGgxYbvd4SSvN7QqOVHlJ2eZ/SB4tO Da2XIvblllhliNrRG+DzYArpvs22BsOiggGj8uSqkW2TIBcawauh9KTtDBg4KStrW/UR heZxIbf2zf13p4hwzsNyyZQ6m4a0cVAoN53yz0i7xGFmWiW0lbayyJlIFnv1exxZoGMg gktg== 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=gQ3tMQClfO9NRhDHuTTv3sshyVDNk3yEHLSJCyjQC4o=; b=HlMjG+fmHlGUjkjZtaNmG5k27eFE5zUsQWcKZD+kovCJHEUFewvdFXdV1NSyEI4dE6 RXn0dNunFh/PO7bWL9z2Clw4hRZSA/LsAD2u8HXuuctBusJPtBVb+8B3cc8e7vQYpyFg hlEb+NmJIiQj2NL76I/hGMyzhGvE+mb/0giMJ4e4fSl7od3Lbt2dlLOEaixK4M9egygp 4FyEYayBRkfZ7qhqOZHO9F4XBt62n7yM1c2qC3ier//d7JoWZHhsJ87TztAkAjTGlDXT k52TO5ikALoIYWKniVX9u2keRXOLZdgVFZlnLRi11y15k2uymf9hPy6RcNwiMngKiPhJ yskw== X-Gm-Message-State: APjAAAViFLONgSxyQHkJ/aZ7CbBqCsA+7hv2FZzIkApCI9L44KsvF0co m0meSmep7dL7QdT+TJmD+36M3+yztt/ZbykwBQtoueWSYcP+YghCo5wzMw8uPi/Tpfe/DY6qwRi Jp3MJ1Ln94TccQsB0o65j5xkI1aZYd28W3uKHrWYKDppSlXwZpnotxi+qJjoPBZBoXneELTFQPQ == X-Google-Smtp-Source: APXvYqxy/aJXOiHVj/1V1o7CVkwP+u3j/AE8qXq+3ALN4+pAcE4DVcT4zAUZCqUw0MaWwO1hnaKRThy3M80xTHAq4lA= X-Received: by 2002:a63:66c6:: with SMTP id a189mr779748pgc.401.1581645243781; Thu, 13 Feb 2020 17:54:03 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:33 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 05/15] 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 | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 6ce2ae2eff..4dd72c60f5 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 OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index b7504fe322..b76a1dfb2a 100644 --- a/bugreport.c +++ b/bugreport.c @@ -7,10 +7,23 @@ 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 -a: "); + if (uname(&uname_info)) + strbuf_addf(sys_info, "uname() failed with code %d\n", 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 Fri Feb 14 01:53:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381511 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 27F6C1580 for ; Fri, 14 Feb 2020 01:54:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F17EE2168B for ; Fri, 14 Feb 2020 01:54:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Oq2EixUA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728332AbgBNByH (ORCPT ); Thu, 13 Feb 2020 20:54:07 -0500 Received: from mail-vk1-f202.google.com ([209.85.221.202]:50141 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728193AbgBNByH (ORCPT ); Thu, 13 Feb 2020 20:54:07 -0500 Received: by mail-vk1-f202.google.com with SMTP id v134so2719094vkd.16 for ; Thu, 13 Feb 2020 17:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=I3RloJdvp1spyqvHvZLdZ6xHw0Qu5/WY3tHVJyxBInE=; b=Oq2EixUAwpIjwuf480Nbf7A0yAMTf8mm9botAVw1KOuAupkrj4ImzaQNpCRUpqym9r V8Q5wk9MFp52h6+14tNawPaBNshiBykjNKS/WGna39wotFYsL1hF3aId/HfrweM4fS5K 1SoyA4+v9LpqDjtaVWck/GjuBFW3AUsCbgbQTNmL0MuI3Zdr9Uy3YalsDrG5FXw0KUSX TEpaq3eiuYrqbmX7/vh5k7kztmqD3IJUxwDo36nPufrYg+Jl34OWizcnqLsmrDzSEzvu U/ZR1F4uY6AnCBubgPcoxG1kP3wz29wiemzaHhlcd9UVT/jsll0OTjbn3OokDgLbgFQK Wu2A== 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=I3RloJdvp1spyqvHvZLdZ6xHw0Qu5/WY3tHVJyxBInE=; b=Dk/lvGijmPtNNi7eHKUXHijbo0f8qHSrW2Z7PFcJDxfkqfGfYBTuV+l16U6xbaHn3E 0R4q4zOCtGtmIDkkhmTLS4R4q9IDUeKONlkmbV9ThA/6CdJXTh2fBBI3zjedFwtcBYqP fGyrGW8SLytw6PNGHz1tHsxCnj6xvmuRDoMg20MTsOPMzoK9c7QaaVPbDc3IW/4rjzjf VyWstY8cloKAiCLi93eWByTEWi13eFQKgKTDVQihGvBW4MYpf+by/zwwsV6cMGw6zFKS nDeQy0U3ZE+qDcluK7vHoPukSJoZmfoDJkxdRwQxc7Gn5GeWiZQcGUMbLqB283FoX3Rx kkEw== X-Gm-Message-State: APjAAAVw/+8kToQ5gAOP/dcIF2PcdV/s5uIhAIvC7kyPQjXzy82cbkvh qED6uZt3+WfhrLV+lxDh1kkUreTDTDlLDaKfzhvH1CaZpZVVCP/hm0Y5R+hPxBuVL3ryOdUm/x+ 2D0/mQo/JxRolxDjhkADzmflzqauzxulrnYb2JRgyxJLiajMcoD7uRe1En89u/tZWUpo83nZd+A == X-Google-Smtp-Source: APXvYqxoBpAau5vC5CHLtj+OAmOBKrctD2sCGZ23WG2nlUzJV3ChFyFbhIHAZvjsRxtEwD9krOzhCvbAWXXeIW6kjnU= X-Received: by 2002:ab0:4aca:: with SMTP id t10mr425670uae.89.1581645246122; Thu, 13 Feb 2020 17:54:06 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:34 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 06/15] 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 | 5 +++++ compat/compiler.h | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 compat/compiler.h diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 4dd72c60f5..8bbc4c960c 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 OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index b76a1dfb2a..4f9101caeb 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) { @@ -24,6 +25,10 @@ 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_complete_line(sys_info); } static const char * const bugreport_usage[] = { diff --git a/compat/compiler.h b/compat/compiler.h new file mode 100644 index 0000000000..bda5098e1b --- /dev/null +++ b/compat/compiler.h @@ -0,0 +1,24 @@ +#ifndef COMPILER_H +#define COMPILER_H + +#include "git-compat-util.h" +#include "strbuf.h" + +#ifdef __GLIBC__ +#include + +static inline void get_compiler_info(struct strbuf *info) +{ + strbuf_addf(info, "glibc: %s", gnu_get_libc_version()); +} + +#else + +static inline void get_compiler_info(struct strbuf *info) +{ + strbuf_addstr(info, "get_compiler_info() not implemented"); +} + +#endif + +#endif /* COMPILER_H */ From patchwork Fri Feb 14 01:53:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381525 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 E9233921 for ; Fri, 14 Feb 2020 01:54:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8A9B2187F for ; Fri, 14 Feb 2020 01:54:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mNTaGuz7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728378AbgBNByK (ORCPT ); Thu, 13 Feb 2020 20:54:10 -0500 Received: from mail-pg1-f201.google.com ([209.85.215.201]:42813 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728336AbgBNByJ (ORCPT ); Thu, 13 Feb 2020 20:54:09 -0500 Received: by mail-pg1-f201.google.com with SMTP id 193so5030380pgh.9 for ; Thu, 13 Feb 2020 17:54:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=tWVW7MwWFQo2xFCTRDNOgc7MoIj3aVwWJ38vvZ3cQpo=; b=mNTaGuz7RQa0qf2tHXm07GbwRDf5PRgrBiFJc1FfACbzfgS+lNBoLiyhzUEsfKFoYP FBqdtbrmCyHBQIZqe/L74uG4PrxDU2CYMFH65Q348Nqto8goOiU6L2/PVH2nKAMT/wSn o05MY7IMk2nhv2/K3XHm6r4Kiwgjaz2+hyJIolDJExvQViPZzMaecruv+TLrzOzWvZad HS1l81AZ2Ew+wcDFONYVRLy5PdrcKoEBcbQYXuOYFvISmHfUARllmF2p10WVsyjyez55 A3W1cwS0O/JS1MeyX7VcP0El6mONKPsQXsjsAq7LFVTUidLYhpDPH4U5tawccriWq6Rk cOfw== 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=tWVW7MwWFQo2xFCTRDNOgc7MoIj3aVwWJ38vvZ3cQpo=; b=Jg0YbIioOKCuqI8eCDLKv2BibFzBYX30yHxGSkut6OJBMpvRuWRG51AC11jIUpNKVl uH50hF0G0ip7Fnin3csGI1P7o4cKUp2SC5/gLIStT2+wckozVK5J3/BIHtqRw2NZi8OK lYYzCFiYPRT2GcbJZ20C3Fo+6oFw+T5+eaH7cdNlCys+oazdgGmEsUYkDY22cPxl7Doi Evly2UCMgWXOfE9jWUtd7LECb+atnO8Ys9RrtX+sybPCzWmsWk3cCyqvRJBo2SdvFQQj o1aO7D7IcjskNQLih2HUhHpVhcHwUzTKwZV4rZUtezaK0X7gOyCwfHtNOhmmJCA2scQ/ PDgA== X-Gm-Message-State: APjAAAX6F1YrqRxOnLOu10wopannUgmFmDI/tnLGKS2vAJMbeH+OScCW 8HMk3kZGN1UiyPuNuWaOwwNSZ/JFrOvC8N6p85FlDWGvfizA5iwYEeP8gHnsAPfgLN8Pp/mYkWk ah5qWGmEniHcmE2kIxxOvmP5Ki2QlrVhTuVQAihmKqm2V0mwM8K2XOXu8maH/NHUvSIPT17JnfQ == X-Google-Smtp-Source: APXvYqwml4N4ucHXDXx1HQIkUbytof8Jx9dnB0iblbf4MlPBiN2YyIWbIgW6mkR2JzQ3OCPZRr+cpE+NOZfVD9VaY8M= X-Received: by 2002:a63:5512:: with SMTP id j18mr828363pgb.189.1581645248339; Thu, 13 Feb 2020 17:54:08 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:35 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 07/15] bugreport: add git-remote-https version 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 It's possible for git-remote-curl to be built separately from git; in that case we want to know what version of cURL is used by git-remote-curl, not necessarily which version was present at git-bugreport's build time. So instead, ask git-remote-curl for the version information it knows about. Today, "git-remote-http" and "git-remote-https" are aliased to "git-remote-curl"; but in case we rely on a different library than cURL in the future, let's not explicitly reference cURL from bugreport. For longevity purposes, invoke the alias "git-remote-https" instead of "git-remote-http". Since it could have been built at a different time, also report the version and built-from commit of git-remote-curl alongside the cURL info. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 16 ++++++++++++++++ remote-curl.c | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 8bbc4c960c..33df4dec7f 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -28,6 +28,7 @@ The following information is captured automatically: - 'git version --build-options' - uname sysname, release, version, and machine strings - Compiler-specific info string + - 'git remote-https --build-info' OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 4f9101caeb..bfdff33368 100644 --- a/bugreport.c +++ b/bugreport.c @@ -5,6 +5,18 @@ #include "time.h" #include "help.h" #include "compat/compiler.h" +#include "run-command.h" + +static void get_git_remote_https_version_info(struct strbuf *version_info) +{ + struct child_process cp = CHILD_PROCESS_INIT; + + argv_array_push(&cp.args, "git"); + argv_array_push(&cp.args, "remote-https"); + argv_array_push(&cp.args, "--build-info"); + if (capture_command(&cp, version_info, 0)) + strbuf_addstr(version_info, "'git-remote-https --build-info' not supported\n"); +} static void get_system_info(struct strbuf *sys_info) { @@ -29,6 +41,10 @@ static void get_system_info(struct strbuf *sys_info) strbuf_addstr(sys_info, "compiler info: "); get_compiler_info(sys_info); strbuf_complete_line(sys_info); + + strbuf_addstr(sys_info, "git-remote-https --build-info:\n"); + get_git_remote_https_version_info(sys_info); + strbuf_complete_line(sys_info); } static const char * const bugreport_usage[] = { diff --git a/remote-curl.c b/remote-curl.c index 350d92a074..c590fbfae3 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -17,6 +17,7 @@ #include "protocol.h" #include "quote.h" #include "transport.h" +#include "version.h" static struct remote *remote; /* always ends with a trailing slash */ @@ -1374,6 +1375,13 @@ int cmd_main(int argc, const char **argv) string_list_init(&options.deepen_not, 1); string_list_init(&options.push_options, 1); + if (!strcmp("--build-info", argv[1])) { + printf("git-http-fetch version: %s\n", git_version_string); + printf("built from commit: %s\n", git_built_from_commit_string); + printf("curl version: %s\n", curl_version()); + return 0; + } + /* * Just report "remote-curl" here (folding all the various aliases * ("git-remote-http", "git-remote-https", and etc.) here since they From patchwork Fri Feb 14 01:53: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: 11381519 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 75BF51580 for ; Fri, 14 Feb 2020 01:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5529A2187F for ; Fri, 14 Feb 2020 01:54:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cgbTuakU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728483AbgBNByV (ORCPT ); Thu, 13 Feb 2020 20:54:21 -0500 Received: from mail-yb1-f201.google.com ([209.85.219.201]:39922 "EHLO mail-yb1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728200AbgBNByN (ORCPT ); Thu, 13 Feb 2020 20:54:13 -0500 Received: by mail-yb1-f201.google.com with SMTP id y123so6535710yby.6 for ; Thu, 13 Feb 2020 17:54:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=/khBfeqMsFSzVsQmvZgWwvtD4WlIt5dmIasVZVck7D0=; b=cgbTuakUbyjRZBbpxC+zuIu/FzA2/xFOEJcovBRo5g0IiujieuLIfC9MqjjyqmlRjx SEJrDyDMJXUXEweVl5Q5/cWfxw2Ijq0Sb2hcqqPSCRjPFjXs9gpVo7xs7sar6BVuKQOo VOAeAyvOaHaxEFOVu4x15CqL+lmOkXQlc2Glgwv1swz5aRMFYjjwMxieUefZYEj2YqOg 40JC6gbk9zxsa5lTMggNaJBjvX063ER7QkZqPemYQbTqNBuAKJy2a4uBTVDPmyhpxa7k teb2TobzV0xV8/2UUOr2Uhm1gwIqYxIhY1FvBxmUAfawLEr1V6jyrT0SY9ieDld7r8rU 0NDQ== 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=/khBfeqMsFSzVsQmvZgWwvtD4WlIt5dmIasVZVck7D0=; b=b5WXeQR5MIi75Tn0lvD+dW2mXlxrwj6qpA+Vr2+H56r+Fbo4V1IzuTVJkZBgCTq2cJ 5iv9ujNOjgAt/ppFbyt5UExGwEz8ma/uUc2pAexqyuv2phrmJK9HhUhXEGWt7PwvD5ft HMO/09CMV+LAFam5qSPen9EXS9i4IrldTWwO9hOq9VpOx2PTA5nmEiSCumvuV6iJifUG 74nHRQWrsjj4X7yblryixI1omeQXa+HFliZ5/0USXhu/7OTBOS/QgNzp0rlRRDT/D9h9 0Rmhtl4qaMGD+xxN94NsgzTyEJ4W9/temB7qmWBLXIKh+a+D64WG5hKuhgNVpd8wG2jP M/Fg== X-Gm-Message-State: APjAAAVV8zolB0IeOjTq3/jt15UagxmMycqlNqNaTz90PW4vLz+RfApM 4MVqVZEEO3H6zHnblG25U9QNHgLSU4rc8L0mFoYf8ZKi9SBa7GlJEkuJ9JBVj/j7Ut5ACJui7UP F6m5ZI8/H4SABvxS0j2l6O/0vWrMdxwt2bPpkupJ1emuO1nqrkxL8ap0eQPtnX3oL0PltMyAnvw == X-Google-Smtp-Source: APXvYqy/77rjyC8bDjBb5rAucZn47xqZzlsSV2akABB4mGhIis7efko/csip7bjLV+/6KJU4J6TTI8qhuWd9aifVRvY= X-Received: by 2002:a25:8041:: with SMTP id a1mr608697ybn.420.1581645250665; Thu, 13 Feb 2020 17:54:10 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:36 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 08/15] bugreport: include user interactive shell 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 It's possible a user may complain about the way that Git interacts with their interactive shell, e.g. autocompletion or shell prompt. In that case, it's useful for us to know which shell they're using interactively. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 33df4dec7f..23265b0d74 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -29,6 +29,7 @@ The following information is captured automatically: - uname sysname, release, version, and machine strings - Compiler-specific info string - 'git remote-https --build-info' + - $SHELL OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index bfdff33368..c1475601bf 100644 --- a/bugreport.c +++ b/bugreport.c @@ -21,6 +21,7 @@ static void get_git_remote_https_version_info(struct strbuf *version_info) static void get_system_info(struct strbuf *sys_info) { struct utsname uname_info; + char *shell = NULL; /* get git version from native cmd */ strbuf_addstr(sys_info, "git version:\n"); @@ -42,6 +43,10 @@ static void get_system_info(struct strbuf *sys_info) get_compiler_info(sys_info); strbuf_complete_line(sys_info); + shell = getenv("SHELL"); + strbuf_addf(sys_info, "$SHELL (typically, interactive shell): %s\n", + shell ? shell : ""); + strbuf_addstr(sys_info, "git-remote-https --build-info:\n"); get_git_remote_https_version_info(sys_info); strbuf_complete_line(sys_info); From patchwork Fri Feb 14 01:53:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381513 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 88B401580 for ; Fri, 14 Feb 2020 01:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54E4A20848 for ; Fri, 14 Feb 2020 01:54:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZA3DvkRs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728337AbgBNByP (ORCPT ); Thu, 13 Feb 2020 20:54:15 -0500 Received: from mail-yb1-f202.google.com ([209.85.219.202]:46166 "EHLO mail-yb1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728454AbgBNByO (ORCPT ); Thu, 13 Feb 2020 20:54:14 -0500 Received: by mail-yb1-f202.google.com with SMTP id s13so6522575ybl.13 for ; Thu, 13 Feb 2020 17:54:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=PC9UMTKQ9nJeZfF0icJi440ZQAhg5kkV5bERIH5pEKc=; b=ZA3DvkRs2MVz9LMvSFiWXs6PjjepgSLcU+0N3IeQrBkk5b98/QAws338Pt+u0BPnI9 qMdB+jLg9nBWyB21wM3LHPDc1jnS/HfKbbxLq9znZUU9xbPnw5d2Z0DjtaJ75TjhVOYd hZEv+8JTa242ggqpPopkxrTrLaclISQ4fiy4CIXDsJEpgBXANVCOqLhkPlvRTppxPmLi qU11qPvfQjlQgsC7OPaGOy0jF4anaStapOu+SpJ4cDN+bETrVxWoquzBRI3yqzkhE/9F uMBBc1Ff/06PyhGWj3oOX6BMV/e8usGLEdWIHEP4Ek6rycoFBybYOQ2cRpAv53A+jGpv A5JQ== 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=PC9UMTKQ9nJeZfF0icJi440ZQAhg5kkV5bERIH5pEKc=; b=a9SnXDcT3IigzQlo4f7caiqpeuOoaAsYBQiw5HBeuqVRSWOUOK00cFeGftGpzlPXCO 9HOwGIPDEIvBHShsUKxxrI1G2uK8iH803lNY2SEZE2SQOeuITG9zBxcT+pLnm7Bz41nG YNZOV4CwlvjbR80vo3LzYc1Qw9IA63J1v6ZdiwZ+PqXWawn4PypMwWIExI7SG/5wMxGw sOdLo2TCpT7hJAmtphDF5C0xuwL5NbR4FjWSYJdioZMWTkCcjw1H1u6L+rRkkuDSfCjA LIaPA/0iiep1Cy+X4zTm792mAFcjytZ8F6qoUMzXGzJtRqDPvQ0RLaK3THKX46wCnroL GRhw== X-Gm-Message-State: APjAAAXXaj9/a3Q5FcyjJ85ZDP7AirrpGveIKKajOZN5TgllBJzMQ3pz Mj/D3zfYZO8i0qbZuG20UyXOUIv09lvYe4L3HNapmv5mTqspRRYBWRFnulhYRXofm44gu4NCWih 91NhgHaku1qSXhoiIqEPkZxaFzQWCLdiGssuyemjCY5+fKMObJYdehEWDDNejYpkAoewsiGfr/g == X-Google-Smtp-Source: APXvYqzq7JUSRu5B/jGvpnbkyaNWEuLtS3FArFdjseCtQ3ucSlqmkVLlb4jnwsxTVPm34llwRmoty34LAr4kX5/kJ4M= X-Received: by 2002:a81:408:: with SMTP id 8mr550400ywe.88.1581645253096; Thu, 13 Feb 2020 17:54:13 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:37 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 09/15] bugreport: generate config safelist based on docs From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , " =?utf-8?q?Martin_=C3=85gren?= " , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a new step to the build to generate a safelist of git-config variables which are appropriate to include in the output of git-bugreport. New variables can be added to the safelist by annotating their documentation in Documentation/config with the "annotate" macro, which is a no-op in AsciiDoc and AsciiDoctor. Some configs are private in nature, and can contain remote URLs, passwords, or other sensitive information. In the event that a user doesn't notice their information while reviewing a bugreport, that user may leak their credentials to other individuals, mailing lists, or bug tracking tools inadvertently. Heuristic blocklisting of configuration keys is imperfect and prone to false negatives; given the nature of the information which can be leaked, a safelist is more reliable. However, it's possible that in some situations, an organization may be less concerned with privacy of things like remote URLs and branch names, and more concerned with ease of diagnosis for their support staff. In those cases, it may make more sense for that organization to modify the code to use a blocklist. To that end, we should try to mark configs which are definitely safe, and configs which are definitely unsafe, and leave blank configs which are somewhere in between. To mark a config as safe, add "annotate:bugreport[include]" to the corresponding line in the config documentation; to mark it as unsafe, add "annotate:bugreport[exclude]" instead. Generating bugreport-config-safelist.h at build time by grepping the documentation for this new macro helps us prevent staleness. The macro itself is a no-op and should not alter the appearance of the documentation in either AsciiDoc or AsciiDoctor, confirmable by running: cd Documentation ./doc-diff --asciidoctor HEAD^ HEAD ./doc-diff --asciidoc HEAD^ HEAD Diffing the rendered HTML shows that only inline comments were added, which shouldn't be a problem. Additionally, add annotations to the sendemail config documentation in order to demonstrate a proof of concept. Helped-by: Martin Ă…gren Helped-by: Johannes Schindelin Signed-off-by: Emily Shaffer --- .gitignore | 1 + Documentation/asciidoc.conf | 9 ++++ Documentation/asciidoctor-extensions.rb | 7 ++++ Documentation/config/sendemail.txt | 56 ++++++++++++------------- Makefile | 7 ++++ generate-bugreport-config-safelist.sh | 18 ++++++++ 6 files changed, 70 insertions(+), 28 deletions(-) create mode 100755 generate-bugreport-config-safelist.sh diff --git a/.gitignore b/.gitignore index d89bf9e11e..bd2f49b996 100644 --- a/.gitignore +++ b/.gitignore @@ -192,6 +192,7 @@ /gitweb/static/gitweb.min.* /config-list.h /command-list.h +/bugreport-config-safelist.h *.tar.gz *.dsc *.deb diff --git a/Documentation/asciidoc.conf b/Documentation/asciidoc.conf index 8fc4b67081..663e06481f 100644 --- a/Documentation/asciidoc.conf +++ b/Documentation/asciidoc.conf @@ -6,9 +6,14 @@ # # Show Git link as: (
); if section is defined, else just show # the command. +# +# The annotate macro does nothing as far as rendering is +# concerned -- we just grep for it in the sources to populate +# things like the bugreport safelist. [macros] (?su)[\\]?(?Plinkgit):(?P\S*?)\[(?P.*?)\]= +(?su)[\\]?(?Pannotate):(?P\S*?)\[(?P.*?)\]= [attributes] asterisk=* @@ -28,6 +33,8 @@ ifdef::backend-docbook[] {0#} {0#{target}{0}} {0#} +[annotate-inlinemacro] +{0#} endif::backend-docbook[] ifdef::backend-docbook[] @@ -94,4 +101,6 @@ ifdef::backend-xhtml11[] git-relative-html-prefix= [linkgit-inlinemacro] {target}{0?({0})} +[annotate-inlinemacro] + endif::backend-xhtml11[] diff --git a/Documentation/asciidoctor-extensions.rb b/Documentation/asciidoctor-extensions.rb index d906a00803..03c80af0e5 100644 --- a/Documentation/asciidoctor-extensions.rb +++ b/Documentation/asciidoctor-extensions.rb @@ -39,10 +39,17 @@ module Git output end end + + class AnnotateProcessor < Asciidoctor::Extensions::InlineMacroProcessor + def process(parent, target, attrs) + "" + end + end end end Asciidoctor::Extensions.register do inline_macro Git::Documentation::LinkGitProcessor, :linkgit postprocessor Git::Documentation::DocumentPostProcessor + inline_macro Git::Documentation::AnnotateProcessor, :annotate end diff --git a/Documentation/config/sendemail.txt b/Documentation/config/sendemail.txt index 0006faf800..fe27473e44 100644 --- a/Documentation/config/sendemail.txt +++ b/Documentation/config/sendemail.txt @@ -4,7 +4,7 @@ sendemail.identity:: values in the 'sendemail' section. The default identity is the value of `sendemail.identity`. -sendemail.smtpEncryption:: +sendemail.smtpEncryption annotate:bugreport[include] :: See linkgit:git-send-email[1] for description. Note that this setting is not subject to the 'identity' mechanism. @@ -15,7 +15,7 @@ sendemail.smtpsslcertpath:: Path to ca-certificates (either a directory or a single file). Set it to an empty string to disable certificate verification. -sendemail..*:: +sendemail..* annotate:bugreport[exclude] :: Identity-specific versions of the 'sendemail.*' parameters found below, taking precedence over those when this identity is selected, through either the command-line or @@ -23,41 +23,41 @@ sendemail..*:: sendemail.aliasesFile:: sendemail.aliasFileType:: -sendemail.annotate:: -sendemail.bcc:: -sendemail.cc:: -sendemail.ccCmd:: -sendemail.chainReplyTo:: -sendemail.confirm:: -sendemail.envelopeSender:: -sendemail.from:: -sendemail.multiEdit:: -sendemail.signedoffbycc:: -sendemail.smtpPass:: -sendemail.suppresscc:: -sendemail.suppressFrom:: -sendemail.to:: -sendemail.tocmd:: -sendemail.smtpDomain:: -sendemail.smtpServer:: -sendemail.smtpServerPort:: -sendemail.smtpServerOption:: -sendemail.smtpUser:: -sendemail.thread:: -sendemail.transferEncoding:: -sendemail.validate:: -sendemail.xmailer:: +sendemail.annotate annotate:bugreport[include] :: +sendemail.bcc annotate:bugreport[include] :: +sendemail.cc annotate:bugreport[include] :: +sendemail.ccCmd annotate:bugreport[include] :: +sendemail.chainReplyTo annotate:bugreport[include] :: +sendemail.confirm annotate:bugreport[include] :: +sendemail.envelopeSender annotate:bugreport[include] :: +sendemail.from annotate:bugreport[include] :: +sendemail.multiEdit annotate:bugreport[include] :: +sendemail.signedoffbycc annotate:bugreport[include] :: +sendemail.smtpPass annotate:bugreport[exclude] :: +sendemail.suppresscc annotate:bugreport[include] :: +sendemail.suppressFrom annotate:bugreport[include] :: +sendemail.to annotate:bugreport[include] :: +sendemail.tocmd annotate:bugreport[include] :: +sendemail.smtpDomain annotate:bugreport[include] :: +sendemail.smtpServer annotate:bugreport[include] :: +sendemail.smtpServerPort annotate:bugreport[include] :: +sendemail.smtpServerOption annotate:bugreport[include] :: +sendemail.smtpUser annotate:bugreport[exclude] :: +sendemail.thread annotate:bugreport[include] :: +sendemail.transferEncoding annotate:bugreport[include] :: +sendemail.validate annotate:bugreport[include] :: +sendemail.xmailer annotate:bugreport[include] :: See linkgit:git-send-email[1] for description. sendemail.signedoffcc (deprecated):: Deprecated alias for `sendemail.signedoffbycc`. -sendemail.smtpBatchSize:: +sendemail.smtpBatchSize annotate:bugreport[include] :: Number of messages to be sent per connection, after that a relogin will happen. If the value is 0 or undefined, send all messages in one connection. See also the `--batch-size` option of linkgit:git-send-email[1]. -sendemail.smtpReloginDelay:: +sendemail.smtpReloginDelay annotate:bugreport[include] :: Seconds wait before reconnecting to smtp server. See also the `--relogin-delay` option of linkgit:git-send-email[1]. diff --git a/Makefile b/Makefile index a01a050aa3..2bc9f112ea 100644 --- a/Makefile +++ b/Makefile @@ -817,6 +817,7 @@ VCSSVN_LIB = vcs-svn/lib.a GENERATED_H += config-list.h GENERATED_H += command-list.h +GENERATED_H += bugreport-config-safelist.h LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ $(FIND) . \ @@ -2163,6 +2164,12 @@ command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Doc $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ command-list.txt >$@+ && mv $@+ $@ +bugreport-config-safelist.h: generate-bugreport-config-safelist.sh + +bugreport-config-safelist.h: Documentation/config/*.txt + $(QUIET_GEN)$(SHELL_PATH) ./generate-bugreport-config-safelist.sh \ + >$@+ && mv $@+ $@ + SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\ $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\ diff --git a/generate-bugreport-config-safelist.sh b/generate-bugreport-config-safelist.sh new file mode 100755 index 0000000000..2794a8ae77 --- /dev/null +++ b/generate-bugreport-config-safelist.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +cat < X-Patchwork-Id: 11381515 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 7BF661580 for ; Fri, 14 Feb 2020 01:54:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5AE4120848 for ; Fri, 14 Feb 2020 01:54:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vpwKV54t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728469AbgBNByS (ORCPT ); Thu, 13 Feb 2020 20:54:18 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:36302 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728454AbgBNByQ (ORCPT ); Thu, 13 Feb 2020 20:54:16 -0500 Received: by mail-qk1-f201.google.com with SMTP id r142so5102228qke.3 for ; Thu, 13 Feb 2020 17:54:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NmUjZIAliovE6D2f3OLHzof6gg4XCMhi7ZLvLLnkEdA=; b=vpwKV54tUoCF5YUSRXSDCYZuob97KgsDSgoFSUHWWxdrPTuXGZ4iO48dKsJWBOL3Vh 5jQhpG+tOUREO/or4FYLKGakdK5QV3yvrIfpDSzNEtr+8A4PF99Oai9TygC2RROcVR9s w4WxDpgEa94B/FWioMY4WI+yLUzxhKl4RXeJ4lQV3xLQzLtfzNyBLlJC/jkKk4aTTyQF SaWC6m0NY9VyznTU1b46u7sUbfwJefeV3KJOisxdvo+5N7ZAbwZ0DPEqWltQeFXUlLrt L7uPjs5oN+cTreaPXc6NMQQN0aUFtbT9Dcxv4gdo7kyOzjUyL547bYbv55aXKFik3BHi FZzg== 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=NmUjZIAliovE6D2f3OLHzof6gg4XCMhi7ZLvLLnkEdA=; b=TCyouUZvbvdPcTOEOOUkZ4OVKaZ1NEGDQo/cTez61tBSP9R+KHbHeAHvNpm1oN4kGw UFrk4QSvcD89s/aLHo0cUaPmcairtIgY7QVbyi6+I0EvtUBxOBW7TifjUyEdsLOqEPD0 AkamHQYe4ix92ZQyDsXR8RQ8gOkCNCbnTpUJYBzCicfa4Y1cQxokFgRt+YHQVXbgBK9T eBJrdQ3yfS+bOX5PDb+TYpgCdtIvvj4oT28AU91Y3rwJZkZO0nqulVNFF1FH9XQ7nEFO 8r9AgA+mq00K5F4vtocsdlJJb2rUatqIuQ5PeMWt/OySr3k6q/pFHxQOJKj8CzXI490p LDvg== X-Gm-Message-State: APjAAAUQmKJ9ixXmIkTkgePTbgZb/VNHUnE9CbpdpIOM+3rHMlwEvIfw h185WqMz4grgkYCIs3JNHrdfD6pUjCFumFRQyBT6unrXhXqavq0pfF5t++GJX++B85ANqcelf+c waRucB+qHgK8tJM940rh7clJFcoLBG4BzOrXL1+PYgoB0eTsw+1TJb04QJ7d3yb9sdZllbT7I0w == X-Google-Smtp-Source: APXvYqyTJXJbOE6PVyLJh2reiHxSk3utqLaqeqEgMbKyE8uclePkDmlfrB/maBaaWWp/RnlvYUoGjJBy1G7c0VYqMyI= X-Received: by 2002:a05:620a:2119:: with SMTP id l25mr463148qkl.248.1581645255611; Thu, 13 Feb 2020 17:54:15 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:38 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-11-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 10/15] bugreport: add config values from safelist 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 bugreport to gather the values of config options which are present in 'bugreport-config-safelist.h', and show their origin scope. Many config options are sensitive, and many Git add-ons use config options which git-core does not know about; it is better only to gather config options which we know to be safe, rather than excluding options which we know to be unsafe. Rather than including the path to someone's config, which can reveal filesystem layout and project names, just name the scope (e.g. system, global, local) of the config source. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + Makefile | 2 ++ bugreport.c | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 23265b0d74..4e9171d1bd 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -30,6 +30,7 @@ The following information is captured automatically: - Compiler-specific info string - 'git remote-https --build-info' - $SHELL + - Selected config values OPTIONS ------- diff --git a/Makefile b/Makefile index 2bc9f112ea..7b139230ae 100644 --- a/Makefile +++ b/Makefile @@ -2131,6 +2131,8 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h +bugreport.sp bugreport.s bugreport.o: bugreport-config-safelist.h + 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)"' \ diff --git a/bugreport.c b/bugreport.c index c1475601bf..1a9430a857 100644 --- a/bugreport.c +++ b/bugreport.c @@ -6,6 +6,9 @@ #include "help.h" #include "compat/compiler.h" #include "run-command.h" +#include "config.h" +#include "bugreport-config-safelist.h" +#include "khash.h" static void get_git_remote_https_version_info(struct strbuf *version_info) { @@ -52,6 +55,29 @@ static void get_system_info(struct strbuf *sys_info) strbuf_complete_line(sys_info); } +static void get_safelisted_config(struct strbuf *config_info) +{ + size_t idx; + struct string_list_item *it = NULL; + struct key_value_info *kv_info = NULL; + + for (idx = 0; idx < ARRAY_SIZE(bugreport_config_safelist); idx++) { + const struct string_list *list = + git_config_get_value_multi(bugreport_config_safelist[idx]); + + if (!list) + continue; + + strbuf_addf(config_info, "%s:\n", bugreport_config_safelist[idx]); + for_each_string_list_item(it, list) { + kv_info = it->util; + strbuf_addf(config_info, " %s (%s)\n", it->string, + kv_info ? config_scope_name(kv_info->scope) + : "source unknown"); + } + } +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), NULL @@ -94,6 +120,7 @@ int cmd_main(int argc, const char **argv) char *option_output = NULL; char *option_suffix = "%F-%H%M"; struct stat statbuf; + int nongit_ok = 0; const struct option bugreport_options[] = { OPT_STRING('o', "output-directory", &option_output, N_("path"), @@ -102,6 +129,10 @@ int cmd_main(int argc, const char **argv) N_("specify a strftime format suffix for the filename")), OPT_END() }; + + /* Prerequisite for hooks and config checks */ + setup_git_directory_gently(&nongit_ok); + argc = parse_options(argc, argv, "", bugreport_options, bugreport_usage, 0); @@ -132,6 +163,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "System Info"); get_system_info(&buffer); + get_header(&buffer, "Safelisted Config Info"); + get_safelisted_config(&buffer); + report = fopen_for_writing(report_path.buf); if (report == NULL) { From patchwork Fri Feb 14 01:53: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: 11381517 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 96293921 for ; Fri, 14 Feb 2020 01:54:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75BB52187F for ; Fri, 14 Feb 2020 01:54:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nsbrRUsG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728479AbgBNByT (ORCPT ); Thu, 13 Feb 2020 20:54:19 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:33630 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728467AbgBNByS (ORCPT ); Thu, 13 Feb 2020 20:54:18 -0500 Received: by mail-pf1-f202.google.com with SMTP id c72so4974972pfc.0 for ; Thu, 13 Feb 2020 17:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KtQc2NqQlhwB5rQ3CSYNZW6h8xao3iiZQNiOwbO0syc=; b=nsbrRUsGf9cYXjUqBd7VTIBPv214mWQNRdQoLea8UNcmMGu67GqVzST7WXlP3WcriK avFdRxJPDJ1DPcLQBt3SF+t2Qqt9/sXqM0wF7eCUjrX3vCwjiDZ7aa/mVO1sZwVIVJ1M mf2OliT/1vlRkFoWzhCtCyD1N9eOiwVReOP3CTumLJYp//KuBZrXEqW0tCIVC1Zfakr3 FeAv97C2Okvu/FWiqLDk+BFSYFdQiCafcZta5X1vw4h+HhUbxu8sldB/PP6pcu2PsRfF QgZGh6db2jB8ulVooIzgq4JuLgPB4go7K6I4zSySB01Pkb2oK6Vi/W80tnYL5a0rZaUM Uc/Q== 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=KtQc2NqQlhwB5rQ3CSYNZW6h8xao3iiZQNiOwbO0syc=; b=ap0zcwQDMdgrV9bPfMnnB/h8TFedwmdRECg+VIA8IfE64TTfTMO04yjG6UAawRIuTS foDUDldztk1Y6Bq59joENaokFgzDzMn/HdxC9xyojzcON66BQMA4SpBY+wqFYPy61M5y P8MDW3cP8OxVHcI9Y+jJdR0LclxgY4dgSBMXnOruDFRBdW3frxk16LLo365zfsWiR4QM mWXPd0LypO5Opgqb/Xhv/2iPUL0NYGE1gR4gqOsFWRZQB2ANPuby67em5/GgvFEkKFG/ bm1tahHlxwbJ4o5c0Drf4nwrCZL6TIxikY43sO98VBWWFLg0eYRHQPk7spYS64ZUthQQ 3GHw== X-Gm-Message-State: APjAAAU4HedRNja1wcYmViTlc2XnS8mxLOReyWuE9EVIpynsQz42qdKa OyziRRreYyrzIOtKsDLRNq8uZqub6i/06N8yXAFvtUA063bCUrg51SGagbDDNODk15yRK/kXoVX wn5XOp68YYJT4A+hllKzcg1wyWaoVv0R1K2iamJDl92/LWR28mgeR+OlnXiIREZmgg8PAMJXvdw == X-Google-Smtp-Source: APXvYqwAFPoWMDEN6eo8zFJCCE8yNrNiX7MT6aT1HbyR2fyuCC31aR8L6tA9N6ErFkWY1cHbBJenjF8CHwTuMLemA6A= X-Received: by 2002:a63:cb11:: with SMTP id p17mr935226pgg.42.1581645257911; Thu, 13 Feb 2020 17:54:17 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:39 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-12-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 11/15] bugreport: collect list of populated hooks 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 Occasionally a failure a user is seeing may be related to a specific hook which is being run, perhaps without the user realizing. While the contents of hooks can be sensitive - containing user data or process information specific to the user's organization - simply knowing that a hook is being run at a certain stage can help us to understand whether something is going wrong. Without a definitive list of hook names within the code, we compile our own list from the documentation. This is likely prone to bitrot. To reduce the amount of code humans need to read, we turn the list into a string_list and iterate over it (as we are calling the same find_hook operation on each string). However, since bugreport should primarily be called by the user, the performance loss from massaging the string seems acceptable. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 4e9171d1bd..779c9c7fd9 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -31,6 +31,7 @@ The following information is captured automatically: - 'git remote-https --build-info' - $SHELL - Selected config values + - A list of enabled hooks OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 1a9430a857..7e6147a935 100644 --- a/bugreport.c +++ b/bugreport.c @@ -9,6 +9,7 @@ #include "config.h" #include "bugreport-config-safelist.h" #include "khash.h" +#include "run-command.h" static void get_git_remote_https_version_info(struct strbuf *version_info) { @@ -78,6 +79,55 @@ static void get_safelisted_config(struct strbuf *config_info) } } +static void get_populated_hooks(struct strbuf *hook_info, int nongit) +{ + /* + * Doesn't look like there is a list of all possible hooks; so below is + * a transcription of `git help hooks`. + */ + const char *hooks = "applypatch-msg," + "pre-applypatch," + "post-applypatch," + "pre-commit," + "pre-merge-commit," + "prepare-commit-msg," + "commit-msg," + "post-commit," + "pre-rebase," + "post-checkout," + "post-merge," + "pre-push," + "pre-receive," + "update," + "post-receive," + "post-update," + "push-to-checkout," + "pre-auto-gc," + "post-rewrite," + "sendemail-validate," + "fsmonitor-watchman," + "p4-pre-submit," + "post-index-changex"; + struct string_list hooks_list = STRING_LIST_INIT_DUP; + struct string_list_item *iter = NULL; + + + if (nongit) { + strbuf_addstr(hook_info, + "not run from a git repository - no hooks to show\n"); + return; + } + + string_list_split(&hooks_list, hooks, ',', -1); + + for_each_string_list_item(iter, &hooks_list) { + if (find_hook(iter->string)) { + strbuf_addstr(hook_info, iter->string); + strbuf_complete_line(hook_info); + } + } +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), NULL @@ -166,6 +216,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Safelisted Config Info"); get_safelisted_config(&buffer); + get_header(&buffer, "Enabled Hooks"); + get_populated_hooks(&buffer, nongit_ok); + report = fopen_for_writing(report_path.buf); if (report == NULL) { From patchwork Fri Feb 14 01:53: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: 11381521 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 DB51E1580 for ; Fri, 14 Feb 2020 01:54:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B984F20848 for ; Fri, 14 Feb 2020 01:54:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sVgDfXH9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728488AbgBNByW (ORCPT ); Thu, 13 Feb 2020 20:54:22 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:51980 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728200AbgBNByW (ORCPT ); Thu, 13 Feb 2020 20:54:22 -0500 Received: by mail-pg1-f202.google.com with SMTP id m18so5028788pgn.18 for ; Thu, 13 Feb 2020 17:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=vp2GGgOSFO7of4FYxfU0AD8iRUDIAoiHfZJeEqu5n48=; b=sVgDfXH9n1v1cl2YTxHGEfoibToTyPOiGz95+YKM+53mZJzoSW5H4MibxDY+PJop9v 2/5hVd3zhJEZIvza3OMNLCLsjxBXcgO4w3SL0UozRnS8eD0DuzDqJR0vHkuDTT8fpEFd l4gpbDY21GHJ6HSYUt7wg5Mgz86XoxhW1drf9ARD9HyiLpjGCoJCz4iCjbQdWmL0UdrD ZBp0Imh3KKYcn5KY0tVJlqSy4jI0ElINpdVlvkR7QA2XQfQsddVD13Gr96jVPYDgl38R iGc5QhrHlzJ92CVtffKZpzywqTzDTf/P/8Qsie2Pr4hz8MhGH0erynVcCpAzZe2rhuCA PvAQ== 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=vp2GGgOSFO7of4FYxfU0AD8iRUDIAoiHfZJeEqu5n48=; b=bn1iV1BVGlNnqLTqMrRtTxmYVgPtPLW8P7Mp3XFUfkazDpK0f7HACSAhMuUM/tFS5T yk+siQwHCBdwogJ4xDoIq5cBUYk1E/vY5NqNxKt8m8aT0DoEIDEilxnexB4wZg7Mstma 38aIyG5C5lfqcHzG0NkxAQwrFj1T902jEJWzhE7TjlBo3q7eDlw/iLYGFD+umgugOy23 3/hZmxZiBo7s9S35y4NyxsjgP3XsyzPtEYO7MKGyspJfUb2O26vUmAM3VKSEAZyxpO2N 7wv99uT+0Ofh9FbDCijDwA1fQI0i4CvW9QeYJMPXWal5D0xgh3SikcsLEj34uQro3Bb4 u0hQ== X-Gm-Message-State: APjAAAWFeN9F16pxLT/1JQkghEN7tePsY8L48AfxxnElDq+sEw/h5gLk 7bM660j8rIC6bopRhNLD6+GHcObS20ttClx2G1idYqXfTH9niTp16C8XKgmbG3Al7wLc1Cas4J3 LLdBIGxpXsk0oL2j2VmZlFR4ZXauTvL4njwM88KXkpUt3Quy5hUc0oVbmuNBo8etwpfxm2Hz2wg == X-Google-Smtp-Source: APXvYqyNHRG/QHELDJ59IzlEe61gwWXSm+VN/azb01nOhqxRF1xJPTa7UC8a0d4/l/DAcJ/oDUy7drIUWhNli9sopQU= X-Received: by 2002:a63:504f:: with SMTP id q15mr922418pgl.8.1581645260119; Thu, 13 Feb 2020 17:54:20 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:40 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-13-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 12/15] bugreport: count loose objects From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The number of unpacked objects in a user's repository may help us understand the root of the problem they're seeing, especially if a command is running unusually slowly. Helped-by: Johannes Schindelin Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 779c9c7fd9..7e1ed44cb4 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -32,6 +32,7 @@ The following information is captured automatically: - $SHELL - Selected config values - A list of enabled hooks + - The number of loose objects in the repository OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 7e6147a935..f5201ce416 100644 --- a/bugreport.c +++ b/bugreport.c @@ -10,6 +10,7 @@ #include "bugreport-config-safelist.h" #include "khash.h" #include "run-command.h" +#include "object-store.h" static void get_git_remote_https_version_info(struct strbuf *version_info) { @@ -128,6 +129,54 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) } } +static int loose_object_cb(const struct object_id *oid, const char *path, + void *data) { + int *loose_object_count = data; + + if (loose_object_count) { + (*loose_object_count)++; + return 0; + } + + return 1; +} + +static void get_loose_object_summary(struct strbuf *obj_info, int nongit) { + + int local_loose_object_count = 0, total_loose_object_count = 0; + int local_count_questionable = 0, total_count_questionable = 0; + + if (nongit) { + strbuf_addstr(obj_info, + "not run from a git repository - no objects to show\n"); + return; + } + + local_count_questionable = for_each_loose_object( + loose_object_cb, + &local_loose_object_count, + FOR_EACH_OBJECT_LOCAL_ONLY); + + total_count_questionable = for_each_loose_object( + loose_object_cb, + &total_loose_object_count, + 0); + + strbuf_addf(obj_info, "%d local loose objects%s\n", + local_loose_object_count, + local_count_questionable ? " (problem during count)" : ""); + + strbuf_addf(obj_info, "%d alternate loose objects%s\n", + total_loose_object_count - local_loose_object_count, + (local_count_questionable || total_count_questionable) + ? " (problem during count)" + : ""); + + strbuf_addf(obj_info, "%d total loose objects%s\n", + total_loose_object_count, + total_count_questionable ? " (problem during count)" : ""); +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), NULL @@ -219,6 +268,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Enabled Hooks"); get_populated_hooks(&buffer, nongit_ok); + get_header(&buffer, "Loose Object Counts"); + get_loose_object_summary(&buffer, nongit_ok); + report = fopen_for_writing(report_path.buf); if (report == NULL) { From patchwork Fri Feb 14 01:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381523 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 B19BE921 for ; Fri, 14 Feb 2020 01:54:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 909A62187F for ; Fri, 14 Feb 2020 01:54:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cxZ1nj3R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728513AbgBNByX (ORCPT ); Thu, 13 Feb 2020 20:54:23 -0500 Received: from mail-pf1-f201.google.com ([209.85.210.201]:49931 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728200AbgBNByX (ORCPT ); Thu, 13 Feb 2020 20:54:23 -0500 Received: by mail-pf1-f201.google.com with SMTP id c9so4955326pfo.16 for ; Thu, 13 Feb 2020 17:54:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=tAqmBpvv3JJsurmFduHZ0tAvK1YA3xnaG1czNXAmRro=; b=cxZ1nj3RKUBIwf7uoiJXwtwv7wAt/NVdPO58Pvmk8ca4/DeHE34DQP7X8bWja48X48 OInPCQMx6ldvGdbWvSeBhlWoav9zpADbxCuRROUllxX5ycpdrOiTe3VM/LlXyu5KvBHL yFMXM34CtDLGSTNisgN7fn5Er9ibwOTVt++DbgKCKONz66ScIfy/qeUS6VG///hrksJg 8Bnxepy689gauF8HP0J/c40f1bIHbANtCjF6qp7VGqYRI1s+UH6iU9pWDq1gU/Yl0ake YKPK4VJmt/ygLmS9rkdBRzyRayJbqP1KTEWd76NggnYFd3y4t+cPahyh8RlimYqNdbRF b9dg== 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=tAqmBpvv3JJsurmFduHZ0tAvK1YA3xnaG1czNXAmRro=; b=NaDrDdewNacgG7Tgv9q9WvkO7rKRIyFgP3vADZjDQKXcg3zQd42O0WyQNuBvJrrMXI +v5IanwrK1yMG2UupatGKNqApmQUxFZeG1Bno4efqAv8nUU0RADfPUaLbJJ8UWO9wcrC amR9L6mlQaXQL43dgFMK/QXN30ZDnYWlfvAItybGH9YVGJ+SgS8ffo7N4CkX4lnklKrT /GLQ6U+0MOjNmdIwX5QMwYSTJ6C2l16kWWnVWFKuiV+gHH4DNLgdz+lmSoJ+d1tjg0YN B+F0WEndNgxQp1A40MV5nT6QBdctIrVOqCk8yuOPqsRHqPApDioDt8ftkTYOktgUqPE1 K1fw== X-Gm-Message-State: APjAAAUW7uQqNlDmpeXBwjbbU8tV17UpfSs3Art4DKPpqAOJtnkk8jbN Wfdly6zYEu3K8HztlJFSNVwmqsGHfbf4go3w39wRZTNKJ62kn6QayGZrpKPrUukbCK0ardFfeeD FWeMC96MY1FoT3pjtMcQ7maymsUrtTOUw8eV3Gd1EqkVZswMWsrJYSmFk3dn5MUNmMVkzWzfvTg == X-Google-Smtp-Source: APXvYqyEeMWXejox2wnDXofZa0EoOwcnVAGPWBp1JJ/YVdTy/hQ7KHJFpN5Z8JXUkei4oVzsRgPbRkw0a7EG0wmEyJ8= X-Received: by 2002:a63:360a:: with SMTP id d10mr871281pga.366.1581645262612; Thu, 13 Feb 2020 17:54:22 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:41 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-14-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 13/15] bugreport: add packed object summary 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 Alongside the loose object counts, it can be useful to show the number of packs and packed objects. This way we can check whether the repo has an appropriate ratio of packed to loose objects to help determine whether it's behaving correctly. Add a utility to easily traverse all packfiles in a given repository. Use it in packfile.c and remove a redundant call to prepare_packed_git(), which is already called in get_all_packs(). Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 30 ++++++++++++++++++++++++++++++ object-store.h | 6 ++++++ packfile.c | 3 +-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 7e1ed44cb4..309b34fc42 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -33,6 +33,7 @@ The following information is captured automatically: - Selected config values - A list of enabled hooks - The number of loose objects in the repository + - The number of packs and packed objects in the repository OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index f5201ce416..580de13ddc 100644 --- a/bugreport.c +++ b/bugreport.c @@ -177,6 +177,33 @@ static void get_loose_object_summary(struct strbuf *obj_info, int nongit) { total_count_questionable ? " (problem during count)" : ""); } +static void get_packed_object_summary(struct strbuf *obj_info, int nongit) +{ + struct packed_git *pack = NULL; + int pack_count = 0; + int object_count = 0; + + if (nongit) { + strbuf_addstr(obj_info, + "not run from a git repository - no objects to show\n"); + return; + } + + for_each_pack(the_repository, pack) { + pack_count++; + /* + * To accurately count how many objects are packed, look inside + * the packfile's index. + */ + open_pack_index(pack); + object_count += pack->num_objects; + } + + strbuf_addf(obj_info, "%d total packs (%d objects)\n", pack_count, + object_count); + +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), NULL @@ -271,6 +298,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Loose Object Counts"); get_loose_object_summary(&buffer, nongit_ok); + get_header(&buffer, "Packed Object Summary"); + get_packed_object_summary(&buffer, nongit_ok); + report = fopen_for_writing(report_path.buf); if (report == NULL) { diff --git a/object-store.h b/object-store.h index 55ee639350..518c73469d 100644 --- a/object-store.h +++ b/object-store.h @@ -6,6 +6,7 @@ #include "list.h" #include "sha1-array.h" #include "strbuf.h" +#include "packfile.h" struct object_directory { struct object_directory *next; @@ -403,4 +404,9 @@ int for_each_object_in_pack(struct packed_git *p, int for_each_packed_object(each_packed_object_fn, void *, enum for_each_object_flags flags); +#define for_each_pack(repo, pack) \ + for (pack = get_all_packs(repo);\ + pack; \ + pack = pack->next) + #endif /* OBJECT_STORE_H */ diff --git a/packfile.c b/packfile.c index 7e7c04e4d8..6873827fb5 100644 --- a/packfile.c +++ b/packfile.c @@ -2061,8 +2061,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, int r = 0; int pack_errors = 0; - prepare_packed_git(the_repository); - for (p = get_all_packs(the_repository); p; p = p->next) { + for_each_pack(the_repository, p) { if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) continue; if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) && From patchwork Fri Feb 14 01:53:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381527 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 7A9291580 for ; Fri, 14 Feb 2020 01:54:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 586A120848 for ; Fri, 14 Feb 2020 01:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dHUw6zsm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728522AbgBNBy0 (ORCPT ); Thu, 13 Feb 2020 20:54:26 -0500 Received: from mail-yb1-f201.google.com ([209.85.219.201]:44146 "EHLO mail-yb1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728200AbgBNBy0 (ORCPT ); Thu, 13 Feb 2020 20:54:26 -0500 Received: by mail-yb1-f201.google.com with SMTP id n13so6538209ybd.11 for ; Thu, 13 Feb 2020 17:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DTdoVnwl3Doo1Jag89MvQKMjslSAxopi0LZVHXddsrc=; b=dHUw6zsmCUttx3cdKq51lZEwwEG+hd5Zc16lIMLYp2E++yBqSc48kLDvcYH33ClTu8 YVbEEFVj3Q7dLjsRt8zTR5O81275pKaJ24h9wAajM4k8FNNKmqDoPAtfxcBHeyYbgtVk 4UBt+A03kJtlvhY8vHDR+t0BZThSQ/VlQywYC+O6lu9wM1jaTetatkLv0zh2IvlUyWXZ QR6eLC5rDkscNA1Ts6RFzpqOR8wC+e3r0M9/Flvfnh9FIyWZMkI5QPXxZHC21I1qLfVg C8bX1uxFvcTmMMcMeItOQBQ5D8KqkoJoTPqYijAbgwFDci1GHXoihm4K7awVVzTH1raT 3PVQ== 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=DTdoVnwl3Doo1Jag89MvQKMjslSAxopi0LZVHXddsrc=; b=Unx0uIf8uQAo5+ETywYnpEk77+D80MVft0GtjGBbO9yATKj41ZCv/0kmZLL321GMce vD83L993YFJhEup7Umau9SjfLgEhMI/nwywnIrGEqSZfvh+zq3wgKzCnf/8s7OBe9oxJ yVG2yKTC3mmPQaESYPatA69D1FS/3b2VEoLN5XKeLqD44dSpqn+FOwLtNgah+xxeShuH Rt/WMxpVvZFtgPOdeRX2k3CmnqIoNL0YjyFa1bu5jVXwkr7eHYYkOoim4V8qRrrNaJxn 0vaLZf0mk7ezOXZ1swZacqJnFgKw9VnxSr9R1oOa0r3vEw9v28PM067TMe7GSJNFNg0N u/MQ== X-Gm-Message-State: APjAAAXDs3udBtqorjkZeq3uWTnLGuue/qM+sZzGlwOt2KfyOTq/+oAW 5mtwedJBlyVOQ8nj4YO+0zjNWDgZz/PtXNRF2bG5Rm8LvxW0SEuKb+UPwmKgfV8cr6M8CrtRgjk nsl6e3fQLqDjqJvWoroNuIUqUFzU6Gk6SU71RC5Lhtj+JBVNp6mhdFMEKzuSD9F19xpoj7QFDqQ == X-Google-Smtp-Source: APXvYqyarlwOS6nSfLwsjMv+jNiAOMiNf3UU9XGtCjeptMS64Gz6n2l1USf2PpyAklug3Q35vjKA3T6jBwQvpfENJ1I= X-Received: by 2002:a0d:f245:: with SMTP id b66mr567233ywf.102.1581645265022; Thu, 13 Feb 2020 17:54:25 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:42 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-15-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 14/15] bugreport: list contents of $OBJDIR/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 Miscellaneous information used about the object store can end up in .git/objects/info; this can help us understand what may be going on with the object store when the user is reporting a bug. Otherwise, it could be difficult to track down what is going wrong with an object which isn't kept locally to .git/objects/ or .git/objects/pack. Having some understanding of where the user's objects may be kept can save us some hops during the bug reporting process. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 309b34fc42..a21d081616 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -34,6 +34,7 @@ The following information is captured automatically: - A list of enabled hooks - The number of loose objects in the repository - The number of packs and packed objects in the repository + - A list of the contents of .git/objects/info (or equivalent) OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 580de13ddc..1c67b55598 100644 --- a/bugreport.c +++ b/bugreport.c @@ -204,6 +204,57 @@ static void get_packed_object_summary(struct strbuf *obj_info, int nongit) } +static void list_contents_of_dir_recursively(struct strbuf *contents, + struct strbuf *dirpath) +{ + struct dirent *d; + DIR *dir; + size_t path_len; + + dir = opendir(dirpath->buf); + if (!dir) + return; + + strbuf_complete(dirpath, '/'); + path_len = dirpath->len; + + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + + strbuf_addbuf(contents, dirpath); + strbuf_addstr(contents, d->d_name); + strbuf_complete_line(contents); + + if (d->d_type == DT_DIR) { + strbuf_addstr(dirpath, d->d_name); + list_contents_of_dir_recursively(contents, dirpath); + } + strbuf_setlen(dirpath, path_len); + } + + closedir(dir); +} + +static void get_object_info_summary(struct strbuf *obj_info, int nongit) +{ + struct strbuf dirpath = STRBUF_INIT; + + if (nongit) { + strbuf_addstr(obj_info, + "not run from a git repository - object info unavailable\n"); + return; + } + + strbuf_addstr(&dirpath, get_object_directory()); + strbuf_complete(&dirpath, '/'); + strbuf_addstr(&dirpath, "info/"); + + list_contents_of_dir_recursively(obj_info, &dirpath); + + strbuf_release(&dirpath); +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), NULL @@ -301,6 +352,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Packed Object Summary"); get_packed_object_summary(&buffer, nongit_ok); + get_header(&buffer, "Object Info Summary"); + get_object_info_summary(&buffer, nongit_ok); + report = fopen_for_writing(report_path.buf); if (report == NULL) { From patchwork Fri Feb 14 01:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11381529 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 DDDF31580 for ; Fri, 14 Feb 2020 01:54:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBD5C20848 for ; Fri, 14 Feb 2020 01:54:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DZB+WRJo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728523AbgBNBy2 (ORCPT ); Thu, 13 Feb 2020 20:54:28 -0500 Received: from mail-pg1-f201.google.com ([209.85.215.201]:46706 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728052AbgBNBy2 (ORCPT ); Thu, 13 Feb 2020 20:54:28 -0500 Received: by mail-pg1-f201.google.com with SMTP id f5so5025778pgn.13 for ; Thu, 13 Feb 2020 17:54:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Euv/yjuzPZRAiWkQXN0/3dsS8sVF8EZnzt+OM2Lwltw=; b=DZB+WRJouJXKMnRljreTGuosbB7ew8kmEGT6s84sexEW9+44WArvSW9t4ILOPd4R54 8leOdULj85nUCEB9k0aG1VgxjmHajouO02+9u8F+vSmYmB5ZR0AqfjpMywqElUjtuMH5 5J10kT/WYEcsOWCWkiYmh1k/8YBr/YLI29uZLQg/kCWy+RBYZ+WEkDvlN1CAST3HeVZI p/y+Mj1JYfiYH2AutsKE3hx0H/Ton4m4soEEPfmihA0RTBFE/M0Ra/ALWcXjYK5trNmj nZ8/RXihxIvaLi5wCKRnvD8U3lHzfEBqa8Azm8MIkiLX2Nn6wF0pZePtKCwQ26PbUN4i iRaA== 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=Euv/yjuzPZRAiWkQXN0/3dsS8sVF8EZnzt+OM2Lwltw=; b=TdwFiFd5Md3SpocFt2C1e9nojCSyAnFHzIsUh8YH1QDNLr/squfDnCEMDCMqdirmqy flwHCMVImBVqjWOTH4UtOsDQeYpVCzay3ylq0twV4vjB5S0FJBiEHeqJlseDpES56qT7 hnkLU/7CzCykV/GdPP7VqrXH50v79xhNrCdAPXL2d63I5qWzuo6jxEUEDmEODFbcgQPJ 6e7sEepDRzPHp/QLRgoDClg1HPbPzf2gn9Xpde+D9wZIrrI5F3HswNrr+ePUgz9sRrVt STMCAN39ApjjaSs8lR8cbXI8Osyhz5vMzawzVKqcLCvqjkqDMcfPl/JBIrP8NVgiR5RH v3Cg== X-Gm-Message-State: APjAAAWNndsihn4BvJt6lXG54ehrAEGlSpaUccBBNR+2N1CsPNQfqbEf mHLPfTfX3Xe51QPhQY9h1pcoTLvPClU/jjFbG+VZg+PFiRNW/UdTc6ckuXmkjkIWkUOTE3aAg2d LJetFRrodwo8OdEMp1yTUcuzTdnG5BGtB6juLvmOuaTsNXl9Rv9OXiKCa/8hbz0Riyd2ryhw16g == X-Google-Smtp-Source: APXvYqwJbreNdSbzk6OyBNsgSauQCmwl9lxjqRjj3zECGx0PgqxlS0adMN8AWK7j2cXDKRezxEnG1XMPnqLKkusjapE= X-Received: by 2002:a63:1e06:: with SMTP id e6mr941179pge.134.1581645267398; Thu, 13 Feb 2020 17:54:27 -0800 (PST) Date: Thu, 13 Feb 2020 17:53:43 -0800 In-Reply-To: <20200214015343.201946-1-emilyshaffer@google.com> Message-Id: <20200214015343.201946-16-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200214015343.201946-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v7 15/15] bugreport: summarize contents of alternates file 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 In some cases, it could be that the user is having a problem with an object which isn't present in their normal object directory. We can get a hint that that might be the case by examining the list of alternates where their object may be stored instead. Since paths to alternates may be sensitive, we'll instead count how many alternates have been specified and note how many of them exist or are broken. While object-cache.h describes a function "foreach_alt_odb()", this function does not provide information on broken alternates, which are skipped over in "link_alt_odb_entry()". Since the goal is to identify missing alternates, we can gather the contents of .git/objects/info/alternates manually. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index a21d081616..e870900c80 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -35,6 +35,7 @@ The following information is captured automatically: - The number of loose objects in the repository - The number of packs and packed objects in the repository - A list of the contents of .git/objects/info (or equivalent) + - The number of valid and invalid alternates OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 1c67b55598..3bc8cb3579 100644 --- a/bugreport.c +++ b/bugreport.c @@ -255,6 +255,48 @@ static void get_object_info_summary(struct strbuf *obj_info, int nongit) strbuf_release(&dirpath); } +static void get_alternates_summary(struct strbuf *alternates_info, int nongit) +{ + struct strbuf alternates_path = STRBUF_INIT; + struct strbuf alternate = STRBUF_INIT; + FILE *file; + size_t exists = 0, broken = 0; + + if (nongit) { + strbuf_addstr(alternates_info, + "not run from a git repository - alternates unavailable\n"); + return; + } + + strbuf_addstr(&alternates_path, get_object_directory()); + strbuf_complete(&alternates_path, '/'); + strbuf_addstr(&alternates_path, "info/alternates"); + + file = fopen(alternates_path.buf, "r"); + if (!file) { + strbuf_addstr(alternates_info, "No alternates file found.\n"); + strbuf_release(&alternates_path); + return; + } + + while (strbuf_getline(&alternate, file) != EOF) { + if (!access(alternate.buf, F_OK)) + exists++; + else + broken++; + } + + strbuf_addf(alternates_info, + "%zd alternates found (%zd working, %zd broken)\n", + exists + broken, + exists, + broken); + + fclose(file); + strbuf_release(&alternate); + strbuf_release(&alternates_path); +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), NULL @@ -355,6 +397,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Object Info Summary"); get_object_info_summary(&buffer, nongit_ok); + get_header(&buffer, "Alternates"); + get_alternates_summary(&buffer, nongit_ok); + report = fopen_for_writing(report_path.buf); if (report == NULL) {