From patchwork Thu Feb 6 00:40: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: 11367397 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 4612C14D5 for ; Thu, 6 Feb 2020 00:41:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FFBC2082E for ; Thu, 6 Feb 2020 00:41:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YyYHxjGg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727562AbgBFAl0 (ORCPT ); Wed, 5 Feb 2020 19:41:26 -0500 Received: from mail-qk1-f202.google.com ([209.85.222.202]:37882 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727149AbgBFAlZ (ORCPT ); Wed, 5 Feb 2020 19:41:25 -0500 Received: by mail-qk1-f202.google.com with SMTP id v2so2510972qkf.4 for ; Wed, 05 Feb 2020 16:41:24 -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=r9z2zrD8IAwV9AGxjem868vIIposGGhQU1vZPzJpyAs=; b=YyYHxjGg2Hyq2JVRBkHjaDPB5HWUdwDaOMjP8Zq6IcFVpcT6BT8lfjR4A4r+SePORt oT8wB1gjDGcNiJgrkXQx+6RUXlMh0Kpd0xvVYOyarlheGx1abb2v2JMJ8yavUIbaDf4N poQp75BMs4s634XcAZSGTylzKKIDQlId0QFaxVMB4JaxETmIdpafutKEhehl9zHxqaF1 qD92oLhv/Vbb7XbOdXWgEgWyRUbrRSNOUKiB6OnSlcM4sVKmpOwc5fQBX0jnunyBieG9 KgAiGo3fx3Tv9EiYiFUBjtPnurUzKFIj13SB8MlIwv6+d/TN85bnT+/IwxqIKgsXOOjU Briw== 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=r9z2zrD8IAwV9AGxjem868vIIposGGhQU1vZPzJpyAs=; b=hyBeXCu63XOjOKeWT8WH20yg56qc0vst+QAjvkuD6aVmQ2ja2uhka3oB640DM4ljWs rp5oHdCtQ9npd3cQ1HnC+0P/8bDNmaeFFup+rYtE2amXFfkhX43tWy5ojXG1tuS6RyWG gSC4kiQSNi8oAqjU48zYkAGqnNI6bWbNs/CQfbQzA82FaADUe9i7GME9Pdll4f9FZ8DP TBcZZPhc1FghNIj77z2LK3nQoxPOR45eJ4iLOL6NTrNVbDSuivpaiIz1kDttrgxZJ+f2 d9LO3c6D3cyL9ZGVrFWXO3vdV/VP7sbZgRG8WnC1ve9uFHSWfmHmjtg6xAjRBrXxeEek 5KBw== X-Gm-Message-State: APjAAAXpDJr86/DpnyJXZFnOGwTZ1nMxRn+cp5dKUu+uaMZOqloB7hXS 2iropwNC9DBWJETQTjCvn/W5FkIQNb8d8gJWPVv3DsBowAG9tVtT+As2o+w9IEzvXIilBzmlG6v NLc8WmkNqrWaq1/XjpfmpiaRKM1JRGlKOnPsSE6d4VMZIGwI7As53gloiv+VQPRU3z8OA9cyIQQ == X-Google-Smtp-Source: APXvYqyZDyJVVPOjlPu0ZqLRr6mcFfXL2LUjCD0GeZVlC0SEq4BUbfnjgABPb90glUYFg/VDYnViSYOOZFYcz2Zf5Fg= X-Received: by 2002:a0c:f98a:: with SMTP id t10mr325342qvn.144.1580949683883; Wed, 05 Feb 2020 16:41:23 -0800 (PST) Date: Wed, 5 Feb 2020 16:40:54 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 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 | 24 ++++++++++++ help.c | 85 ----------------------------------------- help.h | 1 - 7 files changed, 121 insertions(+), 108 deletions(-) create mode 100755 generate-configlist.sh diff --git a/.gitignore b/.gitignore index aebe7c0908..ea97de83f3 100644 --- a/.gitignore +++ b/.gitignore @@ -189,6 +189,7 @@ /gitweb/gitweb.cgi /gitweb/static/gitweb.js /gitweb/static/gitweb.min.* +/config-list.h /command-list.h *.tar.gz *.dsc diff --git a/Makefile b/Makefile index 09f98b777c..5a022367d4 100644 --- a/Makefile +++ b/Makefile @@ -814,6 +814,7 @@ LIB_FILE = libgit.a XDIFF_LIB = xdiff/lib.a VCSSVN_LIB = vcs-svn/lib.a +GENERATED_H += config-list.h GENERATED_H += command-list.h LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ @@ -2128,7 +2129,7 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h -builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX +builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ @@ -2148,6 +2149,12 @@ $(BUILT_INS): git$X ln -s $< $@ 2>/dev/null || \ cp $< $@ +config-list.h: generate-configlist.sh + +config-list.h: + $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \ + >$@+ && mv $@+ $@ + command-list.h: generate-cmdlist.sh command-list.txt command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt @@ -2781,7 +2788,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE .PHONY: sparse $(SP_OBJ) sparse: $(SP_OBJ) -EXCEPT_HDRS := command-list.h unicode-width.h compat/% xdiff/% +EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/% ifndef GCRYPT_SHA256 EXCEPT_HDRS += sha256/gcrypt.h endif @@ -2803,7 +2810,7 @@ hdr-check: $(HCO) style: git clang-format --style file --diff --extensions c,h -check: command-list.h +check: config-list.h command-list.h @if sparse; \ then \ echo >&2 "Use 'make sparse' instead"; \ diff --git a/builtin/help.c b/builtin/help.c index e5590d7787..1c5f2b9255 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -8,6 +8,7 @@ #include "parse-options.h" #include "run-command.h" #include "column.h" +#include "config-list.h" #include "help.h" #include "alias.h" @@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = { NULL }; +struct slot_expansion { + const char *prefix; + const char *placeholder; + void (*fn)(struct string_list *list, const char *prefix); + int found; +}; + +static void list_config_help(int for_human) +{ + struct slot_expansion slot_expansions[] = { + { "advice", "*", list_config_advices }, + { "color.branch", "", list_config_color_branch_slots }, + { "color.decorate", "", list_config_color_decorate_slots }, + { "color.diff", "", list_config_color_diff_slots }, + { "color.grep", "", list_config_color_grep_slots }, + { "color.interactive", "", list_config_color_interactive_slots }, + { "color.remote", "", list_config_color_sideband_slots }, + { "color.status", "", list_config_color_status_slots }, + { "fsck", "", list_config_fsck_msg_ids }, + { "receive.fsck", "", list_config_fsck_msg_ids }, + { NULL, NULL, NULL } + }; + const char **p; + struct slot_expansion *e; + struct string_list keys = STRING_LIST_INIT_DUP; + int i; + + for (p = config_name_list; *p; p++) { + const char *var = *p; + struct strbuf sb = STRBUF_INIT; + + for (e = slot_expansions; e->prefix; e++) { + + strbuf_reset(&sb); + strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); + if (!strcasecmp(var, sb.buf)) { + e->fn(&keys, e->prefix); + e->found++; + break; + } + } + strbuf_release(&sb); + if (!e->prefix) + string_list_append(&keys, var); + } + + for (e = slot_expansions; e->prefix; e++) + if (!e->found) + BUG("slot_expansion %s.%s is not used", + e->prefix, e->placeholder); + + string_list_sort(&keys); + for (i = 0; i < keys.nr; i++) { + const char *var = keys.items[i].string; + const char *wildcard, *tag, *cut; + + if (for_human) { + puts(var); + continue; + } + + wildcard = strchr(var, '*'); + tag = strchr(var, '<'); + + if (!wildcard && !tag) { + puts(var); + continue; + } + + if (wildcard && !tag) + cut = wildcard; + else if (!wildcard && tag) + cut = tag; + else + cut = wildcard < tag ? wildcard : tag; + + /* + * We may produce duplicates, but that's up to + * git-completion.bash to handle + */ + printf("%.*s\n", (int)(cut - var), var); + } + string_list_clear(&keys, 0); +} + static enum help_format parse_help_format(const char *format) { if (!strcmp(format, "man")) diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index 71158f7d8b..45fecf8bdf 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -76,23 +76,6 @@ print_command_list () { echo "};" } -print_config_list () { - cat <", list_config_color_branch_slots }, - { "color.decorate", "", list_config_color_decorate_slots }, - { "color.diff", "", list_config_color_diff_slots }, - { "color.grep", "", list_config_color_grep_slots }, - { "color.interactive", "", list_config_color_interactive_slots }, - { "color.remote", "", list_config_color_sideband_slots }, - { "color.status", "", list_config_color_status_slots }, - { "fsck", "", list_config_fsck_msg_ids }, - { "receive.fsck", "", list_config_fsck_msg_ids }, - { NULL, NULL, NULL } - }; - const char **p; - struct slot_expansion *e; - struct string_list keys = STRING_LIST_INIT_DUP; - int i; - - for (p = config_name_list; *p; p++) { - const char *var = *p; - struct strbuf sb = STRBUF_INIT; - - for (e = slot_expansions; e->prefix; e++) { - - strbuf_reset(&sb); - strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder); - if (!strcasecmp(var, sb.buf)) { - e->fn(&keys, e->prefix); - e->found++; - break; - } - } - strbuf_release(&sb); - if (!e->prefix) - string_list_append(&keys, var); - } - - for (e = slot_expansions; e->prefix; e++) - if (!e->found) - BUG("slot_expansion %s.%s is not used", - e->prefix, e->placeholder); - - string_list_sort(&keys); - for (i = 0; i < keys.nr; i++) { - const char *var = keys.items[i].string; - const char *wildcard, *tag, *cut; - - if (for_human) { - puts(var); - continue; - } - - wildcard = strchr(var, '*'); - tag = strchr(var, '<'); - - if (!wildcard && !tag) { - puts(var); - continue; - } - - if (wildcard && !tag) - cut = wildcard; - else if (!wildcard && tag) - cut = tag; - else - cut = wildcard < tag ? wildcard : tag; - - /* - * We may produce duplicates, but that's up to - * git-completion.bash to handle - */ - printf("%.*s\n", (int)(cut - var), var); - } - string_list_clear(&keys, 0); -} - static int get_alias(const char *var, const char *value, void *data) { struct string_list *list = data; diff --git a/help.h b/help.h index 7a455beeb7..9071894e8c 100644 --- a/help.h +++ b/help.h @@ -22,7 +22,6 @@ static inline void mput_char(char c, unsigned int num) void list_common_cmds_help(void); void list_all_cmds_help(void); void list_common_guides_help(void); -void list_config_help(int for_human); void list_all_main_cmds(struct string_list *list); void list_all_other_cmds(struct string_list *list); From patchwork Thu Feb 6 00:40: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: 11367399 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 E488B139A for ; Thu, 6 Feb 2020 00:41:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFB442082E for ; Thu, 6 Feb 2020 00:41:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cFfJehmE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727550AbgBFAl3 (ORCPT ); Wed, 5 Feb 2020 19:41:29 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:36687 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgBFAl2 (ORCPT ); Wed, 5 Feb 2020 19:41:28 -0500 Received: by mail-pf1-f202.google.com with SMTP id 6so2689368pfv.3 for ; Wed, 05 Feb 2020 16:41:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LQKyEVtppS6PEntYcg7p2r4j5sdNP7kaZlvApuidwPQ=; b=cFfJehmEBXAo01ocNZjmwvXQV5jMil/FA7IsCOzqeOWX7YwiR+GnJGOKJCQydoFtB6 ACAu870XZOqQlrPbzhBAEzo2Jb683OhYhmGcyWikP78sAYx8+Q26B/IjL4TbPZdERhIf nwFFPRh/J9KvEdp8PZVmI+Nm0KJ18S6FR39wvM0V5q4uO8CwbfE58Cy7ZeG8bkTeXj4u IzC0Pn0BIo+4w6sgC9jaH7JednCsfYXR7aWXrTClcwJw3kI4Y9WOIuMm0RCKqLw1NP5R 6DqpSty1KWPkcdx31mwSWfwbHMItByBTt9kCASgHxqd1ZsbgXbshnvTusElSXCZ4pSZ0 Qi/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=LQKyEVtppS6PEntYcg7p2r4j5sdNP7kaZlvApuidwPQ=; b=Pi1C3X2l4d3X5Ur5DkeKIuEgqmWsXAhRKMtxwUMjPs4Hl0dIhtk75roWov69/Yl/D4 eUfhYE/7mDT9kZmUz6DDUo21YePyjGuIF4EusuwIviyTuIQjG/To2e2MWj8NBbygrD0x FcHYrnBpRT1nhxvfh63/Vw0Cl0QaaESJ7/yk0YJK/ViZhwBDUbcOLLlCGg50yhDt1Zpt 1ikAfDTc3YH9/ZlX4kQ3vR8tWD6iPoQWq+raAd/L7kJpgTSjOcyKaB6L9oJ9dawf8kvB J2+tBBZVUK2qOWcw3JMJAGMeq6oY5eLF6+SqV72uDj40BoZr+VTu2T5dNLUAFAdvT6cf pF/Q== X-Gm-Message-State: APjAAAVfDgTVvx8MyPOds2jhmkRNYTvRzyXwZw9loMV+6nTxDapzo8ov 9uVYw9BJuYkUTIXYguz4VSN1yBRXYJDiwwC7o2Pz1Tm6JVXuPi6zbZHbBbzUMdAuiGzFmqxTfms 9V++6FJ5bvoMoUzVhMh24Q5DsUbBJ0FZy7yhc2isRxgTWpq5CsSTQ8VD49BLP1I1UGdbuK8kG3w == X-Google-Smtp-Source: APXvYqzNM+hqNXj1scCvuzUFB0izXQvGYmuJkwDfSgZUfAQJyMFxR7TG2WspP6IDx9yMYb9AP8F5JT/bUcujcapgoY8= X-Received: by 2002:a63:e64d:: with SMTP id p13mr645333pgj.121.1580949686415; Wed, 05 Feb 2020 16:41:26 -0800 (PST) Date: Wed, 5 Feb 2020 16:40:55 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 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 6 00:40: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: 11367403 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 1111114B4 for ; Thu, 6 Feb 2020 00:41:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D340221775 for ; Thu, 6 Feb 2020 00:41:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OL9IuFPV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727578AbgBFAlc (ORCPT ); Wed, 5 Feb 2020 19:41:32 -0500 Received: from mail-pj1-f73.google.com ([209.85.216.73]:42257 "EHLO mail-pj1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727577AbgBFAl3 (ORCPT ); Wed, 5 Feb 2020 19:41:29 -0500 Received: by mail-pj1-f73.google.com with SMTP id hi12so2285397pjb.7 for ; Wed, 05 Feb 2020 16:41:29 -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=0SxoWHucftRH/KPOoSORrHecC74+RUfZbQilCzLwPQU=; b=OL9IuFPVYZB2S+C6YlgMU9556kwIMDASAl5trqAfFUwQ7gEFXG3Y81E82Llr4GGkBL DUYkh3U7pP/B3+V8j33XrdSrLWafY3HWKe4qYExlqC3MkxgwLAQvhKbbkGYP8YwvMjfL VFX3X54c0g7YFhtdOw7gF+HBKa4i9Im2Duv0xQCBlgWITFx7TZWGxw6jWc4ZM1+39iLf g6FKPA35LXTRdc8C09qucYLiehx8eiv49n8W7iZpbA8n+wYfrVgdcqV8U9lcDvdBIK+O ZcevEK91M5FPuAk/ZGuhH9hf+dQZMOH5Q+DVTsMTdcZFU1vEcD+PDUPMHtcn8FiF4XJy ds0w== 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=0SxoWHucftRH/KPOoSORrHecC74+RUfZbQilCzLwPQU=; b=Wgdkx+sbunVhtm33mIzrn4N3kE4BErtyoWWEYDIEkPJruUGKbBFOKoaJFF/OgojOp0 d3vWmfRMyTJa8G3P5QxegYwty6Hul1CpSubJZxwpJTI5aLyuCuY1lqy0bUiaSgxxUdbo qDO8jIJxefG6KM1zGKsPxS0INa2agtv245qb7Q/2u6CHPnwGB68ZtD3UqnPWXeFvUNXY fd34o/oNKDAZiPelkNfJ3Q+f++uuWwAhYVxYjFFE0hWUUXUfnYZCw+obthNyEBEPpHPv 3Y0opiEE00LXauwRsxL0XglDYeeTYMOuZQ9bcmd/ltC1oG0MKC549k+Pm9o9BycMVQS9 WR3Q== X-Gm-Message-State: APjAAAVGGwTh0D1GjbQ+aNQfj7nOA6yUjalqgIuX9ofhHpUqw4S35KNS RO0Q23rS/QTLhd08gY65tAG0/6JF+iaRnlQt6wgFjbqvuqCrcuEsQMxuuyX/aRmyY9Zvso47oci pFJ3bNcTYo2Sml+e5xLDFPIpFvwTNunhcC6TrthO5xnzlzc4b4A5SZUNyLd6QahA/woiDfd40pg == X-Google-Smtp-Source: APXvYqxG+5hi8G0uY37f70PC0+xupZVNZ1GiGF0zqkFg//q1oAtFYEVxvU/d0+fHHStAWNmBJfFWxuWa6ZMCbWBRcS0= X-Received: by 2002:a63:447:: with SMTP id 68mr618575pge.97.1580949688964; Wed, 05 Feb 2020 16:41:28 -0800 (PST) Date: Wed, 5 Feb 2020 16:40:56 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 03/15] bugreport: add tool to generate debugging info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach Git how to prompt the user for a good bug report: reproduction steps, expected behavior, and actual behavior. Later, Git can learn how to collect some diagnostic information from the repository. If users can send us a well-written bug report which contains diagnostic information we would otherwise need to ask the user for, we can reduce the number of question-and-answer round trips between the reporter and the Git contributor. Users may also wish to send a report like this to their local "Git expert" if they have put their repository into a state they are confused by. Signed-off-by: Emily Shaffer --- .gitignore | 1 + Documentation/git-bugreport.txt | 41 ++++++++++++++++ Makefile | 5 ++ bugreport.c | 85 +++++++++++++++++++++++++++++++++ t/t0091-bugreport.sh | 49 +++++++++++++++++++ 5 files changed, 181 insertions(+) create mode 100644 Documentation/git-bugreport.txt create mode 100644 bugreport.c create mode 100755 t/t0091-bugreport.sh diff --git a/.gitignore b/.gitignore index ea97de83f3..d89bf9e11e 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ /git-bisect--helper /git-blame /git-branch +/git-bugreport /git-bundle /git-cat-file /git-check-attr diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt new file mode 100644 index 0000000000..52d49ed7aa --- /dev/null +++ b/Documentation/git-bugreport.txt @@ -0,0 +1,41 @@ +git-bugreport(1) +================ + +NAME +---- +git-bugreport - Collect information for user to file a bug report + +SYNOPSIS +-------- +[verse] +'git bugreport' [(-o | --output-directory) ] [(-s | --suffix) ] + +DESCRIPTION +----------- +Captures information about the user's machine, Git client, and repository state, +as well as a form requesting information about the behavior the user observed, +into a single text file which the user can then share, for example to the Git +mailing list, in order to report an observed bug. + +The following information is requested from the user: + + - Reproduction steps + - Expected behavior + - Actual behavior + +OPTIONS +------- +-o :: +--output-directory :: + Place the resulting bug report file in `` instead of the root of + the Git repository. + +-s :: +--suffix :: + Specify an alternate suffix for the bugreport name, to create a file + named 'git-bugreport-'. This should take the form of a + link:strftime[3] format string; the current local time will be used. + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Makefile b/Makefile index 5a022367d4..a01a050aa3 100644 --- a/Makefile +++ b/Makefile @@ -681,6 +681,7 @@ EXTRA_PROGRAMS = # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS += $(EXTRA_PROGRAMS) +PROGRAM_OBJS += bugreport.o PROGRAM_OBJS += credential-store.o PROGRAM_OBJS += daemon.o PROGRAM_OBJS += fast-import.o @@ -2457,6 +2458,10 @@ endif git-%$X: %.o GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +git-bugreport$X: bugreport.o GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(LIBS) + git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(IMAP_SEND_LDFLAGS) $(LIBS) diff --git a/bugreport.c b/bugreport.c new file mode 100644 index 0000000000..db46fb88be --- /dev/null +++ b/bugreport.c @@ -0,0 +1,85 @@ +#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); + + 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/t/t0091-bugreport.sh b/t/t0091-bugreport.sh new file mode 100755 index 0000000000..451badff0c --- /dev/null +++ b/t/t0091-bugreport.sh @@ -0,0 +1,49 @@ +#!/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 && + REPORT="$(ls git-bugreport-*)" && + check_all_headers_populated <$REPORT && + rm $REPORT +' + +test_expect_success 'dies if file with same name as report already exists' ' + touch git-bugreport-duplicate.txt && + test_must_fail git bugreport --suffix duplicate && + rm git-bugreport-duplicate.txt +' + +test_expect_success '--output-directory puts the report in the provided dir' ' + mkdir foo/ && + git bugreport -o foo/ && + test_path_is_file foo/git-bugreport-* && + rm -fr foo/ +' + +test_expect_success 'incorrect arguments abort with usage' ' + test_must_fail git bugreport --false 2>output && + grep usage output && + test_path_is_missing git-bugreport-* +' + +test_done From patchwork Thu Feb 6 00:40: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: 11367405 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 401EA14B4 for ; Thu, 6 Feb 2020 00:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 149BD217BA for ; Thu, 6 Feb 2020 00:41:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tfFXxZNE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbgBFAld (ORCPT ); Wed, 5 Feb 2020 19:41:33 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:50671 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbgBFAlc (ORCPT ); Wed, 5 Feb 2020 19:41:32 -0500 Received: by mail-pl1-f201.google.com with SMTP id g5so2137997plq.17 for ; Wed, 05 Feb 2020 16:41: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=CQZ2Bvrq0TpsF/pxowKghBdFuTljBZeQYUnQLxdO4bo=; b=tfFXxZNEXCzBuIU70U/9HjpbRMRcs0ni2Ta/QoH187BHOuWZW+xhANL4KU6lkcVVwm 5xQzDt3Pay8uDsjMsM+Ddnhn/elg04+yYOUyyM5gW4djpkDEvF0tT/sv0Wudz3r0DIFb NirV12+Wk97zM0yyP62OqGdMDRFCt6JWjWS2BUyVghkM7PAXXxXhxARpzzBz/ecGTQIx jZC1zjcsgf9pYXCxRPskVk4036EFvHtnzt8bO6wssvKfMHbB7avsnkIxH4FEu5OHEE2k mUYsV7nTKwfsiv6kvlbfKLPGSYkZXbqyb1nT1WRoeemwpxgS3jW+PbUdxWcY6qrnSoJS 9cfw== 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=CQZ2Bvrq0TpsF/pxowKghBdFuTljBZeQYUnQLxdO4bo=; b=e7ndFaB1WyfoldRE9gSH9IPq43DaaK+7TYfUjspwkx7Tf2vr0cVtV7GLL1frsmlm8q lUx+dbEGpFWO9UQXd8aq01Ismru0QogzhHXytJHJdQ+y/MnbmhLplmU16h0guOi/JdEh pxyoahloBLMkrESZ/72DE/cxXUFMKAzztxNILSr87/fQ7IGLfQFLAX7BmrzvgSfiE8Cr FprjRMfkC2iGiKW1r9U2/MqCHKycKjX6bLIgIC12Q4JT/I9WsTKYx7CTNv+L7gW0nWVj DWW1I/z1MWJyn361arQ7YEsuLwDUYqxJgR1GQkf+FiAEQDhf/oyb8C0MdHMRT+65vDvy R27w== X-Gm-Message-State: APjAAAXUSX9K5xcWwdiowqLvE2l2Y8zbxsFfSXFuz4JoUMVPn76aH21D 80Odqj8y7czBc9DcCjumUu+CXAR4yrNMXcxzM6b1DAzblwfXUP+NfKfA2rLDjlSdRQrGKWJgmTM ZHo46QKTa+ynhRoXVuvpOsicBSIZTvz2BgcTkqZCRLa3J67j71ga46cSAFh+r4liAL9UPM1eUPA == X-Google-Smtp-Source: APXvYqzsUoEcKlWoTjCqEwNMsPFh2krMZqUlZzTTYDk5FIhHyQgU3crIlwmJdcDYj6J79KxR3WcIaivVHlqq6MdU0D8= X-Received: by 2002:a65:68ce:: with SMTP id k14mr638634pgt.336.1580949691425; Wed, 05 Feb 2020 16:41:31 -0800 (PST) Date: Wed, 5 Feb 2020 16:40:57 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 04/15] bugreport: gather git version and build info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Knowing which version of Git a user has and how it was built allows us to more precisely pin down the circumstances when a certain issue occurs, so teach bugreport how to tell us the same output as 'git version --build-options'. It's not ideal to directly call 'git version --build-options' because that output goes to stdout. Instead, wrap the version string in a helper within help.[ch] library, and call that helper from within the bugreport library. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 4 +++ bugreport.c | 19 ++++++++++++- help.c | 48 ++++++++++++++++++++------------- help.h | 1 + 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 52d49ed7aa..6ce2ae2eff 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -23,6 +23,10 @@ The following information is requested from the user: - Expected behavior - Actual behavior +The following information is captured automatically: + + - 'git version --build-options' + OPTIONS ------- -o :: diff --git a/bugreport.c b/bugreport.c index db46fb88be..dd21be9d68 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; @@ -67,6 +81,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 6 00:40: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: 11367407 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 E402D139A for ; Thu, 6 Feb 2020 00:41:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C2E3521775 for ; Thu, 6 Feb 2020 00:41:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OolPfQPs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727588AbgBFAlf (ORCPT ); Wed, 5 Feb 2020 19:41:35 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:33954 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727307AbgBFAlf (ORCPT ); Wed, 5 Feb 2020 19:41:35 -0500 Received: by mail-pl1-f201.google.com with SMTP id j8so2171553plk.1 for ; Wed, 05 Feb 2020 16:41:34 -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=nJNkj4A/VbaQrOpNCNLsBz3dJqXhe+B0PfpbB72FC2U=; b=OolPfQPs5R4WNnd4lnXvbSE1NifGMFaAr1cqQkckM8sQqOQZXiRypx4vJ2/98LD6MU GK4Q7Wx18Z2Uoy0lKM9SYQl+ywOeaHo7hH7ziqLu1TbXEZAbM3T8OfxIiaEZTEeOKhnr 2FVxOQO9Kjdjjk9qHFnWIFzOIctUBqu88CcGxA8gHP7T+6ig3nKAt4PISvHxsPGaOyWm 890nfw0fMakbEHsEPIq7uhePdn138rV2XSPQSJB0ZpK2kRNWY5C5noTH5EgAKvQjhTAp lIgZ0uXa3GbViOSzSbVw3D2/X6ktyIZp+uyLT+pXCi9zAlxIF5+u+DJJaoZTI0gcDtzq 8o4A== 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=nJNkj4A/VbaQrOpNCNLsBz3dJqXhe+B0PfpbB72FC2U=; b=f5+U1b7roN21d+Zun+uxyuwAh2zkr1pUq0M4OS53viANgn/Oj1gYKVBAhQ0S45Zdi2 9zDyYtqFDZn9dmzpqAghHMnRQ6dLqnl7lRWXqkKMiWPahDXNEHJdhUUHWj3oXtwmVsQm q0VSHrabHzSTMHPHuOWMXk9/FRXjHIRPtifafqL6Od5A1nKWp/sGPjMDoLhVXhUd1CE0 XiLaE0cCgIGCcsV8TnhKTkT9Nj7O7wSEswh24bIhHCEO/OSaKxF/XC5/tB1uTq4lsZJJ lLjFkGNH9mlL5z1m72kGtm98HHWg0MF3wIrZ9JKOznPTFBcVnog/AgikQaRR0tBzHjgI T3Jg== X-Gm-Message-State: APjAAAWGQljPnZaAa/OxJ7A9xByolCeAhX/TXyyaNztFV2T+vWE+4U5q Zy+wcY49KhjaGn4oFyvjBvpeQoR83ya0rFKPC7UXBly05zIYSB69SAUM77a6fMA4ofTkPXVTv2q wy7lDryJfiBeaQrXirGY4sWF7nELPdt2Ax9a/HBNFlG94EV7dhOk/pMa1kZDlRfytpPSPt6IOMQ == X-Google-Smtp-Source: APXvYqw7WaWCGymzfv8ep2tH7G0zfEwG2qrKfNv9r3ZC9GfmMF0MbkVXsDAoyGphmhfyEzHaT64wsyZuExRKn5ldP6E= X-Received: by 2002:a63:7a0f:: with SMTP id v15mr629063pgc.139.1580949694024; Wed, 05 Feb 2020 16:41:34 -0800 (PST) Date: Wed, 5 Feb 2020 16:40:58 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 05/15] bugreport: add uname info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The contents of uname() can give us some insight into what sort of system the user is running on, and help us replicate their setup if need be. The domainname field is not guaranteed to be available, so don't collect it. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 6ce2ae2eff..4dd72c60f5 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -26,6 +26,7 @@ The following information is requested from the user: The following information is captured automatically: - 'git version --build-options' + - uname sysname, release, version, and machine strings OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index dd21be9d68..4c4b877ea1 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 6 00:40:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367409 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 E8068139A for ; Thu, 6 Feb 2020 00:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7602217BA for ; Thu, 6 Feb 2020 00:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jIIeqdI7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727591AbgBFAlj (ORCPT ); Wed, 5 Feb 2020 19:41:39 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:38728 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727307AbgBFAli (ORCPT ); Wed, 5 Feb 2020 19:41:38 -0500 Received: by mail-pl1-f202.google.com with SMTP id t17so2162926ply.5 for ; Wed, 05 Feb 2020 16:41: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=dc1xnC2Yu5IrOpjcdoaBFZ2Zc8DG4O3aHKRqAb2kd3w=; b=jIIeqdI773ut41OopRPc6OAm2Y36vx22wtrfVpKgY5cYmn4BGLaYWOLT2dzW6sKyYH MBczLCzRROVDhaPtFrkNo0ppzxqAwHprENUkIduDLHiEnCv/2vnYkqUTYJlp4iWAYmJy GuokHrqs5l4Bmbv2Kbe5qbEihveQ/jrlxvXNAw3U4JWQi0PMyS1Qv5F/XbuH8qnp9zhj gjzIBRfPPqftI6uQWyr/tJtIDD0tqLwCgjObr6aPrE9SoBTFdkhc5gVoGWayQ8fpwe8f xvkjS3LVMFSmnI+PdVQnrSSbzN00JDPDiSeZuI+t61TRc9Knr71+QMS5wBW2jZax0vzf yG6Q== 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=dc1xnC2Yu5IrOpjcdoaBFZ2Zc8DG4O3aHKRqAb2kd3w=; b=MKOK9dN8BXzAE5XLJC7NKy+M8LLtNhyqYgFzBuxNMo4/AaAxv/xmUYXYrxVTioWrOI 645gMsM6L9nJCPsVf0Vz05lsYWNtPpYLXR2ujE9h/Q2392RRI0vtekljacsfFCG6vyQE ofFQRb6B5UZMkH2OW3JyL44NpsuTWKtoAhMcs+YxOEmYJ4uBXBdGNZnAshclDUZBGnIh grcO2mlIOv5BQmf6Rs7ITgBga6giV0mqktDvruVSkrDDvip4xbX1eE2TltCGGA5JWOwS osBEAVhvZ29zAcu+gZz095MBKuCsq9eXPGx0oXN8gfBFce7OHx8GNsOSFNV7I2W8NS+P iQaA== X-Gm-Message-State: APjAAAW54Zb1LCFXiZ1wTEd+WGCFY90ppX1O0erG4bxuGRNpnqikXMql 7rHwrHmZgkWkGi9fm5i9kP5Gjyi+OmOvB9//ZEi//elZrgGWhO2A4UT86MNQb1irTcP4pgk8g71 Yh/G0twnEM2IqGRA1apBMW2Pgp+06MuWKuKRKDPgCIzPoPy3uPQxdOzdIV6BSN1TgO1GUSnRnEQ == X-Google-Smtp-Source: APXvYqy9pqk/gRrxfJEEU6mjyaU2oJJnQUyKhgnstvAN783SvJ77S0CfwhzCYtE3m8RJHJPgrKdlzz5W0C9vwpZEgMg= X-Received: by 2002:a63:455c:: with SMTP id u28mr661340pgk.163.1580949696420; Wed, 05 Feb 2020 16:41:36 -0800 (PST) Date: Wed, 5 Feb 2020 16:40:59 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 06/15] bugreport: add compiler info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To help pinpoint the source of a regression, it is useful to know some info about the compiler which the user's Git client was built with. By adding a generic get_compiler_info() in 'compat/' we can choose which relevant information to share per compiler; to get started, let's demonstrate the version of glibc if the user built with 'gcc'. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 5 +++++ compat/compiler.h | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 compat/compiler.h diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 4dd72c60f5..8bbc4c960c 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -27,6 +27,7 @@ The following information is captured automatically: - 'git version --build-options' - uname sysname, release, version, and machine strings + - Compiler-specific info string OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 4c4b877ea1..aaeb94c10c 100644 --- a/bugreport.c +++ b/bugreport.c @@ -4,6 +4,7 @@ #include "strbuf.h" #include "time.h" #include "help.h" +#include "compat/compiler.h" static void get_system_info(struct strbuf *sys_info) { @@ -24,6 +25,10 @@ static void get_system_info(struct strbuf *sys_info) uname_info.release, uname_info.version, uname_info.machine); + + strbuf_addstr(sys_info, "compiler info: "); + get_compiler_info(sys_info); + strbuf_complete_line(sys_info); } static const char * const bugreport_usage[] = { diff --git a/compat/compiler.h b/compat/compiler.h new file mode 100644 index 0000000000..bda5098e1b --- /dev/null +++ b/compat/compiler.h @@ -0,0 +1,24 @@ +#ifndef COMPILER_H +#define COMPILER_H + +#include "git-compat-util.h" +#include "strbuf.h" + +#ifdef __GLIBC__ +#include + +static inline void get_compiler_info(struct strbuf *info) +{ + strbuf_addf(info, "glibc: %s", gnu_get_libc_version()); +} + +#else + +static inline void get_compiler_info(struct strbuf *info) +{ + strbuf_addstr(info, "get_compiler_info() not implemented"); +} + +#endif + +#endif /* COMPILER_H */ From patchwork Thu Feb 6 00:41:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367411 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 335BD14B4 for ; Thu, 6 Feb 2020 00:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1216321775 for ; Thu, 6 Feb 2020 00:41:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DNFn9ujg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727609AbgBFAll (ORCPT ); Wed, 5 Feb 2020 19:41:41 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:43484 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727594AbgBFAlj (ORCPT ); Wed, 5 Feb 2020 19:41:39 -0500 Received: by mail-pl1-f202.google.com with SMTP id n17so2153419plp.10 for ; Wed, 05 Feb 2020 16:41: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=ujjBNDyfw7GCLR2oiVSm8ReAAGWWdvXUt3+varUUjp4=; b=DNFn9ujg8cSIz3eg2QuZ7BKh/t2qx+dSFhNcSi9ubplihN3Q8pzN9nc1O+5DZh70og IRaz7/DTpilyjJfI2ckfxfd055X9CW1aM6DQXSCnbkGgjN+Hzrrg3BDOpg5aNnWhLHGn lqPfC+WaHa+cHfNqvilNUjX8Np025CYRRjzLUw6h9lO7kAE9o9fCRT9sjQvYgKqp1DiC YD6Vo0iGcKmky2gp8hIedIF8KQHVj9fQzaOg3M7wLAodwcZ7HmWZn/P3WK0jaTQRKQUF d54sgajhoznjnzHHzTgIAxCKoVrZqbJO5hajuVrEXJ9L6NtTNbmzwytjWdLC/vt2lXJk juww== 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=ujjBNDyfw7GCLR2oiVSm8ReAAGWWdvXUt3+varUUjp4=; b=tEUOnBR4xnT39HyeUlcndNEFBBx6ulCmmRq4AU19NeIKykhGDflJlUqqfy+LLdWLz9 TyGfv/PPUeToUHVoJ/rFlcygPqhpa4RXl5cI5Jv2M5shJMWTqKd7vMpRTTiyRWyB36BT XSicT9z5Z2XXVD43htmU1pufOzX5fDKXf00WsxUJrc0M4PAmrcv5VONJR2fdb6Q9IUbu ssNJh8Tv43DJ1T05lGbSgkGOR2iDVfhvSeoB+drCYmaWbya4emDL0mhuaRJYIyUgOrb/ D5/Cy42jwLKqYkK70zJSZnxYIt3Z1fiZU5gvoO5NviV0JXJgYCBzrHyO7E1LdwoDBpNe G5oQ== X-Gm-Message-State: APjAAAUwgsSms7iwIWH7oFdKze/UyRJ9VANnw0tt7eMfG/swXDIP3Jmm mCXJcUzhu3bxFq8OFTpIDQ3U+AqEBL+rEqmfoNJ+B2xH67+4LoSCq8HMhCqgp0NFRUdCtfzVRcG 3s/2ZQvlFsp50heYa/4QD0DKoxKGAZkrlSs+hvnsgzi7AJLKFQJ11LpJYzVwr+eX1Fy/+P4JRhg == X-Google-Smtp-Source: APXvYqxessZrdtac2NVR/uRl/v6+PHOAUBdGn2+Exd4PC9KKtBMLmQ6L1dym7DZv2v67ZOwkC0yhVGQqbSwhEEMpHkA= X-Received: by 2002:a63:515d:: with SMTP id r29mr611460pgl.265.1580949698874; Wed, 05 Feb 2020 16:41:38 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:00 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 07/15] bugreport: add git-remote-https version From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's possible for git-remote-curl to be built separately from git; in that case we want to know what version of cURL is used by git-remote-curl, not necessarily which version was present at git-bugreport's build time. So instead, ask git-remote-curl for the version information it knows about. Today, "git-remote-http" and "git-remote-https" are aliased to "git-remote-curl"; but in case we rely on a different library than cURL in the future, let's not explicitly reference cURL from bugreport. For longevity purposes, invoke the alias "git-remote-https" instead of "git-remote-http". Since it could have been built at a different time, also report the version and built-from commit of git-remote-curl alongside the cURL info. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 16 ++++++++++++++++ remote-curl.c | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 8bbc4c960c..33df4dec7f 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -28,6 +28,7 @@ The following information is captured automatically: - 'git version --build-options' - uname sysname, release, version, and machine strings - Compiler-specific info string + - 'git remote-https --build-info' OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index aaeb94c10c..da5859c131 100644 --- a/bugreport.c +++ b/bugreport.c @@ -5,6 +5,18 @@ #include "time.h" #include "help.h" #include "compat/compiler.h" +#include "run-command.h" + +static void get_git_remote_https_version_info(struct strbuf *version_info) +{ + struct child_process cp = CHILD_PROCESS_INIT; + + argv_array_push(&cp.args, "git"); + argv_array_push(&cp.args, "remote-https"); + argv_array_push(&cp.args, "--build-info"); + if (capture_command(&cp, version_info, 0)) + strbuf_addstr(version_info, "'git-remote-https --build-info' not supported\n"); +} static void get_system_info(struct strbuf *sys_info) { @@ -29,6 +41,10 @@ static void get_system_info(struct strbuf *sys_info) strbuf_addstr(sys_info, "compiler info: "); get_compiler_info(sys_info); strbuf_complete_line(sys_info); + + strbuf_addstr(sys_info, "git-remote-https --build-info:\n"); + get_git_remote_https_version_info(sys_info); + strbuf_complete_line(sys_info); } static const char * const bugreport_usage[] = { diff --git a/remote-curl.c b/remote-curl.c index 350d92a074..c590fbfae3 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -17,6 +17,7 @@ #include "protocol.h" #include "quote.h" #include "transport.h" +#include "version.h" static struct remote *remote; /* always ends with a trailing slash */ @@ -1374,6 +1375,13 @@ int cmd_main(int argc, const char **argv) string_list_init(&options.deepen_not, 1); string_list_init(&options.push_options, 1); + if (!strcmp("--build-info", argv[1])) { + printf("git-http-fetch version: %s\n", git_version_string); + printf("built from commit: %s\n", git_built_from_commit_string); + printf("curl version: %s\n", curl_version()); + return 0; + } + /* * Just report "remote-curl" here (folding all the various aliases * ("git-remote-http", "git-remote-https", and etc.) here since they From patchwork Thu Feb 6 00:41:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367413 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 AD8B014B4 for ; Thu, 6 Feb 2020 00:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CA3021775 for ; Thu, 6 Feb 2020 00:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NNg2KUID" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727617AbgBFAlo (ORCPT ); Wed, 5 Feb 2020 19:41:44 -0500 Received: from mail-qv1-f73.google.com ([209.85.219.73]:33754 "EHLO mail-qv1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727594AbgBFAlo (ORCPT ); Wed, 5 Feb 2020 19:41:44 -0500 Received: by mail-qv1-f73.google.com with SMTP id g6so2669283qvp.0 for ; Wed, 05 Feb 2020 16:41: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=LiqBU2NZJkFohItMVyTBnqvVVK4vvXjflKpGmKVrOC8=; b=NNg2KUIDLfPOEub34yu33KhTLZvnWM5jolTQWQmcw/Uizp3lphftWPdASJYMfPkqUr LKhxXBqLlZRUV+UE8b27Svc4kk7ON3lWHq78dHcJI4gsVZ+YBm7pN/WwnjvAO+cNzO8Z n+4Ape0I3KJdOqVGIktok70PrsuthVwwtw4vxNae8APyJr0bRUOtcmBIABVuM9W82tV3 q8MfqFCFkOsIT657WbE9s2k20zVqjFqIswfq6b0FRQQlq6ghFD0+xMNuXTa1CgTeyo8a f3fBr05rE4r9xCPsNigz+x46FsBicF134CCmgXDbc0j6dzdk35mqVmkqtOOD+lXXFNnA 2q8Q== 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=LiqBU2NZJkFohItMVyTBnqvVVK4vvXjflKpGmKVrOC8=; b=UAHqlQzt49RCOtEEEcKPJtiAKpg6LhsttdL7sz6xRprsIzbsP9c5ZsW93a85YgE7m9 3TSqgIgTKiViJwl0EDSc0yIvEoQfTWyWbH38GBzFCKHlgTAVkrPyNQYcZS1m2gLUeEPM dqkt4Ybj9Jw7fhfN1N9AH18JNIUDKUNvbzYSwviTi1Hi7Wc77+VHHEa+xcaeyJKIhhHs wAJ4nUkhgAb8/huoRHZtBOjtY+rE33K06CfFFWiY1OHnz5QadbRXzIEOTx6ZuAvd1L5F 7y9dlvAXVRgSHXvyi4utBiHkUL6jsuyT5KR39rculSIWHu7r4YMPxDwOuLRZPn0QNxpP ZSbg== X-Gm-Message-State: APjAAAVWRkDfL9aCwscD9bAz7n7N3CT/tvRSvDPR1hMmIAzkXQGU+F9r yYM/9OUG1jfCRyL6ZRMdf+ACf9LjtPe1VB8UaNKFHB0NOdXj1yDcX6TAxmqfypXmkyjlIPTppz0 fbep3aplOiTMBn7Bl8CXcJkPHTBLep79jtRSLyv8oWnyLFqrOLmsxuY4YA8KY1Q/kAq2xbkOaKQ == X-Google-Smtp-Source: APXvYqynZxYDoM0+hZLVwOPinmqY+CjpOJrZVBYlvcrhsKMT1fVq7kplFqvizHun0SaaZCuO2iau11XJu/BDD75L+bA= X-Received: by 2002:a37:65c8:: with SMTP id z191mr394838qkb.176.1580949701476; Wed, 05 Feb 2020 16:41:41 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:01 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 08/15] bugreport: include user interactive shell From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's possible a user may complain about the way that Git interacts with their interactive shell, e.g. autocompletion or shell prompt. In that case, it's useful for us to know which shell they're using interactively. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 33df4dec7f..23265b0d74 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -29,6 +29,7 @@ The following information is captured automatically: - uname sysname, release, version, and machine strings - Compiler-specific info string - 'git remote-https --build-info' + - $SHELL OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index da5859c131..9b51250155 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 6 00:41:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367415 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 2AEAC139A for ; Thu, 6 Feb 2020 00:41:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F2D0E21775 for ; Thu, 6 Feb 2020 00:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EtLirClw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727628AbgBFAlp (ORCPT ); Wed, 5 Feb 2020 19:41:45 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:51453 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727605AbgBFAlo (ORCPT ); Wed, 5 Feb 2020 19:41:44 -0500 Received: by mail-pl1-f202.google.com with SMTP id 71so2145033plb.18 for ; Wed, 05 Feb 2020 16:41:44 -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=3YyqGZ8aXVg0+rVOJCVfZyJznLLWhioF3VHsPuVTBNw=; b=EtLirClwXb+GIz6xzYjsLQY77wAtReZDo8i6qO1q/FvKFF7n+fxKVPzckHVip3HCxy qefOObBUBqwHaBquF+U6Z82eXXH2fZTD+sXjLmHzSf9NhBGw7G2ChrjY8Y9Z18PpeRc6 VzYeVz0W3KNz3vjJ6UcXrLIeK7rRoa11P2MoMEXfpprBdesVeahJ8EONZ/SrNC9Ua4I/ L5aMvyA/828sZAxIcVWgmjSBJrGbFxnTKeRi4FkHtFolv8Msyamz5K5pynAhkT1E1ICu 7BjGdSp/T6R58LG5FsWWHE5R8EAj5RT/xaGVCe4wFhmdjCZSoCXt0dtonIYw5DuHG1LC 9Ntw== 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=3YyqGZ8aXVg0+rVOJCVfZyJznLLWhioF3VHsPuVTBNw=; b=rbpfEcgIeHtLEc7lLCcUcpY3fW5poZqFOj5T0NjnMXQXU2nWdKGgburBLZP7EKl/s2 PX2lz7OKFjqFmmGF3TQ5JtREXghhM+4kfNOlYXv8RLzQq7svcJPZsyRAt4UsSmG7eTL4 n5TVE8lmQ3HBWf5B0YX3ADbplKqDNmPHoze4a7AAcNkqluHAJxT4rU0cniH+6JD8JeDv C4DH32hOtad8pTviqVLV+4EwcQ3H62Y6cv9X3c1GrBOdEC4viGPbZ1YWEBfimDbKB8eS zRIoRgblCnCbJoFwk91RBspYuW6nDLUAt37AhNysTZGrH+qOM5xsPziwr/3J6PS3N/Qj Rhlg== X-Gm-Message-State: APjAAAUumKYFARFTdeMNtGsIYKx4CiEYalb9sg9z7uMXO8H9/n6TCESI GknBka4FfcYo2b1pD9jZ6ePOdKIjuLuOjX32mAStZwmo0hiiyg8v0Aq5NHK9/ZEXoJ1fbBQCJb4 2blDJlV2bm1y68MxA/xFYEA+61MYgcOuYIWJM2LZmcS4oLumzvE+ANEY2RC/x1gmZDVSXoxoLxA == X-Google-Smtp-Source: APXvYqzJRRvOjf4tNoutAoKTjETouY3bbWH0dqPT0VccQF1VpSukvXAb9oUvdRP48cSZ5gLKQ21E+0TB1AeF4i7zYmw= X-Received: by 2002:a63:4804:: with SMTP id v4mr610930pga.373.1580949703776; Wed, 05 Feb 2020 16:41:43 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:02 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 09/15] bugreport: generate config safelist based on docs From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , " =?utf-8?q?Martin_=C3=85gren?= " , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a new step to the build to generate a safelist of git-config variables which are appropriate to include in the output of git-bugreport. New variables can be added to the safelist by annotating their documentation in Documentation/config with the "annotate" macro, which is a no-op in AsciiDoc and AsciiDoctor. Some configs are private in nature, and can contain remote URLs, passwords, or other sensitive information. In the event that a user doesn't notice their information while reviewing a bugreport, that user may leak their credentials to other individuals, mailing lists, or bug tracking tools inadvertently. Heuristic blocklisting of configuration keys is imperfect and prone to false negatives; given the nature of the information which can be leaked, a safelist is more reliable. However, it's possible that in some situations, an organization may be less concerned with privacy of things like remote URLs and branch names, and more concerned with ease of diagnosis for their support staff. In those cases, it may make more sense for that organization to modify the code to use a blocklist. To that end, we should try to mark configs which are definitely safe, and configs which are definitely unsafe, and leave blank configs which are somewhere in between. To mark a config as safe, add "annotate:bugreport[include]" to the corresponding line in the config documentation; to mark it as unsafe, add "annotate:bugreport[exclude]" instead. Generating bugreport-config-safelist.h at build time by grepping the documentation for this new macro helps us prevent staleness. The macro itself is a no-op and should not alter the appearance of the documentation in either AsciiDoc or AsciiDoctor, confirmable by running: cd Documentation ./doc-diff --asciidoctor HEAD^ HEAD ./doc-diff --asciidoc HEAD^ HEAD Diffing the rendered HTML shows that only inline comments were added, which shouldn't be a problem. Additionally, add annotations to the sendemail config documentation in order to demonstrate a proof of concept. Helped-by: Martin Ă…gren Helped-by: Johannes Schindelin Signed-off-by: Emily Shaffer --- .gitignore | 1 + Documentation/asciidoc.conf | 9 ++++ Documentation/asciidoctor-extensions.rb | 5 +++ Documentation/config/sendemail.txt | 56 ++++++++++++------------- Makefile | 7 ++++ generate-bugreport-config-safelist.sh | 17 ++++++++ 6 files changed, 67 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..382bd8f6f4 100644 --- a/Documentation/asciidoctor-extensions.rb +++ b/Documentation/asciidoctor-extensions.rb @@ -37,6 +37,10 @@ module Git output = output.sub(/<\/refmeta>/, new_tags + "") end output + + class AnnotateProcessor < Asciidoctor::Extensions::InlineMacroProcessor + def process(parent, target, attrs) + "" end end end @@ -45,4 +49,5 @@ end Asciidoctor::Extensions.register do inline_macro Git::Documentation::LinkGitProcessor, :linkgit postprocessor Git::Documentation::DocumentPostProcessor + inline_macro Git::Documentation::AnnotateProcessor, :annotate end diff --git a/Documentation/config/sendemail.txt b/Documentation/config/sendemail.txt index 0006faf800..fe27473e44 100644 --- a/Documentation/config/sendemail.txt +++ b/Documentation/config/sendemail.txt @@ -4,7 +4,7 @@ sendemail.identity:: values in the 'sendemail' section. The default identity is the value of `sendemail.identity`. -sendemail.smtpEncryption:: +sendemail.smtpEncryption annotate:bugreport[include] :: See linkgit:git-send-email[1] for description. Note that this setting is not subject to the 'identity' mechanism. @@ -15,7 +15,7 @@ sendemail.smtpsslcertpath:: Path to ca-certificates (either a directory or a single file). Set it to an empty string to disable certificate verification. -sendemail..*:: +sendemail..* annotate:bugreport[exclude] :: Identity-specific versions of the 'sendemail.*' parameters found below, taking precedence over those when this identity is selected, through either the command-line or @@ -23,41 +23,41 @@ sendemail..*:: sendemail.aliasesFile:: sendemail.aliasFileType:: -sendemail.annotate:: -sendemail.bcc:: -sendemail.cc:: -sendemail.ccCmd:: -sendemail.chainReplyTo:: -sendemail.confirm:: -sendemail.envelopeSender:: -sendemail.from:: -sendemail.multiEdit:: -sendemail.signedoffbycc:: -sendemail.smtpPass:: -sendemail.suppresscc:: -sendemail.suppressFrom:: -sendemail.to:: -sendemail.tocmd:: -sendemail.smtpDomain:: -sendemail.smtpServer:: -sendemail.smtpServerPort:: -sendemail.smtpServerOption:: -sendemail.smtpUser:: -sendemail.thread:: -sendemail.transferEncoding:: -sendemail.validate:: -sendemail.xmailer:: +sendemail.annotate annotate:bugreport[include] :: +sendemail.bcc annotate:bugreport[include] :: +sendemail.cc annotate:bugreport[include] :: +sendemail.ccCmd annotate:bugreport[include] :: +sendemail.chainReplyTo annotate:bugreport[include] :: +sendemail.confirm annotate:bugreport[include] :: +sendemail.envelopeSender annotate:bugreport[include] :: +sendemail.from annotate:bugreport[include] :: +sendemail.multiEdit annotate:bugreport[include] :: +sendemail.signedoffbycc annotate:bugreport[include] :: +sendemail.smtpPass annotate:bugreport[exclude] :: +sendemail.suppresscc annotate:bugreport[include] :: +sendemail.suppressFrom annotate:bugreport[include] :: +sendemail.to annotate:bugreport[include] :: +sendemail.tocmd annotate:bugreport[include] :: +sendemail.smtpDomain annotate:bugreport[include] :: +sendemail.smtpServer annotate:bugreport[include] :: +sendemail.smtpServerPort annotate:bugreport[include] :: +sendemail.smtpServerOption annotate:bugreport[include] :: +sendemail.smtpUser annotate:bugreport[exclude] :: +sendemail.thread annotate:bugreport[include] :: +sendemail.transferEncoding annotate:bugreport[include] :: +sendemail.validate annotate:bugreport[include] :: +sendemail.xmailer annotate:bugreport[include] :: See linkgit:git-send-email[1] for description. sendemail.signedoffcc (deprecated):: Deprecated alias for `sendemail.signedoffbycc`. -sendemail.smtpBatchSize:: +sendemail.smtpBatchSize annotate:bugreport[include] :: Number of messages to be sent per connection, after that a relogin will happen. If the value is 0 or undefined, send all messages in one connection. See also the `--batch-size` option of linkgit:git-send-email[1]. -sendemail.smtpReloginDelay:: +sendemail.smtpReloginDelay annotate:bugreport[include] :: Seconds wait before reconnecting to smtp server. See also the `--relogin-delay` option of linkgit:git-send-email[1]. diff --git a/Makefile b/Makefile index a01a050aa3..2bc9f112ea 100644 --- a/Makefile +++ b/Makefile @@ -817,6 +817,7 @@ VCSSVN_LIB = vcs-svn/lib.a GENERATED_H += config-list.h GENERATED_H += command-list.h +GENERATED_H += bugreport-config-safelist.h LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ $(FIND) . \ @@ -2163,6 +2164,12 @@ command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Doc $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ command-list.txt >$@+ && mv $@+ $@ +bugreport-config-safelist.h: generate-bugreport-config-safelist.sh + +bugreport-config-safelist.h: Documentation/config/*.txt + $(QUIET_GEN)$(SHELL_PATH) ./generate-bugreport-config-safelist.sh \ + >$@+ && mv $@+ $@ + SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\ $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\ $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\ diff --git a/generate-bugreport-config-safelist.sh b/generate-bugreport-config-safelist.sh new file mode 100755 index 0000000000..17d92a91c5 --- /dev/null +++ b/generate-bugreport-config-safelist.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +cat < X-Patchwork-Id: 11367417 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 C907C14B4 for ; Thu, 6 Feb 2020 00:41:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A87BA217BA for ; Thu, 6 Feb 2020 00:41:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sNIMidWL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727641AbgBFAlr (ORCPT ); Wed, 5 Feb 2020 19:41:47 -0500 Received: from mail-pg1-f201.google.com ([209.85.215.201]:37980 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727634AbgBFAlr (ORCPT ); Wed, 5 Feb 2020 19:41:47 -0500 Received: by mail-pg1-f201.google.com with SMTP id q3so2171954pgj.5 for ; Wed, 05 Feb 2020 16:41:46 -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=Xn7vYQZm56gxEnLr9PuWecj9e7cLoJ7hhpV54aYx100=; b=sNIMidWLrYoZu2Vd3ZC1exf4h1JfdG16QLuOVbiEkVURb3levGbWUxDG4ybDxw7IaW yjAHdjJJx4g53vb3FDlBCjES99bsrrLYhB3JAlpiFc3gl+J0t0mRIZbjEFm4cijpJG6e ibV/LolxLkBVplaCFaOlKBBbfwmZVWlwp3+6+0LLs8sZCVVVSQd4Eam5h6gacpzcILc+ SzqJ2AaWzLZVRsnZPc3ZZ3kty0b6ZcuiyDLjyElih0rGxD3Ph/61DDqmgnbJrb0XW7kG Xw7AK7vuI0ODYDyNgHEysu6cDp65cVTltfUg2J0XpzCuiT97O9tN5KHYQ40M7oEadron MOZg== 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=Xn7vYQZm56gxEnLr9PuWecj9e7cLoJ7hhpV54aYx100=; b=fNVWTOi0tTym+W2TAK9y1knuo0pLJNMfVK0I2V60P1NljJWTzUvu05G1c9il6ldFFT Y7dNd7eYwE84OLZZcHherLXb2klLSDfgMHHthATk+92RoBJaCnou4L4RwCNXBBQKYtn8 1LLVj09ljKry31dyTViWgoLxFwGmH13a+y/lkF0JYQy/+BVuXVYMp9dS+VcoEdMOxwGf rsXiNhZ//w9a27GnNe5hWBmCjmuWp7juKgSlb7pEks9DXIzrAF3l4/+6WavDFXSiNml9 3bqZJ3bQpWZNNhfEgti2JSikLysemN8HJEuZHkGwHOtnMBfS6OcvFY7K38Ks9WjPJ8rA H+AA== X-Gm-Message-State: APjAAAUYD4iewo7ahXNupYtfBpp5Q1+SRALhr4OGlQ7IXDaK1cTHjwDc qFi6IsfjDR1t56MvNmlL+6t7btWZN83n73AHtLXGsTxgbUIKfTWIZlo8irA6R01r6bcPd7yty0x V2nd7O/jNUEfJc+h40y+xf+mrFUwgnqgQvpi3O9i7/GDOG8tkaM/VySn5NGngWmX9t2Zep+C5WA == X-Google-Smtp-Source: APXvYqyQamB6qh/UhLDZI+QRdPGApI99XeT6DXSHa+D82casxqM0zKDgwCrRKJt2NadMulK5hpQmNB450VVdP84c02w= X-Received: by 2002:a63:a807:: with SMTP id o7mr595336pgf.407.1580949706144; Wed, 05 Feb 2020 16:41:46 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:03 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-11-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 10/15] bugreport: add config values from safelist From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach bugreport to gather the values of config options which are present in 'bugreport-config-safelist.h', and show their origin scope. Many config options are sensitive, and many Git add-ons use config options which git-core does not know about; it is better only to gather config options which we know to be safe, rather than excluding options which we know to be unsafe. Rather than including the path to someone's config, which can reveal filesystem layout and project names, just name the scope (e.g. system, global, local) of the config source. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + Makefile | 2 ++ bugreport.c | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 23265b0d74..4e9171d1bd 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -30,6 +30,7 @@ The following information is captured automatically: - Compiler-specific info string - 'git remote-https --build-info' - $SHELL + - Selected config values OPTIONS ------- diff --git a/Makefile b/Makefile index 2bc9f112ea..7b139230ae 100644 --- a/Makefile +++ b/Makefile @@ -2131,6 +2131,8 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) help.sp help.s help.o: command-list.h +bugreport.sp bugreport.s bugreport.o: bugreport-config-safelist.h + builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \ '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ diff --git a/bugreport.c b/bugreport.c index 9b51250155..16216bff8e 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); @@ -123,6 +154,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 6 00:41:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367419 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 05D7A14B4 for ; Thu, 6 Feb 2020 00:41:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D774521775 for ; Thu, 6 Feb 2020 00:41:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NT+MbDxH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727634AbgBFAlt (ORCPT ); Wed, 5 Feb 2020 19:41:49 -0500 Received: from mail-pf1-f201.google.com ([209.85.210.201]:36906 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727605AbgBFAlt (ORCPT ); Wed, 5 Feb 2020 19:41:49 -0500 Received: by mail-pf1-f201.google.com with SMTP id x10so2680408pfn.4 for ; Wed, 05 Feb 2020 16:41:49 -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=Xpqvzge8j5/JAisopm62IeoSPFDy2qY2aFrtcninBJY=; b=NT+MbDxH+mtToZy/nL8AnhRh2xKk9ykjRwXzxRkabUXgHdSrjR+CDvPMyxbwlcZB2X GvrA1tJ7V9b9mIzUB5blngEVMavIw5J6LBvi9JGa47BlU7uwDGYw7H3txZcJpoYNDF8X 1ZhAd+O5vlep35fTS1A4unrv1p/4iiVP4o3T3zxIrJI9B0aeEf4CCpVjMoET7cXP/x4o cRG9j5pTeUj7ZMXtBNn4Rv0u+19Op5li6PXeqIyoKayOMEqPRd57WDP6hDfoQRqe/DFy fAHFPWPoGDkToyOOIYASwGIunHiEkvwJ1SbhgS3HgiXprrJzjkCI81wLjHX+Uf13rih+ u9Bw== 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=Xpqvzge8j5/JAisopm62IeoSPFDy2qY2aFrtcninBJY=; b=Bn+I6EYj8ngQBAn8SafC99xg1C+T2bDUsiJs5bXQzfcnrhrNKSwIFl7kBw/A+3XRen PErfWmlxs1B4SqojVTS7fjWTqRRBA67s1K2yiybtyezamD4eaDgg/JHXHrb5UXIdyGyT SnwOYvNqH7LUxei5YaFr9zUvwsrRGbKy2WUDjvUc0LA67wVuJsty0d4WfgTUJT/sG/Ev 4o4SqkA9aZKZkXD0Mq2ADmFtfWZu4FKy032oudhGQMQfNBrPM0gdnTScHS31NPAlfk4s +heEvVYJuqFeLRJSIvOudvvXx7ZeCdWRWxjCWXVWh7fTLbcw5RbEI/yQ+w7jivBI7DDl p6cw== X-Gm-Message-State: APjAAAXYtpRdj2bJJKsELs0LtdFYHgUvU3ioT4NLRNXbDQtQezT87wsV 5dTc8b+enoh50NNLNDRCobQ4JIO2oLsKbHMzGJqSoTomTzQZOXJ9Hb0bl/OV6MN13Xsy3e+n3ps Bdt7NS5thXwEhtuZCAtIRnre+rkI0tnT0RGlTGtAMzZJfzqdS+/Dgfpp4r6yIKfy3ozy/Ent2Hw == X-Google-Smtp-Source: APXvYqyjBzM8wz48NZ/T82YODHBPLIGH5oyxKikpljmCY17Dnft6LytESTGjIsP3eKn/dMFlkVJp6KyYsPzjiv6TDag= X-Received: by 2002:a63:6ac1:: with SMTP id f184mr628041pgc.133.1580949708557; Wed, 05 Feb 2020 16:41:48 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:04 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-12-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 11/15] bugreport: collect list of populated hooks From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Occasionally a failure a user is seeing may be related to a specific hook which is being run, perhaps without the user realizing. While the contents of hooks can be sensitive - containing user data or process information specific to the user's organization - simply knowing that a hook is being run at a certain stage can help us to understand whether something is going wrong. Without a definitive list of hook names within the code, we compile our own list from the documentation. This is likely prone to bitrot. To reduce the amount of code humans need to read, we turn the list into a string_list and iterate over it (as we are calling the same find_hook operation on each string). However, since bugreport should primarily be called by the user, the performance loss from massaging the string seems acceptable. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 4e9171d1bd..779c9c7fd9 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -31,6 +31,7 @@ The following information is captured automatically: - 'git remote-https --build-info' - $SHELL - Selected config values + - A list of enabled hooks OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 16216bff8e..3b0a2b12cc 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 @@ -157,6 +207,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 6 00:41:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367421 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 431F3139A for ; Thu, 6 Feb 2020 00:41:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22DB721775 for ; Thu, 6 Feb 2020 00:41:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s4+T/EL/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727658AbgBFAlx (ORCPT ); Wed, 5 Feb 2020 19:41:53 -0500 Received: from mail-pj1-f74.google.com ([209.85.216.74]:50181 "EHLO mail-pj1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbgBFAlx (ORCPT ); Wed, 5 Feb 2020 19:41:53 -0500 Received: by mail-pj1-f74.google.com with SMTP id z12so2204438pju.0 for ; Wed, 05 Feb 2020 16:41:51 -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=HXAJ+iFjamq+8uYEpgJHgUKO9+FVivh727MB+qeHfTA=; b=s4+T/EL/FS4DplPZdX6e/zRcETF1KeYoN+qKNpm3+76iheo9rVhXZmK81wjX384ppm clhGNSY1L8/UTTFQJEJSFdmRxBVlxDKvwDNwNxOya6cjzhBqZWs2mxh64qdG4IqElDBh X6/4JRZgGWsoykK28gBYqLo7uXUxlzOEdX8PRbGXCK8BfF3+2soNbKud/DZlHKkhExW4 NgRSqRjPdJc/A7qcYb+3xEhED66KTdA/CciCtH1xh8Ks8RM6hOWq3tB9wBR++UxHUZ/2 cSIcnDLoQj6R1dEOdbSR2G4hyhIQuNAqLGTtkdnB4mKMzwv+llVGf10Lt/KlWfj48UIX cqBA== 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=HXAJ+iFjamq+8uYEpgJHgUKO9+FVivh727MB+qeHfTA=; b=omlwbHW0iKMjtf+6OoA63WIZmrpfPUJ6B0Yv+9LTNXrh1IOr1+y8IEn6eugs71WOh/ LUcECD5U4rGLAinVHh/9fDO22HMPGCDfsUDoIBc6PW8437WPwcJ/enhaHWWYSgi4XGKJ RIAUbQPXzx/D8wUAQWHZwnYu2nyZM3pyZizE7DMrCOQYNFFHKpdQcxtpHT0bmjTYYeQJ g14KVluqbgf9OH3QeG/8sB67N8iziSgTr1eB50xVSQ8uVlNgNNzQYz5ZXtqmaLQJpuWV TgW/YRd57JAzc93+tYD3HEBehSeIvz+o0b1ftsQWsLUY3b2MpyZvuabbLcgmVZ28LqfC DjXA== X-Gm-Message-State: APjAAAWEUFmyjY3YizCbmgWpIAkT4beaizDJJp51Nm+CnsUKCGBufSGO Hx8W4qrS/SxlbhDaxRMyei56qBJfTAbLklbu1jys3xnCCglMMJ+A4UvbqIvAVlApKu+kYDvdBzK VCDwHqDdEyU0zBZ2ULv9OscUcAVCZ+MDkjjKxg0JHokn74n7hkNd/EsHd/V+nEXcWvadlVyWlAA == X-Google-Smtp-Source: APXvYqyfEIdWycxit6MIuxcNE62TLpfxx/vp0vV8JCMjUvwJ4rVZzEIMwH9qfkF2PGapHOjjKvIvny3M+CNmsBAsMfk= X-Received: by 2002:a63:d406:: with SMTP id a6mr684882pgh.264.1580949710924; Wed, 05 Feb 2020 16:41:50 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:05 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-13-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 12/15] bugreport: count loose objects From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The number of unpacked objects in a user's repository may help us understand the root of the problem they're seeing, especially if a command is running unusually slowly. Helped-by: Johannes Schindelin Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 779c9c7fd9..7e1ed44cb4 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -32,6 +32,7 @@ The following information is captured automatically: - $SHELL - Selected config values - A list of enabled hooks + - The number of loose objects in the repository OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 3b0a2b12cc..9552e2922e 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 @@ -210,6 +259,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 6 00:41:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367423 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 BFC02139A for ; Thu, 6 Feb 2020 00:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EAF6217BA for ; Thu, 6 Feb 2020 00:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Tkmb7wmK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727663AbgBFAlz (ORCPT ); Wed, 5 Feb 2020 19:41:55 -0500 Received: from mail-vs1-f74.google.com ([209.85.217.74]:33680 "EHLO mail-vs1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbgBFAlz (ORCPT ); Wed, 5 Feb 2020 19:41:55 -0500 Received: by mail-vs1-f74.google.com with SMTP id y15so279169vso.0 for ; Wed, 05 Feb 2020 16:41:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=AVYYQp3rUELKcwibZIXczAtH5lQZZgoIvNRRLEVVSbs=; b=Tkmb7wmK3SLkywHgPorGoZN/EA2o0SXNvPNvkTZNsY6YA3cH28M2d3w0xjhzXKom/u Xp6jnimDhFDMh+6aEWukI/tFrbNVp6ySNkNjeOpv3dV0omBuW0rloqz98ZuhFUvHV3lI 6LWn1igcdCQPckmzMgA+rqlbtxTltw4PRJdEn8XZGp/yuMH5RbfNc1i2DF4pm2hGXH3J mqNL3wvGKjlwnbZu6Yi5C5rAv/STajGZom8FlPhKnu07PfkhlvFkO/klRzetvvdOtCQ2 6Q0u3HePfOLk+NWaPD1lvX9hvLqQus3BafXqDiMnqLvXUkuzWcfIGaEljKjW/D1Bs7hW XtIg== 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=AVYYQp3rUELKcwibZIXczAtH5lQZZgoIvNRRLEVVSbs=; b=O3Y/r8yjDqi+P3jyT4r3N1W/w3Nc9aLSz2qAB0jRTO45ykp18Urk0Wc4hbNKnUacqk jsVZLZu6w0EMoHiAlLtK++9Rr0p+X1ZEolSZcx2HFD/Gr+SiMbT0NM+okZmH6ibjJphA KzqOF3wL5AgBjz6mmv70zJIvjdlAx94JCaN7Imxjj3kduJEfsxDU43m2xPRU15TtbjVr Gujk5dVALPBEEodrdw+Km1a/Gq3kQ3Muf86jVC+THbrwOud1wdxo3M/pm+Y/jptxAno7 tsbXo9ZXPYYuRckiMam0NRVReKfM1K6ozRsKlA5zCbjWWAdTHyl4Va82o1dF28m0JNfA YIDQ== X-Gm-Message-State: APjAAAWQ/KJw7vJqfA74+KVTxJsGmMAxYWYCXYv4C7hUQUh9AWmcdNlE 74KSSK8x1d0qMnULOdLxHY3MTVlB8zTi7wiK7dmlJckYLVTax2tBbRNZmROLCSQvl0g8f6+LXm+ 8TZPMFW6tTehJEYz6hFG784F2VcNV2OK4tguamm+O5azPWVGckY4W3TjCmiRREyD0aoDTad3zmg == X-Google-Smtp-Source: APXvYqy8ofNv6/teoDd9AILK7xRbgVZlYZAMXgRk73pBdvj8rl0zX9pGik11CGLdQ5W41CgxZ6L3zpyaIMiVjWKvLe0= X-Received: by 2002:ab0:48cf:: with SMTP id y15mr245874uac.26.1580949713427; Wed, 05 Feb 2020 16:41:53 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:06 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-14-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 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 --- Perhaps the macro should be in another patch? I didn't spend a lot of time looking for anybody who could conceivably be iterating packs; if I were to do so, I'd break this change out separately. I considered following the pattern in the rest of the file, where the foreach takes a callback and data pointer, but found it would be cumbersome to use with for_each_packed_object() - I'd have to add a new callback just to handle the pack, and bundle that function's callback data along with the callback pointer. It seemed like overkill. - Emily Documentation/git-bugreport.txt | 1 + bugreport.c | 30 ++++++++++++++++++++++++++++++ object-store.h | 6 ++++++ packfile.c | 3 +-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 7e1ed44cb4..309b34fc42 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -33,6 +33,7 @@ The following information is captured automatically: - Selected config values - A list of enabled hooks - The number of loose objects in the repository + - The number of packs and packed objects in the repository OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 9552e2922e..d554488f3e 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 @@ -262,6 +289,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Loose Object Counts"); get_loose_object_summary(&buffer, nongit_ok); + get_header(&buffer, "Packed Object Summary"); + get_packed_object_summary(&buffer, nongit_ok); + report = fopen_for_writing(report_path.buf); if (report == NULL) { diff --git a/object-store.h b/object-store.h index 55ee639350..518c73469d 100644 --- a/object-store.h +++ b/object-store.h @@ -6,6 +6,7 @@ #include "list.h" #include "sha1-array.h" #include "strbuf.h" +#include "packfile.h" struct object_directory { struct object_directory *next; @@ -403,4 +404,9 @@ int for_each_object_in_pack(struct packed_git *p, int for_each_packed_object(each_packed_object_fn, void *, enum for_each_object_flags flags); +#define for_each_pack(repo, pack) \ + for (pack = get_all_packs(repo);\ + pack; \ + pack = pack->next) + #endif /* OBJECT_STORE_H */ diff --git a/packfile.c b/packfile.c index 7e7c04e4d8..6873827fb5 100644 --- a/packfile.c +++ b/packfile.c @@ -2061,8 +2061,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, int r = 0; int pack_errors = 0; - prepare_packed_git(the_repository); - for (p = get_all_packs(the_repository); p; p = p->next) { + for_each_pack(the_repository, p) { if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) continue; if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) && From patchwork Thu Feb 6 00:41:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367425 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 6A220139A for ; Thu, 6 Feb 2020 00:41:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48C3A21775 for ; Thu, 6 Feb 2020 00:41:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tQpHJxBh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727667AbgBFAl6 (ORCPT ); Wed, 5 Feb 2020 19:41:58 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:46902 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbgBFAl6 (ORCPT ); Wed, 5 Feb 2020 19:41:58 -0500 Received: by mail-pl1-f202.google.com with SMTP id t17so2152686plr.13 for ; Wed, 05 Feb 2020 16:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xlXdAkOdeNCyXnBIIbCTdCvrGPJlWzWwSA2EvqUHyXk=; b=tQpHJxBhPofIKnDL5e4w1OctNpnEuQhSgNWiXK6LFp8fl7j8Uz4bF1s5NCUPd0BkM6 GURaiAzxzdIrvpugC8H3TI29LKKJcpwfWJ5RO87YowL4e6NIcccZv681Cf7Fq9jA3Y/W E8HMwjtlIervZID97aEeAwhxldidk8bbt8rRrz1g2qnF1lTXk9CBRkxYV/bylc+Dpf+T C5Qwzre1cVsGEptzuYiAGjmN7fHkL3Vcc02bPhDSfKuWUvGbhLIkMFTRpmMfav2jyVXv qT7wNcvaimdFIihvxFQ4kZtr2w8qxAxuMRqS41FQhy2Bgv2NXq0GlZE91WsjU7epsQDg gNMw== 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=xlXdAkOdeNCyXnBIIbCTdCvrGPJlWzWwSA2EvqUHyXk=; b=OtnNY8ErUdPJCavNxXkaM7ElkJNOgq1QYKnfePKie8Lj4eVABkW0uwbi7M4WPFSohn c3KFl92I7wWvWxGgwWMv7nA3PCmKPRsJt5Gl5gviIsLKDnZy5Emi+HFjfaACmm6dGs6z hzOVhOAPfG+gwLqyOzNyoVmWP9zxM1xeNp2HbOewjnh1Hmv18MbVVx7M1oYVEiJWeRJx t6XdyM/f7GYa3mU43JoKVcmCdaJdt1spMEYsm62JuVA7Wcdd0vmTsugixwTAIgL+23id mvcdd9gquehR4r9Pi6dVxJZd/wsWrHp8sPFTOcvrJ7qyjrE33/B6rqStt1p1gjizMkd+ BZUQ== X-Gm-Message-State: APjAAAUq2Akz1R53UkbeFJHY1f/EJukT4wsknYw5bkgqBfU/XlNbcpJl t/5VnDBue5FwF0eF32jEEMtC21hvEN6GyC0Im4JFhYVOknZSQiQFxrawLH1W35qWZrDB7Z8Ad5d t7kCdk5SdxXAm0sWD7UglcbjyZNHeq1wIzbl97nQ13w4Lt5Oc6lb2xMoyh8UxiV5gJxlSz8J5Mg == X-Google-Smtp-Source: APXvYqwuBYO2l7N7rfeXS+H4W8J0mj0FsZXnOeLfrQJGt/kPsVu1Ea8qhSpq1/xPM/7R1zV7N68lOMzvOOtYN5c9GNI= X-Received: by 2002:a63:7515:: with SMTP id q21mr668826pgc.63.1580949715950; Wed, 05 Feb 2020 16:41:55 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:07 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-15-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 14/15] bugreport: list contents of $OBJDIR/info From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Miscellaneous information used about the object store can end up in .git/objects/info; this can help us understand what may be going on with the object store when the user is reporting a bug. Otherwise, it could be difficult to track down what is going wrong with an object which isn't kept locally to .git/objects/ or .git/objects/pack. Having some understanding of where the user's objects may be kept can save us some hops during the bug reporting process. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index 309b34fc42..a21d081616 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -34,6 +34,7 @@ The following information is captured automatically: - A list of enabled hooks - The number of loose objects in the repository - The number of packs and packed objects in the repository + - A list of the contents of .git/objects/info (or equivalent) OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index d554488f3e..3a3d33f680 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 @@ -292,6 +343,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 6 00:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11367427 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 1E9AA139A for ; Thu, 6 Feb 2020 00:42:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F2847217BA for ; Thu, 6 Feb 2020 00:42:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="g5jRzJwh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727680AbgBFAmB (ORCPT ); Wed, 5 Feb 2020 19:42:01 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:46463 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727669AbgBFAmA (ORCPT ); Wed, 5 Feb 2020 19:42:00 -0500 Received: by mail-pf1-f202.google.com with SMTP id c185so2665453pfb.13 for ; Wed, 05 Feb 2020 16:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+SEt9cIEjZWJQuaMOwoMeoDn/4LSCl52Nai+V0nkf20=; b=g5jRzJwhexYOABCaMOSRTbpKq3B3M8QloSn7+WvtN3JtZHJwD3+xfSK2AYuh4wyHqD X3UzEv0UPx6PqMQ6zAC4PnFm8gSBpIMnHAEDEzjHz0M5EafaAGFLN0Eyc3RS3Wuamy98 mQovZwzG5dy99mM/gxaI34g6vCkroAYh9D+QkmT1EU7+jBeyDB+L3fks9oDurQVl4Un1 KEyEd8xFmROJx7jpDLORSRPGaLmrV23j8NufqVKVFi9qjkx190QTMuh8wrg1M0IAjip1 CUghNxbe3Cy3ecZQojl6eTj0nQ+GjBq4Y/iVDfENm7tKKscPprEqKx8iREsiyjV5yK6O xexQ== 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=+SEt9cIEjZWJQuaMOwoMeoDn/4LSCl52Nai+V0nkf20=; b=SZOJUaayK2iBT/nHOHWdtYvUtmbArMzbGzQM9NyiNK732UHHadwW5gKAwBJwYeLVnv oIJ9RmAQVCZi5yv8msAmszJ735ltG8xKCzReNwvrf5NQkpiIHlLnzHolQaHSVODTuuaH 52YNiQZ9nEz6Wa/E43q4XLN6uaVhnaCXcfBcGAyRnbTLQQXZXT9C+N7YPQpz6dyemGh1 y2sP53OXT/DC4laKof7QZeIgqWB/MGmxPzkbTZv90pE1/fyGMpckXgqC/jVZ0hOhh7tW 6FXA0Jp4l6Rm4aONK4r8IJERLff/8RPoXE5wY3aiiGygo18+DIGiP243mmBBnvWEQiGD X4Og== X-Gm-Message-State: APjAAAWO5plaVSxqkfgYJ4xOoYx/QzEHbeJ3n48yP4Sj0x8Ty10fhc/b 0D7PjZjypEREHYYMmGSy2ziOkIkLJ7nccO/gF50F1exQmGOkorfTvJ1WwmGxrKcXCLGChh4HtBP niEG37BJXK8epNsWg52Ug2B2CyuoRQNlYmLFM5WPwF7TGZP0z96+mLH3cbe2ndb81U5nOLLUcqg == X-Google-Smtp-Source: APXvYqzqLKY8WGtiZ8L1vtX28etY/4GBC+U4H5VZZKEHymYQ2veajrIHycL2KbYbP/Kynuhe+exe/NSbJLlMblcMSyM= X-Received: by 2002:a63:ba05:: with SMTP id k5mr653594pgf.158.1580949718327; Wed, 05 Feb 2020 16:41:58 -0800 (PST) Date: Wed, 5 Feb 2020 16:41:08 -0800 In-Reply-To: <20200206004108.261317-1-emilyshaffer@google.com> Message-Id: <20200206004108.261317-16-emilyshaffer@google.com> Mime-Version: 1.0 References: <20200206004108.261317-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v6 15/15] bugreport: summarize contents of alternates file From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In some cases, it could be that the user is having a problem with an object which isn't present in their normal object directory. We can get a hint that that might be the case by examining the list of alternates where their object may be stored instead. Since paths to alternates may be sensitive, we'll instead count how many alternates have been specified and note how many of them exist or are broken. While object-cache.h describes a function "foreach_alt_odb()", this function does not provide information on broken alternates, which are skipped over in "link_alt_odb_entry()". Since the goal is to identify missing alternates, we can gather the contents of .git/objects/info/alternates manually. Signed-off-by: Emily Shaffer --- Documentation/git-bugreport.txt | 1 + bugreport.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index a21d081616..e870900c80 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -35,6 +35,7 @@ The following information is captured automatically: - The number of loose objects in the repository - The number of packs and packed objects in the repository - A list of the contents of .git/objects/info (or equivalent) + - The number of valid and invalid alternates OPTIONS ------- diff --git a/bugreport.c b/bugreport.c index 3a3d33f680..9d4d5c8e6f 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 @@ -346,6 +388,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) {