From patchwork Thu Feb 20 01:58:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393005 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 4BFFD17EF for ; Thu, 20 Feb 2020 01:59:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 237FB24672 for ; Thu, 20 Feb 2020 01:59:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RBZLMZPf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727790AbgBTB7P (ORCPT ); Wed, 19 Feb 2020 20:59:15 -0500 Received: from mail-qk1-f202.google.com ([209.85.222.202]:50270 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727338AbgBTB7M (ORCPT ); Wed, 19 Feb 2020 20:59:12 -0500 Received: by mail-qk1-f202.google.com with SMTP id b23so1649362qkg.17 for ; Wed, 19 Feb 2020 17:59:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XOVEK94ibAWDiwcsIzDovjRx3yjjmSxllhzBsSKMAkg=; b=RBZLMZPfyGAY2iMlT6Pw7oh92HO4nmLYZbMjBsZEwLZp2RXzxACXYx8IEGKr/sAp5j pG1gC1ICP7X7jrS+ZnN/WC6D1h0ObDiKF2Q1UQrnuVQC2ZmjqQRV0zaaFF6ucOfCPNhB 3zo4sdAizBDzXjUHo2njLGDLn+u4912T6hIpQKxfT73PZi3l56fsZDMSrmge1SYLnN/L KhpTrX425d5D66+SUJk13DUWcLnv29Q5lYDjcLkFffKMQlPXtQYM25pbF/e14BwyPXNW hgoKfXWpO+oRiBEYjsFuGWUJ5nqQLFmcYFOyIyxaH5DoVm2FNnj8DRn6emaseOEOcMsJ 0lvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XOVEK94ibAWDiwcsIzDovjRx3yjjmSxllhzBsSKMAkg=; b=B3U8qtreUon7zqsWtI5RpBfX+ABkoEfhPFMdoZhFVhvBJnLObqi8oBJWEzQBbEJ8pW GKLG5NktSQ34m5RWAI9TKUViTxRv0dJekuvEVHVbsT5uI/kph6xjeQKhovgUrsmF63+i L0oYfCFRoYD7gyC4pit7b6aGSRyQNhcU4vFxYmXJIN/8YGVSJe5qKIql8qmloXc6Yc9G eCa7s04GWIzytUc7mbBQ8DlntTUz97W+LWXJuP0/MY6jQ0q/WjVDX1jhNo0/QNOaVI/p nvW4x/Xe3aLENO/FQhcMheXErqiZOYIeTKaYInbWEev+Yk9rHtUi1qujTQANdBIDc/fy y+mg== X-Gm-Message-State: APjAAAV0xUoAMrp+uerMMDa0ts/OyDtA0FaQ1bGWYjsM3ToW9TZViTUX Kt/ORSA8ZKDt4UPgw+CQDaZ9P9ijcABBoj2hXI+F09bbV3aujctNoo007twLybNFL4t05W0zU1i MXkbqUlRa2UYFJNG+5guEWczD7D4VeYqtlJN0ArDmk8xwgzK6lCb60BZIWy1rGEaa6dmuxp6TuQ == X-Google-Smtp-Source: APXvYqzAK5VTU/wkEG2jamLMFPrpfnonr2Q6lfc8TyQ3K3LVOoPfBfO5FLba1puySUR5tudg1ZO76d1BZV2Auy6UpJo= X-Received: by 2002:a05:6214:1874:: with SMTP id eh20mr24032568qvb.122.1582163948731; Wed, 19 Feb 2020 17:59:08 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:44 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 6134104ae6..c552312d3f 100644 --- a/Makefile +++ b/Makefile @@ -815,6 +815,7 @@ LIB_FILE = libgit.a XDIFF_LIB = xdiff/lib.a VCSSVN_LIB = vcs-svn/lib.a +GENERATED_H += config-list.h GENERATED_H += command-list.h LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ @@ -2132,7 +2133,7 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h -builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX +builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ @@ -2152,6 +2153,12 @@ $(BUILT_INS): git$X ln -s $< $@ 2>/dev/null || \ cp $< $@ +config-list.h: generate-configlist.sh + +config-list.h: + $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \ + >$@+ && mv $@+ $@ + command-list.h: generate-cmdlist.sh command-list.txt command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt @@ -2785,7 +2792,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE .PHONY: sparse $(SP_OBJ) sparse: $(SP_OBJ) -EXCEPT_HDRS := command-list.h unicode-width.h compat/% xdiff/% +EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/% ifndef GCRYPT_SHA256 EXCEPT_HDRS += sha256/gcrypt.h endif @@ -2807,7 +2814,7 @@ hdr-check: $(HCO) style: git clang-format --style file --diff --extensions c,h -check: command-list.h +check: config-list.h command-list.h @if sparse; \ then \ echo >&2 "Use 'make sparse' instead"; \ diff --git a/builtin/help.c b/builtin/help.c index e5590d7787..1c5f2b9255 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -8,6 +8,7 @@ #include "parse-options.h" #include "run-command.h" #include "column.h" +#include "config-list.h" #include "help.h" #include "alias.h" @@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = { NULL }; +struct slot_expansion { + const char *prefix; + const char *placeholder; + void (*fn)(struct string_list *list, const char *prefix); + int found; +}; + +static void list_config_help(int for_human) +{ + struct slot_expansion slot_expansions[] = { + { "advice", "*", list_config_advices }, + { "color.branch", "", list_config_color_branch_slots }, + { "color.decorate", "", list_config_color_decorate_slots }, + { "color.diff", "", list_config_color_diff_slots }, + { "color.grep", "", list_config_color_grep_slots }, + { "color.interactive", "", list_config_color_interactive_slots }, + { "color.remote", "", list_config_color_sideband_slots }, + { "color.status", "", list_config_color_status_slots }, + { "fsck", "", list_config_fsck_msg_ids }, + { "receive.fsck", "", list_config_fsck_msg_ids }, + { NULL, NULL, NULL } + }; + const char **p; + struct slot_expansion *e; + struct string_list keys = STRING_LIST_INIT_DUP; + int i; + + for (p = config_name_list; *p; p++) { + const char *var = *p; + struct strbuf sb = STRBUF_INIT; + + for (e = slot_expansions; e->prefix; e++) { + + strbuf_reset(&sb); + strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); + if (!strcasecmp(var, sb.buf)) { + e->fn(&keys, e->prefix); + e->found++; + break; + } + } + strbuf_release(&sb); + if (!e->prefix) + string_list_append(&keys, var); + } + + for (e = slot_expansions; e->prefix; e++) + if (!e->found) + BUG("slot_expansion %s.%s is not used", + e->prefix, e->placeholder); + + string_list_sort(&keys); + for (i = 0; i < keys.nr; i++) { + const char *var = keys.items[i].string; + const char *wildcard, *tag, *cut; + + if (for_human) { + puts(var); + continue; + } + + wildcard = strchr(var, '*'); + tag = strchr(var, '<'); + + if (!wildcard && !tag) { + puts(var); + continue; + } + + if (wildcard && !tag) + cut = wildcard; + else if (!wildcard && tag) + cut = tag; + else + cut = wildcard < tag ? wildcard : tag; + + /* + * We may produce duplicates, but that's up to + * git-completion.bash to handle + */ + printf("%.*s\n", (int)(cut - var), var); + } + string_list_clear(&keys, 0); +} + static enum help_format parse_help_format(const char *format) { if (!strcmp(format, "man")) diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index 71158f7d8b..45fecf8bdf 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -76,23 +76,6 @@ print_command_list () { echo "};" } -print_config_list () { - cat <", list_config_color_branch_slots }, - { "color.decorate", "", list_config_color_decorate_slots }, - { "color.diff", "", list_config_color_diff_slots }, - { "color.grep", "", list_config_color_grep_slots }, - { "color.interactive", "", list_config_color_interactive_slots }, - { "color.remote", "", list_config_color_sideband_slots }, - { "color.status", "", list_config_color_status_slots }, - { "fsck", "", list_config_fsck_msg_ids }, - { "receive.fsck", "", list_config_fsck_msg_ids }, - { NULL, NULL, NULL } - }; - const char **p; - struct slot_expansion *e; - struct string_list keys = STRING_LIST_INIT_DUP; - int i; - - for (p = config_name_list; *p; p++) { - const char *var = *p; - struct strbuf sb = STRBUF_INIT; - - for (e = slot_expansions; e->prefix; e++) { - - strbuf_reset(&sb); - strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); - if (!strcasecmp(var, sb.buf)) { - e->fn(&keys, e->prefix); - e->found++; - break; - } - } - strbuf_release(&sb); - if (!e->prefix) - string_list_append(&keys, var); - } - - for (e = slot_expansions; e->prefix; e++) - if (!e->found) - BUG("slot_expansion %s.%s is not used", - e->prefix, e->placeholder); - - string_list_sort(&keys); - for (i = 0; i < keys.nr; i++) { - const char *var = keys.items[i].string; - const char *wildcard, *tag, *cut; - - if (for_human) { - puts(var); - continue; - } - - wildcard = strchr(var, '*'); - tag = strchr(var, '<'); - - if (!wildcard && !tag) { - puts(var); - continue; - } - - if (wildcard && !tag) - cut = wildcard; - else if (!wildcard && tag) - cut = tag; - else - cut = wildcard < tag ? wildcard : tag; - - /* - * We may produce duplicates, but that's up to - * git-completion.bash to handle - */ - printf("%.*s\n", (int)(cut - var), var); - } - string_list_clear(&keys, 0); -} - static int get_alias(const char *var, const char *value, void *data) { struct string_list *list = data; diff --git a/help.h b/help.h index 7a455beeb7..9071894e8c 100644 --- a/help.h +++ b/help.h @@ -22,7 +22,6 @@ static inline void mput_char(char c, unsigned int num) void list_common_cmds_help(void); void list_all_cmds_help(void); void list_common_guides_help(void); -void list_config_help(int for_human); void list_all_main_cmds(struct string_list *list); void list_all_other_cmds(struct string_list *list); From patchwork Thu Feb 20 01:58:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393003 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 20975159A for ; Thu, 20 Feb 2020 01:59:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 018B424656 for ; Thu, 20 Feb 2020 01:59:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q1MX+Blk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727721AbgBTB7M (ORCPT ); Wed, 19 Feb 2020 20:59:12 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:46375 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727686AbgBTB7L (ORCPT ); Wed, 19 Feb 2020 20:59:11 -0500 Received: by mail-pl1-f201.google.com with SMTP id t17so1314619plr.13 for ; Wed, 19 Feb 2020 17:59: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=cX0wSw+SUUTI4SBcSf/co+qSodXsGSCbZOly9kNlUfg=; b=Q1MX+BlkqltVVWuK+fZhbifnJlF5ERWRii38zRO6QGzQ5k+1J5n73hP4XLWSttLlwT 6P8CJov5DBEeTQAz0M2vcrpq5zqsNeW6H98Xl2zB+CsWUBcWX2mcrBgUUCTAq5aF57jM f9zg0xRX//94vQVXOriFdDHZ3HKyoj8awJ19RyAQFANu0rZ8OTsY7mgi1PpDrkPBNM3i i5bUeuzoItiAO3fhJq4r7D16CCUAqjhY1I1p8tBgFNcVvPJnY8H+evzKgF3+YG7XLBaY MLi0puHIfmdLTS5L5FrRet3UjsSbTvOpxo88nTzDsP9cIy/g8G84+N/m/B909Xg9JbYK Ap8Q== 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=KWLx2Hmn8NeU9AmAmq/4mDBCJafm/b6k7ZE3TJui8FmslaXRlHamkVw+x58zzuIes+ 8zB/Jat4OiRbaahvgHyHsrBhL2F+Q+PfoLjG0PKRGoxdZW+yrZAnWYH4cjZC8TV9u048 oOiAemvhsvgfUxfE0LjYqCJvUfed3z8IvpoRVE37fJaMNM8/Rqn43YRYnk4x39NDWZjK OxQ0AZsAHUDaxZ7KLOVTlWqAL0aNlID3S5vLX/pF7GOnKgNw638HSOfa/Qa9PyeTqcXM ZltGHJuPgBgUuQJEiC1JwB0AeEG9ZxH767rptqpQcaoMK2KDHnsOI+uSKnNwdRacNRM4 GJ8Q== X-Gm-Message-State: APjAAAVJ8CV9acR04kO3Jf4dgHUrcNRnUSrA7Zudk+iejDeCMYpiWVOV aWE2sC5gOLXUwziyAcZiFUclBAY1ULDq+Sp8MUCPlMpQG4uOjLpS+xbUaqHgpS/3gJnOaQ8EdH7 YAc7zcX3LUkWsmFlLEJV47rHwE2C2VVcUFf+9rlXgF8rCJnq0pDxHpzmNDwJ1ik4YfEBnlG2kYw == X-Google-Smtp-Source: APXvYqxAnrirPr1iRDEYill5WY4t44S0YwVh4GGmyuOMT16mBQnVOss2jo5BMA3GJPyoVuMj37S6b9n9srCcX7XzdHA= X-Received: by 2002:a63:4a58:: with SMTP id j24mr30839972pgl.166.1582163951179; Wed, 19 Feb 2020 17:59:11 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:45 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 Thu Feb 20 01:58:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393007 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 B08FB17EF for ; Thu, 20 Feb 2020 01:59:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8971124671 for ; Thu, 20 Feb 2020 01:59:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RVF2VdaC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727778AbgBTB7P (ORCPT ); Wed, 19 Feb 2020 20:59:15 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:34721 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbgBTB7O (ORCPT ); Wed, 19 Feb 2020 20:59:14 -0500 Received: by mail-pl1-f201.google.com with SMTP id j8so1331287plk.1 for ; Wed, 19 Feb 2020 17:59:14 -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=gMuK/aYCnWssb/NyknfIvTffg+RtpoiWKCFbfUo6DKo=; b=RVF2VdaCn4mfJjoApXiUZTeMQmeQegUmI6reUdCw/+hB3aF5nXF58EMGYGXKQuN+Eg qquF9T0iSE8o3XSdT5BS1meA8lF6YgUPePbfRVrdhaz7n9gVK/W1cEvbWNS3XoSaxDso hEDHd4UUYO+/q4VVhfl27HTl8ZD6Gg7cxawPRnTu191mKR3bDwPIBz2t1llYrpgp7lH2 ps4Wq3qRH+AMl6fTPtoGLW6sETp2ifOM1z0WwnhSu6p0z1ZJZcre0SjvIUMeG/4SJfXw TsKw3lU5oSG+Y98+r83Yvo3+B1+eJkDEeAl6B4zDQxdWDXd4qs1YiAVMzlLfrc83CQIb 4Ndw== 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=gMuK/aYCnWssb/NyknfIvTffg+RtpoiWKCFbfUo6DKo=; b=q9GKf0z2F7SiaSwwSMq91TVZ2EAPObBddHVO7FDPS7gLBf24DdI9Jr8Pjg6ccngC33 TiQ0Npz8sSz++pwpWoYmC3b8rC7zYKpmF821S83Zg7ZTdfnICr8H8NoOZOhhBHC3qREl 85oTC+dbNpEJc8782XuYHMa9V5C3jQiDIENIkHZ6fEW3jeJq26LDDwLhZvrteGUCyW2M bx04BREwSd5L4Tf6ZFusP/LJV5QHDdZjgC60kyfL7j7plp87VI+sDXr8kGhqD3MyaPam XNw3GpXFanSqe3RzRk9CMcWFlzvfkXAmbzLnUHmmE4tCTSj0zOOHebPWeX246I8NrGk9 g+Jg== X-Gm-Message-State: APjAAAXlmBw0y/K3170i3CEwRaPqXPNV6K3uD+G7B8ZYGrNCnUtMhKvh ooG60HORK+uopFwmwTUIOI5d3h57Ajzbs9MkJxe7yc3Yi98dyJ8bl/SzLE2vQdw9X+GGdRGtpGe gCCrFK5eXObHqy75Xo6H6QB7agPtvAks+S8uEkgT4faJrtYNdzj0BSGSjLYtUjd8IqrNchwmydw == X-Google-Smtp-Source: APXvYqw6Zlu9EqVAyXzqVyiltCGysMn7XK4hfcDij9qYi5fExAU0YRBnn3K0/IkUQA6CN+oRPodw2/OuLPNn+wdTGVY= X-Received: by 2002:a63:ca04:: with SMTP id n4mr30782897pgi.110.1582163953705; Wed, 19 Feb 2020 17:59:13 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:46 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 Signed-off-by: Johannes Schindelin --- .gitignore | 1 + Documentation/git-bugreport.txt | 46 ++++++++++++++++ Makefile | 5 ++ bugreport.c | 94 +++++++++++++++++++++++++++++++++ command-list.txt | 1 + t/t0091-bugreport.sh | 61 +++++++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 Documentation/git-bugreport.txt create mode 100644 bugreport.c create mode 100755 t/t0091-bugreport.sh diff --git a/.gitignore b/.gitignore index ea97de83f3..d89bf9e11e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ /git-bisect--helper /git-blame /git-branch +/git-bugreport /git-bundle /git-cat-file /git-check-attr diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt new file mode 100644 index 0000000000..1f9fde5cde --- /dev/null +++ b/Documentation/git-bugreport.txt @@ -0,0 +1,46 @@ +git-bugreport(1) +================ + +NAME +---- +git-bugreport - Collect information for user to file a bug report + +SYNOPSIS +-------- +[verse] +'git bugreport' [(-o | --output-directory) ] [(-s | --suffix) ] + +DESCRIPTION +----------- +Captures information about the user's machine, Git client, and repository state, +as well as a form requesting information about the behavior the user observed, +into a single text file which the user can then share, for example to the Git +mailing list, in order to report an observed bug. + +The following information is requested from the user: + + - Reproduction steps + - Expected behavior + - Actual behavior + +This tool is invoked via the typical Git setup process, which means that in some +cases, it might not be able to launch - for example, if a relevant config file +is unreadable. In this kind of scenario, it may be helpful to manually gather +the kind of information listed above when manually asking for help. + +OPTIONS +------- +-o :: +--output-directory :: + Place the resulting bug report file in `` instead of the root of + the Git repository. + +-s :: +--suffix :: + Specify an alternate suffix for the bugreport name, to create a file + named 'git-bugreport-'. This should take the form of a + link:strftime[3] format string; the current local time will be used. + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index c552312d3f..9e6705061d 100644 --- a/Makefile +++ b/Makefile @@ -681,6 +681,7 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) +PROGRAM_OBJS += bugreport.o PROGRAM_OBJS += credential-store.o PROGRAM_OBJS += daemon.o PROGRAM_OBJS += fast-import.o @@ -2461,6 +2462,10 @@ endif git-%$X: %.o GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(LIBS) + git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(IMAP_SEND_LDFLAGS) $(LIBS) diff --git a/bugreport.c b/bugreport.c new file mode 100644 index 0000000000..8d4a76fdac --- /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..65f664fdac --- /dev/null +++ b/t/t0091-bugreport.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +test_description='git bugreport' + +. ./test-lib.sh + +# Headers "[System Info]" will be followed by a non-empty line if we put some +# information there; we can make sure all our headers were followed by some +# information to check if the command was successful. +HEADER_PATTERN="^\[.*\]$" + +check_all_headers_populated () { + while read -r line + do + if test "$(grep "$HEADER_PATTERN" "$line")" + then + echo "$line" + read -r nextline + if test -z "$nextline"; then + return 1; + fi + fi + done +} + +test_expect_success 'creates a report with content in the right places' ' + git bugreport -s check-headers && + check_all_headers_populated >git-bugreport-duplicate.txt && + test_must_fail git bugreport --suffix duplicate && + test_when_finished rm git-bugreport-duplicate.txt +' + +test_expect_success '--output-directory puts the report in the provided dir' ' + git bugreport -o foo/ && + test_path_is_file foo/git-bugreport-* && + test_when_finished rm -fr foo/ +' + +test_expect_success 'incorrect arguments abort with usage' ' + test_must_fail git bugreport --false 2>output && + test_i18ngrep usage output && + test_path_is_missing git-bugreport-* +' + +test_expect_success 'runs outside of a git dir' ' + nongit git bugreport && + test_when_finished rm non-repo/git-bugreport-* +' + +test_expect_success 'can create leading directories outside of a git dir' ' + nongit git bugreport -o foo/bar/baz && + test_when_finished rm -fr foo/bar/baz +' + + +test_done From patchwork Thu Feb 20 01:58:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393011 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 6F469930 for ; Thu, 20 Feb 2020 01:59:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4732521D56 for ; Thu, 20 Feb 2020 01:59:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d3qJSF5l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbgBTB7T (ORCPT ); Wed, 19 Feb 2020 20:59:19 -0500 Received: from mail-pj1-f73.google.com ([209.85.216.73]:34591 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727338AbgBTB7Q (ORCPT ); Wed, 19 Feb 2020 20:59:16 -0500 Received: by mail-pj1-f73.google.com with SMTP id v8so852582pju.1 for ; Wed, 19 Feb 2020 17:59: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=PPv7++FpeksN7EXMu0/NkT5FBZuOUS9HjZTLmuUSToA=; b=d3qJSF5ljd529rVyytAoUF8kLKHTgO3/A9yGfAEqMdNtaLzKIY4y8GrxVZ8zmUTwg2 p5XTQjB5XiCQqZuChmr4DZNxkI6y3Alaert9FqWFLpg0R0icR27X0pQUkkb9ZwtCGa/g qd1hDy7KNF1RLJXyDJ6+4hzKbxxAnWlyNFT24RAuhGdrpYVp19muiGUZKn6WyQcwRzkI cWAw4rqp/xpW3XVKPEBTrz3fL92Xvrb9lUhiButcBZPJ1mwgU8ijAJ1OWfabkUSJzJjy SEi0mUbXHl7MH4Kf75aRpTTNZCX7Za6dlcXOckGXvScPyq2Oj9yZx+BoSs7AvbWnmGfi Pgzg== 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=PPv7++FpeksN7EXMu0/NkT5FBZuOUS9HjZTLmuUSToA=; b=B4AbjmHgaY29erkAk1Oru9z4HsPGPRLbSBtEUg5Pbog6fMkWx8mJXlg2+Mmthu6zPo a0gkUs985caGTLBfZ4+5A/IdJ7xay+8sx0i8nUOXOX43iqd/fGZPExCa+sh54NdfRQUL 6HWpb7/QT5/VjBbVZ7HvXgWO4YktQIgUDhuUlcuRaRrTGYqVsx7c6qeCohv3CQuzt+lm GYauzi3XJPEKY1s7I9pnFQhcpjxZTFUSnwGYW3LLNJwPxXkDZawVfNtE12uXjSx2TQOc KinxxrflYDflBKy7lU3B9tzq72JYwc+r5PdxY3SXz5yzi0pv3d00TlXXVHEZG6/riqok Oxqg== X-Gm-Message-State: APjAAAWg7jw2GoIxZYa3g5JmGOEXw6pS6ckrjFrOcej1qTQ5SFMu9quk 62AZVqUC1D90WDkNdNsZTvs0OBlrp9i6sGMIEb9DzpJTTSOmq+OdplHEu6r5QJCqLBshcretGqH AKNDaMDYI+yw77TNO9ZppmuJXZjpc8tiDJKTNSqhzzZxCO/WClYHu2yVye2sQ62WYXVigRbqEAQ == X-Google-Smtp-Source: APXvYqxGnPvwud3Ch9bzFj1ivFI7eCOkCHkaTz3Pq3rVmG7qEXi2hySj5yKzIrryxrku0UYueEPr72ON8ymYsniQIvA= X-Received: by 2002:a63:78c4:: with SMTP id t187mr27922321pgc.88.1582163955953; Wed, 19 Feb 2020 17:59:15 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:47 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 1f9fde5cde..f44ae8cbe7 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -23,6 +23,10 @@ The following information is requested from the user: - Expected behavior - Actual behavior +The following information is captured automatically: + + - 'git version --build-options' + This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file is unreadable. In this kind of scenario, it may be helpful to manually gather diff --git a/bugreport.c b/bugreport.c index 8d4a76fdac..27f813643d 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 Thu Feb 20 01:58:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393013 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 3765B930 for ; Thu, 20 Feb 2020 01:59:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17E2A21D56 for ; Thu, 20 Feb 2020 01:59:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kUpfgkfw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727845AbgBTB7U (ORCPT ); Wed, 19 Feb 2020 20:59:20 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:46377 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727723AbgBTB7T (ORCPT ); Wed, 19 Feb 2020 20:59:19 -0500 Received: by mail-pl1-f202.google.com with SMTP id t17so1314760plr.13 for ; Wed, 19 Feb 2020 17:59: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=SpPiasmSu5nM5NYBdp5tPGkqhgk/t4aM+ow6hD0Pomw=; b=kUpfgkfwY2NLiKOu+O6TaW6eUWKSwk+C1Rxc8YkJ8Oc/iv31NhUkLvVwlaP3RPimzy RtuWAfyo89D0hkvFPsPngfz4JFmgb5Hs/+VX58jWv7PmKYEEvbgNq8PIAyyHFC472VjG yFsxV4bGLnyVtHe+7ilbYPXURJlFxiB2DOSqDFeGp8GYL+d3drF7jz9zg5vo22qQzjWY Qm7jsZG2327ZCmBTEjVspanPYbXWjowVDnHGRLFaEHkcYUXKoVxQVwya8ApGkiyIqD/f 0edSdpvdpyoXkkh+OB+Hg25S0+Y58B70ekFqp+he/QMvPLpA23Ehf+xiJ676S4gbunIm f73w== 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=SpPiasmSu5nM5NYBdp5tPGkqhgk/t4aM+ow6hD0Pomw=; b=Hoe4Vsg4lixbpsBRzpeBuFCt2QZ/q+BPfIjnNma8UhHk3TvsnHqjZiB+i8WERJj9Em n9IBw++xaUqxt5wWXQa909jU7z9STvNxae47/9W/DU/S7boZpSX5x9qXTSSpXxah4znU +eeO/x3v1Z6rZc5noJaGHzAitz8/p1bW8PBMiTyzVQi3doQPMRx/Zjx6F4JWF8M/FAV8 +Oq52V01Ucbfdt91oUXgzfFZab5j/Z5/OoMAhSDJrh5o0bIqQfd3JbnEUqQzFPGWnm/J /T8N0Tl3DBgfVemjJ0R/p72/mu8rqGjRb/igBRWpllQwY5XDXNVIUQ2SyhiKtOI9INXf jIgQ== X-Gm-Message-State: APjAAAVKNum8NqKZ7zADsCc1ml+XS548CJmeTddMDEPUjn4rtarKuSoc CMUmbqs+P6YdwzpDa9e4jpcKJu+DsUapqhZhw0BcbZTuqNC4IlvqyUuhPAqKRIbRwzQIWWB48rQ zZJ0OYgsE/Fy6M7QD39f0mdxEDoOGQC5CVgGEI/v0dYGqAboysvpY11qCqzRxCKS3s0AHMj7VYA == X-Google-Smtp-Source: APXvYqywI8wL6ftFbAfpO3pNKEcxWnhLFW+HE+hGZ7H5Wp8+6FnGh2nb+m3gWSyMk4X+xaY+qFfLuaHdydrFbWBVAAU= X-Received: by 2002:a63:ce03:: with SMTP id y3mr32003841pgf.427.1582163958259; Wed, 19 Feb 2020 17:59:18 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:48 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 f44ae8cbe7..17b0d14e8d 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -26,6 +26,7 @@ The following information is requested from the user: The following information is captured automatically: - 'git version --build-options' + - uname sysname, release, version, and machine strings This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 27f813643d..06a63cc283 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 Thu Feb 20 01:58:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393015 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 C61D9159A for ; Thu, 20 Feb 2020 01:59:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A71C024673 for ; Thu, 20 Feb 2020 01:59:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K22F3D2W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727855AbgBTB7V (ORCPT ); Wed, 19 Feb 2020 20:59:21 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:39499 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727723AbgBTB7V (ORCPT ); Wed, 19 Feb 2020 20:59:21 -0500 Received: by mail-pg1-f202.google.com with SMTP id r192so1310422pgr.6 for ; Wed, 19 Feb 2020 17:59:21 -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=lnD1toCn+iOJUERHZpCUgmvnhHcVAtSQuMPI4z1CnBk=; b=K22F3D2Wzo7RjRbpDHtdA+bajGvWaGz+x20EnsvOzMFp1ZJQx7wf2yI6ShA5rKNkAi 5Q9g5UwvAvbUiDuaIMV9EoJT+kHZiZEDMIzjyVRuSC8nzq0HkL50H6ugMf/jQ77olQ3J rsfE+dK/g56yO2lt+D0jR65aVnJ68nCThArklQg08kXw200X4gKJEULx930PStdq1CoX 6sDrYphvRR56qByJjoUGVBasMAImAubZ9E4yKSSdcy4Tj4vpIt11TGHITJBztVIRdK1c f4O3Oa+jMZE5Mz3QMxRA1i3GcD0PzyKn/WGNne9QMZLt3cUI9SuqowwGuXi6uJOutN4v 4mRw== 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=lnD1toCn+iOJUERHZpCUgmvnhHcVAtSQuMPI4z1CnBk=; b=oV+FLp5wkYPXEFMj0EjmyrdhozBor54yT8bWhDwC8wdrmmNKQBs+kv0ITwgOPITRqp rNbz9iJtJzYpKb6suVjdmurvmSPBUE2/boUyiQkv9ACz36CoA7uI3i140vOkFz2T+GnE jMayOuZtSqb+gWn6bJ9vyxMWp+wk3mG8Rn1z2Ft7nqH4tDSE6ZpX0VPoJQsrRuSZmG2o npi1YZKAPE+tm4O0udGwZluVwzp1C0rKZ9Z9Are/GdEjiNqUA8jQ2jklqHiscTncK0gL kp1xNskTK4CMYboz76CZYAV6FGDy/XQ9Vm1WI3NmPwD5TsCboj+2Pk7aZdTAVpFRqWRB lLcw== X-Gm-Message-State: APjAAAWfHfyjuBWd8gkrrGSwYNQywCx5+aIZvghriryIsZ0YqSjrSWOx P6SyrT8zxE+nyc4PD7POKssfazU2txl+ChJj2Lwa1EFtOtUi+QyIz8m9qd2Vent7a/X8xdfGMTh JvsNUHrdh4KK2Xka62Of8PCkznQzGVss92sSnZ2ZSf1KArwtpig5BLm5RyTXpsSfACPFHjjKnBw == X-Google-Smtp-Source: APXvYqwEowKZTbUkO7ZJumJcr82yMS86/ZXmkvZbDI6cGiRSuy4Y4DCapldFD6eVHnWrmTZlFYSrrk8KA5Mf4LU0of0= X-Received: by 2002:a63:7c4d:: with SMTP id l13mr30982788pgn.275.1582163960397; Wed, 19 Feb 2020 17:59:20 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:49 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 compat/compiler.h diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 17b0d14e8d..643d1b2884 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -27,6 +27,7 @@ The following information is captured automatically: - 'git version --build-options' - uname sysname, release, version, and machine strings + - Compiler-specific info string This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 06a63cc283..9a470c5588 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..ef41177233 --- /dev/null +++ b/compat/compiler.h @@ -0,0 +1,27 @@ +#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\n", gnu_get_libc_version()); +#ifdef __GNUC__ + strbuf_addf(info, "gnuc: %d.%d\n", __GNUC__, __GNUC_MINOR__); +#endif +} + +#else + +static inline void get_compiler_info(struct strbuf *info) +{ + strbuf_addstr(info, "get_compiler_info() not implemented"); +} + +#endif + +#endif /* COMPILER_H */ From patchwork Thu Feb 20 01:58:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393017 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 9A157930 for ; Thu, 20 Feb 2020 01:59:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 79C8324656 for ; Thu, 20 Feb 2020 01:59:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pZEj8enD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727862AbgBTB7Y (ORCPT ); Wed, 19 Feb 2020 20:59:24 -0500 Received: from mail-ua1-f74.google.com ([209.85.222.74]:55670 "EHLO mail-ua1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727723AbgBTB7Y (ORCPT ); Wed, 19 Feb 2020 20:59:24 -0500 Received: by mail-ua1-f74.google.com with SMTP id 71so354679uae.22 for ; Wed, 19 Feb 2020 17:59: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=ZayymgcPEffs+lFpPs+5gCaPklpmHgqLccRVAfxofaw=; b=pZEj8enDbYr/pMo32JBC/kacySJIe+/b7LL+rYE7ZR5dE2ku0srfIwZuUS6U6zDAzI fjhRQIqNueHC4zwnZApv4mjEgoi8sYAfUB9RyO3RW2b1Fwo9JclzojAq8yePTNPxjy7G nwg7bRaLbD2HTHgaKTDw13fLNpPlYevJAEzencLe4NYrF6Bnjtlcdyt6gL68hB7mx+3r 8GCXF062EXFEYzdNaVjCZG6sbjON4D9TfDEdBPOTCU8Jy3QpkS6K+0ueScfERO4AXZce VDyiiTquez76Nwdu/0825ZBSYmQCodtTqFr6O1vkmt4vFc7gm3/obV+NT+gNiRpwtcE+ 7BuA== 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=ZayymgcPEffs+lFpPs+5gCaPklpmHgqLccRVAfxofaw=; b=sQpBlufPaavfty9/kg4zwCS4UUbU+vjOLk5uRlOapGERfUf5njGt0mrsA3md9l1byW 6HQB1OD7qpXY1DOxzuqiDeUTxeEueyJwW+AOOPlodaLlXMnpdV6PcOS/Zrdpael8hSZF ZF693Wwz/ytDNxCvnvxGdAEIjYUSmUpuUNd/dEXdON4vDISkYnJocn1SXxwNGqvIlCvM 0TUWwD8Q5jzhMcrgAe4rx4MZ9OPvjkCSExGgB+vFSR/ryZ9WsJw6g9t/WekjGklohOce jap9vTfCWwRENVR+VWYa1xzznm+bimFIir7jq3VGBnsjzy9sKcg/M6YnIxN92BMOgbK9 EYFw== X-Gm-Message-State: APjAAAVoZpnQNIJThNnuJ6FhPOhLhi01eCH+e5CwlujnOpYl0XWF7Lqn clM0zdeIhPn7D5ijvExur7m8VpYaT6vpeVgIKxQonwHoXbESZGsGwdyGTyzN8rO2B/5Jr9PSyY5 UOEW4n0/Ek/ISmU2YXoSUqWbY+LwhNMP4cCa2QiTiWqrzCpt6iscLxBOApO0HnPEZZcaaLqeUVg == X-Google-Smtp-Source: APXvYqwxKpGsxj3kfue/RkSkl7q3TGKs0NU3PHOSihULhEjTbru8CIf0xgSdsWn9Ta2JBmhe8rs6Z51t0bx4D22d3VE= X-Received: by 2002:a9f:36ca:: with SMTP id p68mr15472244uap.112.1582163962912; Wed, 19 Feb 2020 17:59:22 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:50 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 643d1b2884..8c7cb9a5d4 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' This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 9a470c5588..fb2adfdf14 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; + + cp.git_cmd = 1; + 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 8eb96152f5..73e52175c0 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 */ @@ -1375,6 +1376,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 Thu Feb 20 01:58:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393019 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 7A841930 for ; Thu, 20 Feb 2020 01:59:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B3C124673 for ; Thu, 20 Feb 2020 01:59:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LDYW+K6I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727135AbgBTB70 (ORCPT ); Wed, 19 Feb 2020 20:59:26 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:55784 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727211AbgBTB70 (ORCPT ); Wed, 19 Feb 2020 20:59:26 -0500 Received: by mail-pl1-f201.google.com with SMTP id w11so1296759plp.22 for ; Wed, 19 Feb 2020 17:59: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=4fAfY9ZuFVJkqi21nOKHqeSxjD/1TQgAIkoaLZ5gj2o=; b=LDYW+K6IY5InamqauYcOGzA6vs3vSaoJmlxGGFk3WD00rqvNLDBbA9VggveI+zhlp8 NtSG9KdmUevIEF4+wUbx0hbpnDKlevZbgZLLvFx/blZOvT7HifGm/Jza+UHbJcKu3xo1 S4V7cUcWGB9mnE/dr9vZwZrN1sdgdJ0wq+2iYjqprt7AGbHTY6ZOi+130WT3fImYYSHz pAzq+arMCsdrQy9yhoYl2OLs9a+ybLwbKRnOCh0J0duRWXuS6lmH5lsRw5ciu4QE8tFy xGJB/CSV2zoXT+ZZq0JGACy3AEiRMDMeHJpJY7vjVaoKotnG6TJVSzmMYd51PzKWXFC3 qVAg== 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=4fAfY9ZuFVJkqi21nOKHqeSxjD/1TQgAIkoaLZ5gj2o=; b=JQpXbw9F2Bq9Tk45/M/wRKF5/dF1NdheoOgG0VVIgT1j82lFACQbf7ZqgO3edX30Ut iRXc3VeHeVv+UbpNxwjGcqMjNSO1m2NZUHe0uNqodTCNb0yzj38EsYTf/OAz4WSrXE2U otlSkLvwqmfN6XS56Hxn3rhzuQUEzwnBZ+l1SKmRrQVfZP1VOonhoIm+t0MNPjCaVGoD UYterAMXFipehoaRfkJP7DNmeuYmb31VsAzjjWfuRhnCNZX02LRz4Qmx1ta6S0HKvhe9 LEuNVB973YBbIbVa25JFLOxReGbABm780CXJOT9Uh7DykuRcVUmIf3dMQ8GoyBv47KYW +puw== X-Gm-Message-State: APjAAAXUSIuL/7/ktXRw6IzMvZxHweUO+pZspt0Soq78Vsq0Biov8onM 5lAskmvtgl2bRa4naWlSJphOoBhooiDiT+ho+y13zOPlzAONxB9J49A6VPoK5n2xzf3oVTgn76M U+PRkCF0mu1uvcqsM4w6POlN1kn95uIAbvmiD3c4LUPXERIOzZm1Xrv2yMROeiNyP/211/RAzqg == X-Google-Smtp-Source: APXvYqzZgWC0ob2puEt1wl1BmBjDaOZJySdZJEMCMRGwMoe9ewnOQVr9gHUSedfoaa1WeSC5twEzQtK0HN/qimdQOt0= X-Received: by 2002:a63:5fcf:: with SMTP id t198mr30369113pgb.383.1582163965286; Wed, 19 Feb 2020 17:59:25 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:51 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 8c7cb9a5d4..f7a13c0374 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 This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index fb2adfdf14..f143b9a8f8 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 Thu Feb 20 01:58:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393021 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 800D2159A for ; Thu, 20 Feb 2020 01:59:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5958224672 for ; Thu, 20 Feb 2020 01:59:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UzZfNFe7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727880AbgBTB7a (ORCPT ); Wed, 19 Feb 2020 20:59:30 -0500 Received: from mail-pg1-f201.google.com ([209.85.215.201]:57129 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727211AbgBTB7a (ORCPT ); Wed, 19 Feb 2020 20:59:30 -0500 Received: by mail-pg1-f201.google.com with SMTP id 71so1294156pgg.23 for ; Wed, 19 Feb 2020 17:59:28 -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=QZ8q3r9Q7hgm2TvFM3fgvkUNdUbyqVziDTc1j1AN4C8=; b=UzZfNFe7h61+gne79Oo0FkCw5fYmuyqJtbSsiYXOX6XbMRVTa6zCW4hrJtdw+xvxWA t1ATUrbNF+pvInf6H6LUeEH/L5WXNNBdbpyvhuFc43ENI1F/47FKfBVgzBL36u0qjRps CktvCrh5D1cEHyTGuyO62rnWq/4NX5ZR5W4L36l6XE+qGJWIzZlAVI7ltzP15K/L3VVl mNl46tf+hLhoL2fISQEc0pPQl6hDRpmyyWqhIylKnA560c9DgVel0qmLeUMFBin+k5Bq truynOBU8dFDAfGDX9vMNg1AHpH9NtiiEdYHXVzTPovPfX30c4kp/tGwiQU1YO1PLprW IbFw== 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=QZ8q3r9Q7hgm2TvFM3fgvkUNdUbyqVziDTc1j1AN4C8=; b=tyb2H8jBor4dzOSDHWE8JWsbESpbnwy0PNNYuv3XXHisnD2LTBcHM34aAV3wpAKBOi +5hZWbja4Sh4j8fIlXSqh/iI88m5Eow3l1pzfH+dfHiVmuaUvzh9KXe5o/IJIuk9Q9Aq edUcq9+bgkJEfSjQNIMC/7ftqsNfF+4zHy0lgVS3iwBU7DxgbmvtJRj6bFkQGBsLa6hJ 4zFOJ2hTy7xoiYUqr4zOPh5fNc4TCmk52nBeyJKxKf11WEkEwYX8dCZOwRLMYWfyv0cj Muqmk2+tImthrniwLiwSh0S/mFLi8iYAdFd02HtmHeZF3IlPspLdqGVxvWTBjQq/eM5t 2mqQ== X-Gm-Message-State: APjAAAV/+fwowwXfI5Kz3cVfRMIyGFWa+88iAl+dxg1rQAyJt5VTpHam cTah3t+LmvO+vJZPrAtl6RN+CpWUGmZB1qMO4Hz+YFCTb7Fk6ChN5JbqB/amk2PPd2R94TWjDqk citYnvpQYk63XlD8BgFV+1O0FIY0rErHzLG4CbKYZNbjm5Cb22r6neFV5RdCgpH7NhLbg21P9bQ == X-Google-Smtp-Source: APXvYqwRJgSIZ6UAMHgFGT4fRjGhjsGzSIdWzL6AJm5wywnMerR5pVEyH60Y5a76LMyX1VAVsFJepcz8YwrPczzZmRg= X-Received: by 2002:a63:e545:: with SMTP id z5mr30143358pgj.209.1582163967522; Wed, 19 Feb 2020 17:59:27 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:52 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 Signed-off-by: Johannes Schindelin --- .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 9e6705061d..6bdd3b9337 100644 --- a/Makefile +++ b/Makefile @@ -818,6 +818,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) . \ @@ -2167,6 +2168,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..a9e5b6b2a0 --- /dev/null +++ b/generate-bugreport-config-safelist.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +cat < X-Patchwork-Id: 11393023 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 1281717EF for ; Thu, 20 Feb 2020 01:59:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6FD124672 for ; Thu, 20 Feb 2020 01:59:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YpjdMwm6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbgBTB7b (ORCPT ); Wed, 19 Feb 2020 20:59:31 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:56580 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727874AbgBTB7a (ORCPT ); Wed, 19 Feb 2020 20:59:30 -0500 Received: by mail-pl1-f201.google.com with SMTP id 91so1302328plf.23 for ; Wed, 19 Feb 2020 17:59:30 -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=UtdpUwNkCRSn7wSPhXFJonZevlHj/8EUqs0eR5HfvPc=; b=YpjdMwm6yKx8sqN1xLDx290uJz3KPJpB3ED3zOKF697Qc3K1b+nFND2m4pOFd0ULFT CzbcE03Se++pB+fOhaL8R3TQxovrbNoTmbaRz/oC00YEQ3I4pUU2w0+InlLUwEiJ01RE of2gMB6Ey/OVwcfW8TjJJ1LpPsZTUwzux/ofXGFkXd0AQKA77ydd1m6dW/HnfQqDVsfW DR9h2eYlBvOtx3D/d2C/Mmii4cP6q67/xgoH9C80HQdrXx9SGbPsSuQgkaXSeelPwfI3 5SnIaZu49oXfDxzbDDI+brsbDTnYahw8LTPEpoSTFxMOpPbADWVygTnfDCorcWCPFUx8 Adeg== 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=UtdpUwNkCRSn7wSPhXFJonZevlHj/8EUqs0eR5HfvPc=; b=LvUaBVdjkJXUUPmM9Zbd3eXiGJlYPWh0dUWmE1O2ite07Yde8KwKtDFI/T3A5F1+q0 +EOhg6OTA5oLuf8Yp2wtA8xsZIRoPW5+Nn7JX8XyRy4pr3ajTaMIF+fT0ig05FRQouVt PgMIROE92TuDCBoac7tjRXNQ/M6NRDT20dGrWUKEE93Bh95/z0p/5LOD5vYmfMM5lCTz fzI3zwnHDuelMqywY/iuHPaEhX0FVB5b/7nhEO5ZKWgYsEzeFma9sqZGAPEOYZYe0kCT Y5hgu29wUgZKoG91s54HvY7m9qA0AnZtpJy7HVzgQFMxXcew7Kci4HhCYT18xsLFXjJm 8AEg== X-Gm-Message-State: APjAAAWhdIDHG0mpWyYNn9KMVgGVXM1A0vBrXrcksqEV0QUfjzm6SCn4 wDovhiFl0R2TNVAhEGXnyOojxaVts3Z8RW04SN10D5ujiIvhHOUcLxxqswiLwo9mJuNSv1vc8sI RYo0wpxVqrWVABWOAxmlCb67VJlHMqexq4j6dcHHe+jk81/t/GSjVKW7HLMHMvPUjUjKXmD8tiA == X-Google-Smtp-Source: APXvYqypMtNlnGwqgfR96QwkbOHywVtorLBff+46WIma5w3ki2aQLcwW/eNCe+XdNCwQxpaJjVG9Ahn8Mc26Y/toMNo= X-Received: by 2002:a63:c64b:: with SMTP id x11mr30194504pgg.202.1582163969812; Wed, 19 Feb 2020 17:59:29 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:53 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-11-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 f7a13c0374..efe9719ea4 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 This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/Makefile b/Makefile index 6bdd3b9337..bf4f3ede2a 100644 --- a/Makefile +++ b/Makefile @@ -2135,6 +2135,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 f143b9a8f8..70fb3b8fa6 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 Thu Feb 20 01:58:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393025 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 4381C930 for ; Thu, 20 Feb 2020 01:59:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23E0424656 for ; Thu, 20 Feb 2020 01:59:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="REs6pN9Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727884AbgBTB7d (ORCPT ); Wed, 19 Feb 2020 20:59:33 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:56581 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgBTB7c (ORCPT ); Wed, 19 Feb 2020 20:59:32 -0500 Received: by mail-pl1-f202.google.com with SMTP id 91so1302372plf.23 for ; Wed, 19 Feb 2020 17:59:32 -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=3mXqx2Fz+k1LmCHJaevWcnvPCIb0FxBCTtPRU/FZmQc=; b=REs6pN9ZPDj2OEhg0Xz9RbFI2m3I6YkPdtkT5qKGAwgw6aDZZvDaLMJYeXtvZHE83G BdTKvD764bnoGY2+V4kiujgFexUpZpNhWmkKs1tUrbjt0gKtbjj6WcoVJGtolpB+c3GS RC7chuMB0fuAnHHAlbVckdEaZNhxTPEBB3Tyn9nkjjsGzQeLTRL1nUW3aeumToKVypFE lmoRAmxUnNWiH2j5PSWcJaY2GEuXuXcJHMnQupUEfZF4lwmHdB8Rx4DegH0TQxggVnVc +OKiEZXT164JS+ojKBguyPl5Mqmja82cHN/nB2V1lelseJvk9wCaaMIUnXZ1ipJGXbpO vb6Q== 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=3mXqx2Fz+k1LmCHJaevWcnvPCIb0FxBCTtPRU/FZmQc=; b=nhNy6ocFE3atX664nMFOVndgYoXE/cdZaaxUm5/LW5xI+HcqpMwknvuCAP6OGVpJqC Uhe8pcUC5U5YpSPqQHd3YTWkUCW2WYjGpXFNugBUQvsxgHwNg1mIkHLZRVwx+q7Wa4IP ix1yYWPes5nBQEelpnhygpv3K50tsXbtEpRMZKl0Fi2Wt+1LlbWmjr0X4zTySzs7D9nw rYZfW3yhdKesn/W+N2Q0oBFs/X1rw2p9EQUYVdNHG059jkIYvTJEjsk5IbJDKpXhgGRB d+L70ZWTizXwc/6bwXCk5zx7TXd8NSQd1PbOyDVluinYMsRfuP69jpUh7aofkKMsFFgp uh+A== X-Gm-Message-State: APjAAAWkr8qlFllZeNmSK1Ad1TekTjDHGy8UnHAcD2XHzUD9+t1bghuD OykMnznMv0U6dfhn3fc8DBkImNzLMVQynZ+PFbSuY2RsLW0Llwp404BKL8k1lpjnadL//xhnhq2 yCvBwpmpjXCV+Ipzmf7nbbbM05fexZSt6fY+OR+aCjtItLoyj1H3iZtj7kkLGtot3Wv+mIUJl2w == X-Google-Smtp-Source: APXvYqzFTzr9D6VpaVkj1kANl16FYyT/PRapj2f8TEC6VV9VrLePdTgaRpFWqgDSwmsqhJZRfzQNZnBmov3GuBeblDY= X-Received: by 2002:a63:be48:: with SMTP id g8mr31725889pgo.23.1582163972017; Wed, 19 Feb 2020 17:59:32 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:54 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-12-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 efe9719ea4..4d01528540 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 This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 70fb3b8fa6..b5a0714a7f 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 Thu Feb 20 01:58:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393027 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 065ED159A for ; Thu, 20 Feb 2020 01:59:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAF8324656 for ; Thu, 20 Feb 2020 01:59:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Y9w/0btB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727891AbgBTB7h (ORCPT ); Wed, 19 Feb 2020 20:59:37 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:51418 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgBTB7g (ORCPT ); Wed, 19 Feb 2020 20:59:36 -0500 Received: by mail-pf1-f202.google.com with SMTP id z19so1459007pfn.18 for ; Wed, 19 Feb 2020 17:59:35 -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=VPfeplWG4b67E5JkrJSB8q2+yySZBw43O4RsqMDXlh0=; b=Y9w/0btBtWS2qgTSdCH9GPDf3aAbZKchcaxo7p7NRbKfJIVhYPjEA6NnzQ2sKTdqEQ FhO49zCyxqxRfexrSjHMwBBj0rHLOp5ZgXgsedsHV2ultSw7P+kjx1ObGjqVglD4rxkY GMz1PTdDsuwEo3UwUZhjqDzus1WYpYxAPe0nIoYR1oW66n/ZaDK4vmISoOiiTcOFq6a2 ZW9rF/MjBD2ACXbwndTJYwKdR639lzfwCaq2ozLRoqWbCHJfJsXDU1sTXhb60gzHtuvB mlxvUsDMcCjGgMOaj6r9lWp5RsYtPhhjI6SYKL4uCbZY8N39RBb8Jz1ng26GvjMEtM9B Qu/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VPfeplWG4b67E5JkrJSB8q2+yySZBw43O4RsqMDXlh0=; b=A2fYQeh0+l4udDNt8CggJ13fXkIDUGYHGFFBcdRCuyaemroo3vcLNW4aPVMCsigrtQ zYHjTfU8HlqhNTn1Ef1UYNg7BdcJWLwOQ9PvVfjIgusFAU8eCV0yU/Yq/W+aePMrZAk3 9nYwa0fWcDc5Oynb+biXKKRB+uaGXfQU9zmG5lVL1lPaExdOz3OOovcB0xd+1XYxt3N8 KLieS/SPA/dtSBjAJhjHmw125zSjejLDSaQdcciHnZrhu0tp+Iu8VMOC4cuVWm/4MMD7 chXCdM1Z183Rzon3ysZjo8TNtV0Zg6vP7qR0ruib7oGQ44DoYWzXeetdhOAPnXzjju0N G1Og== X-Gm-Message-State: APjAAAUcy5psiM1dExzR1XgrLNUHEASzjx4Td8s12vLx/rUNeofbOsyx AfnAAYSU8fG903flGAYt3jvfSF8UZc/+YL5M0XdarxPHwJ7yWbOFSvsbSq2iHWn5bgpG3c8QnDk F0VZXypSZ6OvYYo88Y0FZ+bBcnAA8dSGQgFxu8kvs060yga/cehSIU+4WmO6cGCvBC0/TZ1TrNg == X-Google-Smtp-Source: APXvYqyUwQMYBMk3/iOWanD5wecriLIeOoG15pB0gygpeWesTdUcwMGhOjZ9VTEwop43hb8TBSbU3s8N84kYpk4Qj0Q= X-Received: by 2002:a63:f80a:: with SMTP id n10mr31019942pgh.76.1582163974344; Wed, 19 Feb 2020 17:59:34 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:55 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-13-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 4d01528540..4fe1c60506 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 This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index b5a0714a7f..fb7bc72723 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 Thu Feb 20 01:58:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393029 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 51DF2159A for ; Thu, 20 Feb 2020 01:59:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30C6A21D56 for ; Thu, 20 Feb 2020 01:59:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uwMYwpZH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727896AbgBTB7i (ORCPT ); Wed, 19 Feb 2020 20:59:38 -0500 Received: from mail-pj1-f73.google.com ([209.85.216.73]:33561 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgBTB7h (ORCPT ); Wed, 19 Feb 2020 20:59:37 -0500 Received: by mail-pj1-f73.google.com with SMTP id d22so852858pjz.0 for ; Wed, 19 Feb 2020 17:59:37 -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=EsGnCNMpS+5Wytfo1sX1NIfMdMPivlv2CW66I/6jj6g=; b=uwMYwpZHfSrNYE6t8Dhv8jRrejwBafZRQd7Q2XIE1AXnQK3UK8+sQG49GbTLvZ2DU8 1e2YPsCrKPEeJrwkpJ+cidHhTGWSO6LN74lxb2yMuo/GQzK3UYfJOgJQGsnroQdhOtOT qo4CjZGnQkCctK+XAIpO9id8Sq4V/GDfOoWrtwKw5RMogu4Zs3rxDLX87HJngA5wfydu peDnY4LCtt6AS4CDSOKSp9fNjgve4Nm0DOYFJdbUIC0D5PhfBJ5pWLmQ+iYAFyi1R+5K RbMC+shO7CFlbUNNsZnD7Mo623E46Q8/1ip2tBvdwCFNSJh0OUBzWEFFr0yP0BZhfGum pkCg== 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=EsGnCNMpS+5Wytfo1sX1NIfMdMPivlv2CW66I/6jj6g=; b=YgegBzHTwyPv5F2HctXFDil+yG/XYQuXB3BwrGd4FY6gWXxO/2qgD8p1oieAeASkJO kNWlESXYyvmB0RYeWpKxIx2gbIPVMreg1BPNCtvXs+z5r4qIKbmppADYrOnFRfmPyuOx pti3Enud84dcFKrMzEunaStzIE7TaSfzzqS6f2hT4cKI15JXUk0plU0C2t08FKUSuuzD gtfOgkCu7iTML5lKapk2DXfWvx/j17G53XhW6zLcC5+NyrSY3yC68cmPYiASY7ZsA/cK XbOL+3m+eGVM9cSc5nSWoSsw8dX95N8j9AyK2qssPITFzHBNnPAQ/jV051gdyuGoW2nh F3xQ== X-Gm-Message-State: APjAAAWG6eCNClJs6xWzc0lLFgof4C/dtuBCVqGgiX55xUuqQom8d2+J gKQrhLgVajzaYHo0tk/VjJi/Q66nERcRnthagunm3EQXoxbZXgBkWDV0Lp9flOaAdVpOXTjilML wArdihbknb44AbVwbDCwr2RQHixmVUMe2nZHAcmq+pjS4RAZytbwtujZMJyKI6E9oMC/MR/tPYA == X-Google-Smtp-Source: APXvYqwV2cSI1RKNyFuy/P7aKWhohBn3AkdnMaKFO3CguNuZ3lzq2RtPTmvDXoYEI6nwEfCJgJ1hEjkT/sr2EbC6qCw= X-Received: by 2002:a63:f648:: with SMTP id u8mr31074131pgj.148.1582163976920; Wed, 19 Feb 2020 17:59:36 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:56 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-14-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 4fe1c60506..eb41f0677f 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 This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index fb7bc72723..71191f1331 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 5b047637e3..f881a1756e 100644 --- a/object-store.h +++ b/object-store.h @@ -7,6 +7,7 @@ #include "sha1-array.h" #include "strbuf.h" #include "thread-utils.h" +#include "packfile.h" struct object_directory { struct object_directory *next; @@ -447,4 +448,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 99dd1a7d09..95afcc1187 100644 --- a/packfile.c +++ b/packfile.c @@ -2095,8 +2095,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 Thu Feb 20 01:58:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393031 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 73731930 for ; Thu, 20 Feb 2020 01:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54CE624672 for ; Thu, 20 Feb 2020 01:59:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pT/+aId0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727901AbgBTB7k (ORCPT ); Wed, 19 Feb 2020 20:59:40 -0500 Received: from mail-pj1-f74.google.com ([209.85.216.74]:33562 "EHLO mail-pj1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgBTB7k (ORCPT ); Wed, 19 Feb 2020 20:59:40 -0500 Received: by mail-pj1-f74.google.com with SMTP id d22so852902pjz.0 for ; Wed, 19 Feb 2020 17:59:39 -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=mpqrT5Qze+Us8UpdFpAGMe7m+uwP4gL7uh1F2yOvy9Q=; b=pT/+aId0VitvzAcbFUIrSNj6tynk+EQb0WvJZECaWj1icc/4n3rp+sGEudba0Akwao mOEHU42C8cZ9iR6wtJPzn3+vJtfTEpWWwN3hVSrF4zwXUKLwxNwuHKw3wNm72sMIy06Q oCi3xPdeYDpmuPISVA3mz8cJk+trCUT0T0DcAFy7rudwzq0PviMvQXrUTtvtn/S9pnmN ++z5rE33Ud4gya4ENIeLq/fPiFX6I0HjPLVNK9jtJoTv4QZGJwgHEBDCVKy8twrcwcJz EN8wroY50NAKdFipoFd5vSEocMJgCmfwF96RgRBsEGNRUlSc3+tZXeW5HhEI4gBO4IG0 T39g== 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=mpqrT5Qze+Us8UpdFpAGMe7m+uwP4gL7uh1F2yOvy9Q=; b=DN+w2tRcNKg0589db4mCbLeAe++BK61VezcQWSMsWD9DR4NrFOH29Q3W4POiiPyRKA IIx8wlAL/Mum47e72SOEQlKFgrQQmH5c4ZeELLcu0/NgwOJagd9vHxFARB4XkTvTB+Sl rzWA26OIvO91LhqUU+r5aUqMhc5P6XXNz3zZXOywc4UC3nwsVXG7vA+HSmW6isSl+gq9 VHMxlc1HnFUb1re6LX3l4kx++wBohhJ2JEeo5fkpL0Yckxkm2cmJ91ORiDtmwELujCX4 +wdK0Mm5SDq3rVuArHi57lOWkqEG+kZVbhfo6IeJmfA4YkYXFbz7K6LFf9vLLJbyq9VH 1xOg== X-Gm-Message-State: APjAAAXxRp6epT0hSmhpNlhPvfRA1yquVr3wH8QlkPcv9u+lO1CjrYcd tfIdyhvrwpdinuWiusPJd9BEOMrz+yOtnCuxkL5+X1pshvPoMYMvt5+75DYBSxjU22rHVslQb+d Q9YmRj6PUTj9r8Wj/Bh8su7aMWBzT7+1Tio7tStXi9ZUYPFg5GivZppsnfIdBuJaE5X0n0vQLgg == X-Google-Smtp-Source: APXvYqxMr6OZ9K2Qq/170Z41TwUSi4HncLpN7dZwOlwT5fIUb4g7JMJZmzizKDSr/faLw6O9JnWql9KXjwSLzNExy8s= X-Received: by 2002:a63:c401:: with SMTP id h1mr32026555pgd.262.1582163979125; Wed, 19 Feb 2020 17:59:39 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:57 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-15-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 eb41f0677f..a7ef3360d2 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) This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 71191f1331..1d61e0f642 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 Thu Feb 20 01:58:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11393033 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 0E855159A for ; Thu, 20 Feb 2020 01:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2A0D24672 for ; Thu, 20 Feb 2020 01:59:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dPtSAl7s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbgBTB7o (ORCPT ); Wed, 19 Feb 2020 20:59:44 -0500 Received: from mail-pg1-f201.google.com ([209.85.215.201]:52090 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgBTB7n (ORCPT ); Wed, 19 Feb 2020 20:59:43 -0500 Received: by mail-pg1-f201.google.com with SMTP id m18so1299453pgn.18 for ; Wed, 19 Feb 2020 17:59:42 -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=bXqNk8D8gZgU3IlplvuXY/GcpAoadbhrrvLlMeGwTUs=; b=dPtSAl7sIGuHnF9+7mH22yd/UsyKU+c+GEFuSU4dBagLY+Uu2eKYGVIm/NvjyD5QLA Ri9KADoPk2hJM+vKnT74q583FIExFeOmhM8it0c2bimZY+l2mgYfkbqI5Iul8X8dCt6T U7OlrqiSJjyMfQoFYZE3wWqMPQk/EP53AwrX6yGnwD+v401VvZo0M6vPZ3YJJHaW19r+ wjUXvhml+vQeFY8YoldDdrZDntnJXUTPo0UHMZpMfcLRLzGmlYnOOvi7mnghAoViKA+g iWMxQqs6AUlRaFsBpMmWbhV8z3QdlYBI/zhplKq9SnpYgfpXdXMPKlN4cDRz8tp+waxC FLcg== 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=bXqNk8D8gZgU3IlplvuXY/GcpAoadbhrrvLlMeGwTUs=; b=aSKSHLSoLfSRUqxbyjNhq17fgC96JBS6y04ufn5HzyfNW0eC93GJl8b+ynOIWrq8Gw t4YgWXJrPf2wpRXI+UYROf1n8x3NAZNGJOoGgLpUXdJT8PEZ8WxrSmgYX8g5TWUstLGN rrvZ7bQ4DduUJhGR1BFF31wzbJgwykmHyF43xrKM/gmcOrVC+bwuU7jqv6iTUQc7KqTV q50ptLQu1S/w/5uqePcynx4BhOZeLrWsDAcy7JTHK0fAwvxh8sXkZ3MuTqXzPxiVZNKO G8mBp6HLfe1mRrZ7R6p2goj8t7yBB700D+bYEeVXc7FFc5GIxN69iO5OJLSSAHRkDncH jUow== X-Gm-Message-State: APjAAAUmijwUoNkTKHQYI0isTwkI6kYyXXC0vrWPCBEQJ5v2mCIEmonu LzHGZSd9KW/y0enOXDN6DQ4HvDW2OZN9Kd8FKN60jEpblSZs6qJZkRfNJrZkNkdDkamzd6a+Oll d2sstAGGE/wB1RH9eFWIamSiivqg7UQO3OmNfXBEShnFe+wGwqVyEs5omcsxASnz25gmWJX5svQ == X-Google-Smtp-Source: APXvYqyChv3wxYlhQYboFImgQUTHyLYYXWleLM6O8UZQZg9hq3IOAVCUeDJCUf2bpx9rEGIaCERFx24xxSwB6cXPJR4= X-Received: by 2002:a63:8f59:: with SMTP id r25mr31921729pgn.280.1582163981393; Wed, 19 Feb 2020 17:59:41 -0800 (PST) Date: Wed, 19 Feb 2020 17:58:58 -0800 In-Reply-To: <20200220015858.181086-1-emilyshaffer@google.com> Message-Id: <20200220015858.181086-16-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200220015858.181086-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 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 a7ef3360d2..1f60fb9456 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 This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file diff --git a/bugreport.c b/bugreport.c index 1d61e0f642..1640a71086 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) {