From patchwork Fri Oct 25 02:51:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211245 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 32AF0112C for ; Fri, 25 Oct 2019 02:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 103B221929 for ; Fri, 25 Oct 2019 02:51:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nYLD6X/T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391145AbfJYCvm (ORCPT ); Thu, 24 Oct 2019 22:51:42 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:34423 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCvm (ORCPT ); Thu, 24 Oct 2019 22:51:42 -0400 Received: by mail-pf1-f202.google.com with SMTP id a1so785723pfn.1 for ; Thu, 24 Oct 2019 19:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WDh11je03PVm+Rfs/Oo/s+eIqA68pYQ1aARLmtbselo=; b=nYLD6X/TaBqpsCsWFlG678JHUhNkpKZByw4ZTxCeD6ydd5261yQZ/Vues/ELB9jDVT TlLrRKZb9F28HJ7gc+XaoCLdcWnFyrr2gkSh70ZRD+8zeW3nt/cBoKr+K/MtO+ptT3jp eEsffb4YOUpJfUjYBsybte4joYyObmxZCsLSp75fGWWBADtF6rMRVFmu3uXI0THgAlAi P+TLKnXU6ddE6PX+pY7u5u7RAI+PlEsz50zJDazUYA2uUpP8LUsObgOJyYVDRfEJzo+Y 82LCVq34sIgesGMKKzAT+U3ACWbLJ8CGwwEC5TP27EBp7F2qYqUgMgINWWWuGLZ43rMK wp9A== 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=WDh11je03PVm+Rfs/Oo/s+eIqA68pYQ1aARLmtbselo=; b=THwKKQMxTE+p5XbggFOxXVxFCDYiv68n4nS9MUk7ZpbAPEuWsc/ZOD3z4qpRUtgfm/ szNFCrdL40JlW+LiWbDPYfY/A4P1/wIcSNC7abbtQAaGSViSxTYPW5XxeRCqGYzYhjFH BrmMzg52Wap24YM4P/SD85Y0mBNPuN/mnkVhArzSKUgMWE5bzFZqKLvs9om55do+9BD6 +rJPDq4UrDbhGFDTyC20DHHkPdEC+g2DGUnFMJMPapmlMsiNEhBmp0pPdI0cSwjeW4rm Uuw3B/r2IeLKUx7PA2QoQIWW2qrGMkkuiy9lUSMUT8Kymd3bEtfBzSBKa9uAcdCcMjP5 IoSw== X-Gm-Message-State: APjAAAW59OLe45OYx5InYiwzIXm4FSIiEm4DU5bcHWtDqOqlMN2pjyzq +5E/4n3LLwEs4zlB2EVtObyZ9tQrJ5iLukR0wlHjo3evtdmQinPvZnF+1qM/KvZMSpawcnqWIjS stfLx9nm1bMv2f4HXr71bXNgJZ9QeRN2Nt4PIecRnlN03mlObm4wJx2qAb+9y4dWmBTNChjpJgg == X-Google-Smtp-Source: APXvYqwHPdgbicYt9NfQTm7joOYK294H2w0//aLNf8NyNzBLLS1n2LBZ9+8yUPupNJSHg6apihUCjwRNd1TwmN9TRXw= X-Received: by 2002:a65:464b:: with SMTP id k11mr1470817pgr.263.1571971900942; Thu, 24 Oct 2019 19:51:40 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:21 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 1/9] 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 --- Makefile | 1 + builtin.h | 1 + builtin/bugreport.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ git.c | 1 + 4 files changed, 53 insertions(+) create mode 100644 builtin/bugreport.c diff --git a/Makefile b/Makefile index 58b92af54b..132e2a52da 100644 --- a/Makefile +++ b/Makefile @@ -1039,6 +1039,7 @@ BUILTIN_OBJS += builtin/archive.o BUILTIN_OBJS += builtin/bisect--helper.o BUILTIN_OBJS += builtin/blame.o BUILTIN_OBJS += builtin/branch.o +BUILTIN_OBJS += builtin/bugreport.o BUILTIN_OBJS += builtin/bundle.o BUILTIN_OBJS += builtin/cat-file.o BUILTIN_OBJS += builtin/check-attr.o diff --git a/builtin.h b/builtin.h index 5cf5df69f7..c6373d3289 100644 --- a/builtin.h +++ b/builtin.h @@ -135,6 +135,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix); int cmd_bisect__helper(int argc, const char **argv, const char *prefix); int cmd_blame(int argc, const char **argv, const char *prefix); int cmd_branch(int argc, const char **argv, const char *prefix); +int cmd_bugreport(int argc, const char **argv, const char *prefix); int cmd_bundle(int argc, const char **argv, const char *prefix); int cmd_cat_file(int argc, const char **argv, const char *prefix); int cmd_checkout(int argc, const char **argv, const char *prefix); diff --git a/builtin/bugreport.c b/builtin/bugreport.c new file mode 100644 index 0000000000..2ef16440a0 --- /dev/null +++ b/builtin/bugreport.c @@ -0,0 +1,50 @@ +#include "builtin.h" +#include "stdio.h" +#include "strbuf.h" +#include "time.h" + +int get_bug_template(struct strbuf *template) +{ + const char template_text[] = +"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 send.\n"; + + strbuf_reset(template); + strbuf_add(template, template_text, strlen(template_text)); + return 0; +} + +int cmd_bugreport(int argc, const char **argv, const char *prefix) +{ + struct strbuf buffer = STRBUF_INIT; + struct strbuf report_path = STRBUF_INIT; + FILE *report; + time_t now = time(NULL); + + strbuf_addstr(&report_path, "git-bugreport-"); + strbuf_addftime(&report_path, "%F", gmtime(&now), 0, 0); + strbuf_addstr(&report_path, ".txt"); + + report = fopen_for_writing(report_path.buf); + + get_bug_template(&buffer); + strbuf_write(&buffer, report); + + fclose(report); + + launch_editor(report_path.buf, NULL, NULL); + return 0; +} diff --git a/git.c b/git.c index ce6ab0ece2..2d6a64f019 100644 --- a/git.c +++ b/git.c @@ -473,6 +473,7 @@ static struct cmd_struct commands[] = { { "bisect--helper", cmd_bisect__helper, RUN_SETUP }, { "blame", cmd_blame, RUN_SETUP }, { "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG }, + { "bugreport", cmd_bugreport, RUN_SETUP }, { "bundle", cmd_bundle, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "cat-file", cmd_cat_file, RUN_SETUP }, { "check-attr", cmd_check_attr, RUN_SETUP }, From patchwork Fri Oct 25 02:51:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211247 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 A8CEE139A for ; Fri, 25 Oct 2019 02:51:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D77A21D71 for ; Fri, 25 Oct 2019 02:51:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SfhNY0Oy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391177AbfJYCvq (ORCPT ); Thu, 24 Oct 2019 22:51:46 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:56525 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCvq (ORCPT ); Thu, 24 Oct 2019 22:51:46 -0400 Received: by mail-pg1-f202.google.com with SMTP id u4so619236pgp.23 for ; Thu, 24 Oct 2019 19:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xvl0O5lJZZJyQGcddpD2RGvFZUD/xOX/vy5BRm8zyC4=; b=SfhNY0Oyw2uczWnV3KndeYZXa81PZfA7EY0V4eOnGSKYb38Xds1kOaaCeP9/3PBHn0 lwX+sZe1T3SrwSTBID+hU59XLlIGkomE3xDv/xOusClgpLprOS9Garjzwg8XpcD/f3Wl cb0MlosdPcxBOUGroFlerrE3h5vXAVFZ9WwmutSjF1TBCxkUksI8b+cXJDXeD+NqCIW4 7lbkcySJtXU0F3A1o5YpoAkUUMPX8T+SxRMNOBYi0bczbv3cMcT45elIq1kmr8oQBRke rl9uFzDS1sQE1UE1kzpQTI4tk8KQUQx1eC68v54UtU391+/5eYM72eKypY36JGDPtcIn sFTg== 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=xvl0O5lJZZJyQGcddpD2RGvFZUD/xOX/vy5BRm8zyC4=; b=Sz0RdQ5KwT2nbBmHu79eogsUHP+fWtuaKt6hlUILiTxnEVZeQKXekB4nBZP2kE27GY 3/jXMtSKQy3tPibMWbdJrWdMhkL2+Z4YZkISvpalhu6t5xfbX6YIQQNztIT3WUx/4Zf1 IvIrodJe3VFDHW0OgDlFladOJF1uK7va+LmC07vKwHwMh8OQ5ScsccnzizQxI+CfQ7BV rIe/GkAKZ5JSFOnkJ1euehmdJCBt7WB3y+EmWhNfM+Upj6Pri/6uLMj3mq5knEZXtz4N +8x2pTIEZi59KZVuioKMGUXH2jIx7GV1GpPT4BxunLc6OsZUy7Pn5+pzU3MRPrWETR+0 hQ8Q== X-Gm-Message-State: APjAAAW+iVHRRXXGy9CJ4ItUtXq4ULBr7qjz29LDwBlkpTvkehbWNzf9 hbNC4d/XYGcRxoHXci433rjKAj9N1JVPiirf3bIGPiEfKBqb9R97vb0UzHaHIK0ObN6u0c+xIHo dTlSILWdc8Yf48Av9nmkz4eSKatGuE7+rvmFA2ZYjKDXD4aBud0EClhBZZVPMiI31BteSHwebpg == X-Google-Smtp-Source: APXvYqz9dApX1x44AC/ynBFqoWh+Ht9JNUvLNUTvujFYuSHaNYVTnUvXAxwP8Ysb5kGqrTbxpVsE/LPlYjPLN3BTky4= X-Received: by 2002:a63:d809:: with SMTP id b9mr1443476pgh.143.1571971904673; Thu, 24 Oct 2019 19:51:44 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:22 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 2/9] bugreport: generate config whitelist based on docs 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 Add a new step to the build to generate a whitelist of git-config variables which are appropriate to include in the output of git-bugreport. New variables can be added to the whitelist by annotating their documentation in Documentation/config with the line "// bugreport-include". 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 blacklisting of configuration keys is imperfect and prone to false negatives; given the nature of the information which can be leaked, a whitelist is more reliable. In order to prevent staleness of the whitelist, add a mechanism to generate the whitelist from annotations in the config documentation, where contributors are already used to documenting their new config keys. Additionally, add annotations to the sendemail config documentation in order to demonstrate a proof of concept. Signed-off-by: Emily Shaffer --- .gitignore | 1 + Documentation/config/sendemail.txt | 68 +++++++++++++------------- Makefile | 9 +++- bugreport-generate-config-whitelist.sh | 4 ++ 4 files changed, 47 insertions(+), 35 deletions(-) create mode 100755 bugreport-generate-config-whitelist.sh diff --git a/.gitignore b/.gitignore index 89b3b79c1a..055a84c4a8 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/config/sendemail.txt b/Documentation/config/sendemail.txt index 0006faf800..69f3e4f219 100644 --- a/Documentation/config/sendemail.txt +++ b/Documentation/config/sendemail.txt @@ -1,63 +1,63 @@ -sendemail.identity:: +sendemail.identity:: // bugreport-exclude A configuration identity. When given, causes values in the 'sendemail.' subsection to take precedence over values in the 'sendemail' section. The default identity is the value of `sendemail.identity`. -sendemail.smtpEncryption:: +sendemail.smtpEncryption:: // bugreport-include See linkgit:git-send-email[1] for description. Note that this setting is not subject to the 'identity' mechanism. -sendemail.smtpssl (deprecated):: +sendemail.smtpssl (deprecated):: // bugreport-exclude Deprecated alias for 'sendemail.smtpEncryption = ssl'. -sendemail.smtpsslcertpath:: +sendemail.smtpsslcertpath:: // bugreport-exclude Path to ca-certificates (either a directory or a single file). Set it to an empty string to disable certificate verification. -sendemail..*:: +sendemail..*:: // 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 `sendemail.identity`. -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.aliasesFile:: // bugreport-exclude +sendemail.aliasFileType:: // bugreport-exclude +sendemail.annotate:: // bugreport-include +sendemail.bcc:: // bugreport-include +sendemail.cc:: // bugreport-include +sendemail.ccCmd:: // bugreport-include +sendemail.chainReplyTo:: // bugreport-include +sendemail.confirm:: // bugreport-include +sendemail.envelopeSender:: // bugreport-include +sendemail.from:: // bugreport-include +sendemail.multiEdit:: // bugreport-include +sendemail.signedoffbycc:: // bugreport-include +sendemail.smtpPass:: // bugreport-exclude +sendemail.suppresscc:: // bugreport-include +sendemail.suppressFrom:: // bugreport-include +sendemail.to:: // bugreport-include +sendemail.tocmd:: // bugreport-include +sendemail.smtpDomain:: // bugreport-include +sendemail.smtpServer:: // bugreport-include +sendemail.smtpServerPort:: // bugreport-include +sendemail.smtpServerOption:: // bugreport-include +sendemail.smtpUser:: // bugreport-exclude +sendemail.thread:: // bugreport-include +sendemail.transferEncoding:: // bugreport-include +sendemail.validate:: // bugreport-include +sendemail.xmailer:: // bugreport-include See linkgit:git-send-email[1] for description. -sendemail.signedoffcc (deprecated):: +sendemail.signedoffcc (deprecated):: // bugreport-exclude Deprecated alias for `sendemail.signedoffbycc`. -sendemail.smtpBatchSize:: +sendemail.smtpBatchSize:: // 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:: // 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 132e2a52da..78767ecdde 100644 --- a/Makefile +++ b/Makefile @@ -634,6 +634,10 @@ SCRIPT_PYTHON += git-p4.py SCRIPT_SH_GEN = $(patsubst %.sh,%,$(SCRIPT_SH)) SCRIPT_PERL_GEN = $(patsubst %.perl,%,$(SCRIPT_PERL)) SCRIPT_PYTHON_GEN = $(patsubst %.py,%,$(SCRIPT_PYTHON)) +SCRIPT_DEPENDENCIES = git-bugreport-config-whitelist + +$(SCRIPT_DEPENDENCIES): Documentation/config/*.txt + sh bugreport-generate-config-whitelist.sh # Individual rules to allow e.g. # "make -C ../.. SCRIPT_PERL=contrib/foo/bar.perl build-perl-script" @@ -651,17 +655,20 @@ install-perl-script: $(SCRIPT_PERL_GEN) install-python-script: $(SCRIPT_PYTHON_GEN) $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' -.PHONY: clean-perl-script clean-sh-script clean-python-script +.PHONY: clean-perl-script clean-sh-script clean-python-script clean-script-dependencies clean-sh-script: $(RM) $(SCRIPT_SH_GEN) clean-perl-script: $(RM) $(SCRIPT_PERL_GEN) clean-python-script: $(RM) $(SCRIPT_PYTHON_GEN) +clean-script-dependencies: + $(RM) $(SCRIPT_DEPENDENCIES) SCRIPTS = $(SCRIPT_SH_GEN) \ $(SCRIPT_PERL_GEN) \ $(SCRIPT_PYTHON_GEN) \ + $(SCRIPT_DEPENDENCIES) \ git-instaweb ETAGS_TARGET = TAGS diff --git a/bugreport-generate-config-whitelist.sh b/bugreport-generate-config-whitelist.sh new file mode 100755 index 0000000000..ca6b232024 --- /dev/null +++ b/bugreport-generate-config-whitelist.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +grep -RhPo ".*(?=:: \/\/ bugreport-include)" Documentation/config \ + >git-bugreport-config-whitelist From patchwork Fri Oct 25 02:51:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211249 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 104B7139A for ; Fri, 25 Oct 2019 02:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2AE021D71 for ; Fri, 25 Oct 2019 02:51:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rS2x5Uw8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391197AbfJYCvt (ORCPT ); Thu, 24 Oct 2019 22:51:49 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:54377 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCvt (ORCPT ); Thu, 24 Oct 2019 22:51:49 -0400 Received: by mail-pl1-f202.google.com with SMTP id j9so546422plk.21 for ; Thu, 24 Oct 2019 19:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xW+gXInzmEOsyML6gAJy6Y8/K2eeTRCnCrci0ntYOpc=; b=rS2x5Uw8dssps7hbCkeUiWZo4Z1X8qVcZXzg3m+Q78laujhoroUDYGGo0vDyJjNnu8 a6gSZog/WDIXQQ95B3mdyHrkAATzxCcWsYbGUB5zAvxbMtrL+6Z1oqBctbOaHugY9Pm0 gFwhM6tro1YHMxpq1X6jDLGsbMptQ0apuLl+Y5xWqeT8w9bjxZcEsonss02KxT3jHFzv A4i9K5fwtBK7MGFTA8JxTBCzIpYFleCKBbn++yGbp0JdUXczfuj2eJvKAuQXMj5fVY/3 0JpNKM6LmNszVYTGUIzmKo+LiLoOuXHvPJxw5YIN8LWjE+X2GgcyO0wS8bYEAU+cha51 uK/g== 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=xW+gXInzmEOsyML6gAJy6Y8/K2eeTRCnCrci0ntYOpc=; b=dRHL0+QfceCrw33yjRfe7XjaUObrgZQDPGbBIk47oQlZP9VrDxwyVbybncl/1HqYSh aE8curO0XmfR4OfIEET7Z2AWIvGRYpqzT85wkv1O+k1HXqtaQw0bAzXnbyCUybJTJi92 Lb1CWHfUhATQgYpQCv9aCPDdke4uV6ipWKcQZ94fHIGgIFUluI4GFedpSbsbMra/srIW y36hjjIXKpCRHUaeyEopcvMFpVmC/cx8FifNLnt3F5ZMvyjMfBoDxQsjrQ2eu8FKQM9U 1HAeHA7JzVs5KoyQ00UK4L7hElibZRksBDdgUm5vW5OWZd9N/RJN9KFihL7iNr+eEvx7 o2jg== X-Gm-Message-State: APjAAAVE4HHkbx6ytxdUcl/2oJVVEXdkH6X/515rTLA1RIsbRLsNQSpe o2EJCOKqxxEOmvnJytisH8n1fL5Iv5ubd18vBMXFJP2UGFOfwNGPpGAmTRatzptAn0o3dzQdsfH UWFCRKwWhvF9XDe4NJcfhYKn2WQagVh3hIOvXv7tU5e7ToTlI14QEomzu2QFpd+z9irAQEEn4og == X-Google-Smtp-Source: APXvYqzwlXdOZqOzt87tzyjRhJuIq+ANKK9k/S+4g1rS/cpHyQNq2JqG+SBdXT7eSFzp662kOWYODNRXLhD/suBlCqA= X-Received: by 2002:a63:f050:: with SMTP id s16mr1427104pgj.261.1571971908571; Thu, 24 Oct 2019 19:51:48 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:23 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 3/9] bugreport: add version and system information 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 how to collect the Git, curl, and ldd versions, as well as the uname string. Learning the uname and versions in the user's environment will enable us to reproduce behavior reported by the user; the versions will also give us a good starting place while bisecting a newly introduced bug. Put this functionality in a library, so that other commands can easily include this debug info if necessary. Signed-off-by: Emily Shaffer --- Makefile | 1 + bugreport.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ bugreport.h | 7 ++++++ builtin/bugreport.c | 13 +++++++++++ 4 files changed, 76 insertions(+) create mode 100644 bugreport.c create mode 100644 bugreport.h diff --git a/Makefile b/Makefile index 78767ecdde..045b22cb67 100644 --- a/Makefile +++ b/Makefile @@ -844,6 +844,7 @@ LIB_OBJS += bisect.o LIB_OBJS += blame.o LIB_OBJS += blob.o LIB_OBJS += branch.o +LIB_OBJS += bugreport.o LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o diff --git a/bugreport.c b/bugreport.c new file mode 100644 index 0000000000..ada54fe583 --- /dev/null +++ b/bugreport.c @@ -0,0 +1,55 @@ +#include "cache.h" + +#include "bugreport.h" +#include "help.h" +#include "run-command.h" +#include "version.h" + +void get_system_info(struct strbuf *sys_info) +{ + struct child_process cp = CHILD_PROCESS_INIT; + struct strbuf std_out = STRBUF_INIT; + + strbuf_reset(sys_info); + + // get git version from native cmd + strbuf_addstr(sys_info, "git version: "); + strbuf_addstr(sys_info, git_version_string); + strbuf_complete_line(sys_info); + + // system call for other version info + argv_array_push(&cp.args, "uname"); + argv_array_push(&cp.args, "-a"); + capture_command(&cp, &std_out, 0); + + strbuf_addstr(sys_info, "uname -a: "); + strbuf_addbuf(sys_info, &std_out); + strbuf_complete_line(sys_info); + + argv_array_clear(&cp.args); + strbuf_reset(&std_out); + + + argv_array_push(&cp.args, "curl-config"); + argv_array_push(&cp.args, "--version"); + capture_command(&cp, &std_out, 0); + + strbuf_addstr(sys_info, "curl-config --version: "); + strbuf_addbuf(sys_info, &std_out); + strbuf_complete_line(sys_info); + + argv_array_clear(&cp.args); + strbuf_reset(&std_out); + + + argv_array_push(&cp.args, "ldd"); + argv_array_push(&cp.args, "--version"); + capture_command(&cp, &std_out, 0); + + strbuf_addstr(sys_info, "ldd --version: "); + strbuf_addbuf(sys_info, &std_out); + strbuf_complete_line(sys_info); + + argv_array_clear(&cp.args); + strbuf_reset(&std_out); +} diff --git a/bugreport.h b/bugreport.h new file mode 100644 index 0000000000..ba216acf3f --- /dev/null +++ b/bugreport.h @@ -0,0 +1,7 @@ +#include "strbuf.h" + +/** + * Adds the Git version, `uname -a`, and `curl-config --version` to sys_info. + * The previous contents of sys_info will be discarded. + */ +void get_system_info(struct strbuf *sys_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 2ef16440a0..7232d31be7 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "bugreport.h" #include "stdio.h" #include "strbuf.h" #include "time.h" @@ -27,6 +28,13 @@ int get_bug_template(struct strbuf *template) return 0; } +void add_header(FILE *report, const char *title) +{ + struct strbuf buffer = STRBUF_INIT; + strbuf_addf(&buffer, "\n\n[%s]\n", title); + strbuf_write(&buffer, report); +} + int cmd_bugreport(int argc, const char **argv, const char *prefix) { struct strbuf buffer = STRBUF_INIT; @@ -43,6 +51,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_bug_template(&buffer); strbuf_write(&buffer, report); + // add other contents + add_header(report, "System Info"); + get_system_info(&buffer); + strbuf_write(&buffer, report); + fclose(report); launch_editor(report_path.buf, NULL, NULL); From patchwork Fri Oct 25 02:51:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211251 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 E62F7112C for ; Fri, 25 Oct 2019 02:51:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C678121D71 for ; Fri, 25 Oct 2019 02:51:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="a5LalvxN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391209AbfJYCvx (ORCPT ); Thu, 24 Oct 2019 22:51:53 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:45245 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCvx (ORCPT ); Thu, 24 Oct 2019 22:51:53 -0400 Received: by mail-qt1-f201.google.com with SMTP id n34so655369qta.12 for ; Thu, 24 Oct 2019 19:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pRrgZ12LQ5OWBU3mb17YcqPzidyZOAWK/eh1o+ayz7k=; b=a5LalvxN6d2dW4zG1oY3xWF05JS8V7hzxXOsZdXEB6U8eK2AYY/B0Y4Vmty9kHASMT 5R4/Pph19b9jXvoD5nf1xSopM7U2lTKvqIktOYtyCAK6UJnhprujyjLoucOVoRrIy1gx MkwqXN76TUmWf2SqgI5s3sRQQbm4gMBURyt38dR5732q+kGE8EmhN4/C6C2w4CNeiPbb Olm6F2nyiLIn48bK0AvRXx+sGvQCdaoJndh9pOvtzYv7gtgO87zn9l0ZA30ryWcls9cz momUsbPw6uAYzOWnpzyomaxFzjtJ8TnIs2ke9PetGKktph/S90vgg2ZZD/WIN32YXTj1 n/Cg== 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=pRrgZ12LQ5OWBU3mb17YcqPzidyZOAWK/eh1o+ayz7k=; b=VH3/Z3G3xtdBaLC3Dmb+nD6bRcYRPzidZCkuGsuZXf6+iD/Q1ZrrjVpbtsTiV7FUrJ k+RRzMWUzh0jArDbzR7Ht1kPdDybacYAMavfsxSXnGTprG5ALKq1pu9fDJDQv3U04v3l ph567VaturS9h6SB+cpxfYR4lTqO0GTM6vNF2rS8olDIsz8f9XP+xczVBrgCpTJocjwq O2NA4G7flBj6/TG8cmbI5W9c0St3WtFnXeZi7tSm6p7waTbIguZwzxVMteRMg6R9G8Sm T+P5mbp/D3Jd08YvP/LVa5glMKjbX6hsDHvgr5VYYdnB8aJ9GbOcHNkSjeKeRbGYkNiI OfKA== X-Gm-Message-State: APjAAAUmQrsU9gLeAKEQGS4fi72Rq7e0yKuuY5eplru3r4yv8iddc2UM kfl/UlIFM1CngzSDiydL6QYzKJ16aGbDbYS06U11+aE08xeLIeTRKaNWBd+UM5k2Pb2vcwZTFDF lJCEVeLfsd1xXou4LJ3qfUlTHqAT/iIjrhDQZsOokNfuOk1JFfqgocDwMF8aM6r14BAqFP1yr9g == X-Google-Smtp-Source: APXvYqwWz49wo7ikqWqk6DivbQQJjKYKD9QhqKXU6r3aYmjrZOP0ZQALsC4saw48k4D7A0q3Y4ixbYoC1D5o46WHrCE= X-Received: by 2002:aed:3b54:: with SMTP id q20mr910981qte.151.1571971912266; Thu, 24 Oct 2019 19:51:52 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:24 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 4/9] bugreport: add config values from whitelist 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 'git-bugreport-config-whitelist'. 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. Reading the whitelist into memory and sorting it saves us time - since git_config_bugreport() is called for every option the user has configured, limiting the file IO to one open/read/close and performing option lookup in sublinear time is a useful optimization. Signed-off-by: Emily Shaffer --- bugreport.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ bugreport.h | 7 +++++++ builtin/bugreport.c | 4 ++++ 3 files changed, 61 insertions(+) diff --git a/bugreport.c b/bugreport.c index ada54fe583..afa4836ab1 100644 --- a/bugreport.c +++ b/bugreport.c @@ -1,10 +1,24 @@ #include "cache.h" #include "bugreport.h" +#include "config.h" +#include "exec-cmd.h" #include "help.h" #include "run-command.h" #include "version.h" +/** + * A sorted list of config options which we will add to the bugreport. Managed + * by 'gather_whitelist(...)'. + */ +struct string_list whitelist = STRING_LIST_INIT_DUP; +struct strbuf configs_and_values = STRBUF_INIT; + +// git version --build-options +// uname -a +// curl-config --version +// ldd --version +// echo $SHELL void get_system_info(struct strbuf *sys_info) { struct child_process cp = CHILD_PROCESS_INIT; @@ -53,3 +67,39 @@ void get_system_info(struct strbuf *sys_info) argv_array_clear(&cp.args); strbuf_reset(&std_out); } + +void gather_whitelist(struct strbuf *path) +{ + struct strbuf tmp = STRBUF_INIT; + strbuf_read_file(&tmp, path->buf, 0); + string_list_init(&whitelist, 1); + string_list_split(&whitelist, tmp.buf, '\n', -1); + string_list_sort(&whitelist); +} + +int git_config_bugreport(const char *var, const char *value, void *cb) +{ + if (string_list_has_string(&whitelist, var)) { + strbuf_addf(&configs_and_values, + "%s : %s\n", + var, value); + } + + return 0; +} + +void get_whitelisted_config(struct strbuf *config_info) +{ + struct strbuf path = STRBUF_INIT; + + strbuf_addstr(&path, git_exec_path()); + strbuf_addstr(&path, "/git-bugreport-config-whitelist"); + + gather_whitelist(&path); + strbuf_init(&configs_and_values, whitelist.nr); + + git_config(git_config_bugreport, NULL); + + strbuf_reset(config_info); + strbuf_addbuf(config_info, &configs_and_values); +} diff --git a/bugreport.h b/bugreport.h index ba216acf3f..7413e7e1be 100644 --- a/bugreport.h +++ b/bugreport.h @@ -5,3 +5,10 @@ * The previous contents of sys_info will be discarded. */ void get_system_info(struct strbuf *sys_info); + +/** + * Adds the values of the config items listed in + * 'git-bugreport-config-whitelist' to config_info. The previous contents of + * config_info will be discarded. + */ +void get_whitelisted_config(struct strbuf *sys_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 7232d31be7..70fe0d2b85 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -56,6 +56,10 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_system_info(&buffer); strbuf_write(&buffer, report); + add_header(report, "Whitelisted Config"); + get_whitelisted_config(&buffer); + strbuf_write(&buffer, report); + fclose(report); launch_editor(report_path.buf, NULL, NULL); From patchwork Fri Oct 25 02:51:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211253 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 5EC42112C for ; Fri, 25 Oct 2019 02:51:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E39D21D71 for ; Fri, 25 Oct 2019 02:51:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tEQKronj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391226AbfJYCv5 (ORCPT ); Thu, 24 Oct 2019 22:51:57 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:33365 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCv5 (ORCPT ); Thu, 24 Oct 2019 22:51:57 -0400 Received: by mail-pg1-f202.google.com with SMTP id g187so661565pgc.0 for ; Thu, 24 Oct 2019 19:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bP6thc16j4zFuCStHrLp95eyVnwkGKKniBg+7jQB8PU=; b=tEQKronj8D9JGjbsw+6qWfvFJKyQXrehpQ3p714vWFwdBLWhPDZvAVGpfZaJGHmQz9 ipV+Ws05cyXP/2+B1zebWncsmmEcdnFre7WOHdFq4LHRIDgb08BCOeThFZ/5097dXRgn 18+4B22kWLiOwqtOD3pBtW7tuNYL1usRSomg+mIPXT4VeGrbLOFtjOanwsVQ8MzVIRjg /vZd+05T1pKmWO5DQwnud7SNYpHP4mHWqtkMuRkFmKeZTXRhPoRBCuLp/9S2DagtqLt8 DPwjq6CvUpaF4mvoy2kA/21lPxft5maMK3W44CWMOroIh8Cps8LNIycPqZQHPAyZmA4w 38jQ== 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=bP6thc16j4zFuCStHrLp95eyVnwkGKKniBg+7jQB8PU=; b=CSZkWpij82rxNBDoJMC3DpU02NF4LOdvPc7eUNxkI4MsVOHdl/NIPjl64Ms/60CDtX SlPIVWDxsUmmBbVxU5WrBAUbP+lQlHNWgSVtCsx8lT5YJ6c3Ck7/R1AZvzFnTDvSWRxG J7r1MlT/+TRfeDsSemPQbI1EpQM7o9bqQzkZzmT9xdwUgmCcnDVJ2r/UDIhm9aYwokbK q2WSdyKPhf8EBnFWQrABtiqOCP4rKsrrBJpEzA71A6RV/7PSUS9jtxo0EAOLWw+YNima WKzaDnmvXhNiwbBsgMESZmWJBwIDBn5bz7UfoZkJJ7C9VyffAfwXfns0xDS9ovKdNfyX 4ShA== X-Gm-Message-State: APjAAAUUXAyzVtw+qoC7+X9sIFhGVN34Kziaul9gay96z26EikeBCuog U215lkI8j9m4EPF4SNpPqyOIBCt1lmNn5n1y+ujQYRTVmzHFW2rLvwv+nXSCtIuTv06mufOb3Qs UG71QVfM6X+1bFhP6ho6NVcZrEtWRZ1QJLCTzmx7IjbbzPzoxk5jTBwVY8KPRy8u6jW1uLLbE9w == X-Google-Smtp-Source: APXvYqxTRsL8OaBhevdbh+ccDVwSRAVwM8ZyBHXa4K0zjyxJAXNUHPI5x/1RY/HYMLWscQzJK5FxooN1olVyq5msMWk= X-Received: by 2002:a63:d26:: with SMTP id c38mr1476218pgl.84.1571971915917; Thu, 24 Oct 2019 19:51:55 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:25 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 5/9] 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 --- bugreport.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ bugreport.h | 6 ++++++ builtin/bugreport.c | 4 ++++ 3 files changed, 54 insertions(+) diff --git a/bugreport.c b/bugreport.c index afa4836ab1..9d7f44ff28 100644 --- a/bugreport.c +++ b/bugreport.c @@ -103,3 +103,47 @@ void get_whitelisted_config(struct strbuf *config_info) strbuf_reset(config_info); strbuf_addbuf(config_info, &configs_and_values); } + +void get_populated_hooks(struct strbuf *hook_info) +{ + /* + * Doesn't look like there is a list of all possible hooks; so below is + * a transcription of `git help hook`. + */ + 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; + + strbuf_reset(hook_info); + + 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); + } + } +} diff --git a/bugreport.h b/bugreport.h index 7413e7e1be..942a5436e3 100644 --- a/bugreport.h +++ b/bugreport.h @@ -12,3 +12,9 @@ void get_system_info(struct strbuf *sys_info); * config_info will be discarded. */ void get_whitelisted_config(struct strbuf *sys_info); + +/** + * Adds the paths to all configured hooks (but not their contents). The previous + * contents of hook_info will be discarded. + */ +void get_populated_hooks(struct strbuf *hook_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 70fe0d2b85..a0eefba498 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -60,6 +60,10 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_whitelisted_config(&buffer); strbuf_write(&buffer, report); + add_header(report, "Populated Hooks"); + get_populated_hooks(&buffer); + strbuf_write(&buffer, report); + fclose(report); launch_editor(report_path.buf, NULL, NULL); From patchwork Fri Oct 25 02:51:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211255 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 36F32139A for ; Fri, 25 Oct 2019 02:52:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1416E21929 for ; Fri, 25 Oct 2019 02:52:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Drrpnw2S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391249AbfJYCwB (ORCPT ); Thu, 24 Oct 2019 22:52:01 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:46485 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCwB (ORCPT ); Thu, 24 Oct 2019 22:52:01 -0400 Received: by mail-vk1-f202.google.com with SMTP id n124so228337vkg.13 for ; Thu, 24 Oct 2019 19:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=YCvff+85QpMKmKT6MzrF+anTyQpZ411O2Zun7SX3Zds=; b=Drrpnw2S6/MDa3s+UT+NazLihXtncicUf7E4xpUzI2LLzsO6o7Jlfc9xjDKYfERRGA ow7vb+m+3OQPr0+C+5bfSYTe6PxcjPwtO3MLWLUYFDZP6+m1b4QPKkpSjDT3B+XdwuDm +BCTP+5GpBJdHoBKTKZHzhAGkyy+l0fgqUsBBqrO4RKOynKBC8uXJMafWeyHKb8GcW/I UY/5hamY/xqu0SPTHywUtPGHgwhYBV9uYH8QCFAQzEtosgn9dyfLZYHTn0NoU3gkZSs/ J3Iqp5VafozoApAdxr1Dssem4c8pQKIoJAGfj8buAIW0Uf5hSjPAzmltZ42i05GxW9lE Himg== 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=YCvff+85QpMKmKT6MzrF+anTyQpZ411O2Zun7SX3Zds=; b=KJwAJtFKgkT6R77l5mwFliULS6RF6TXATSDwqy4qyDlNA+w9bhOHlPlV5nEznfJXox /c+68U3Wo0VDlK9MrDW0fAiRMXuxW8S0/sHO/Q12Npih8EeTHBRjvbD/nxVJcDuA6HRP 6oXaA4U4ncEXBWjqPwV30TbUnvRQLUWtQYo0ZSvTTUh3sJgGgsYj25fKsyvl7f7g7foG Q+qxQ0dehI8/v6CFTqs3XRs2uYPdbSJoenz7Mhca5osL7XHVyHP0WpegXz1+CmTqmevA HhThbRJw1xjXLPuWCskrDniTr2FbOvOZ4Ez9juJCCAx/lrVbBcfFkQewwSegGreHJ9Ft cwJQ== X-Gm-Message-State: APjAAAViCVzW2SpPVE9PtXf5qM+ThG4BrXwKrxos4QqFnJawfOG6Zmje rB/Om3M8qTx1ZRh43zpCSrqR33D7IJZV4MtzDzuAuvbnkiyTf4zQGWmIitO/m2VbMNOrcyWDyd6 EAFHCbd8aOCUkwRWrG77tlleL/GubKdKTv90e1HbzWnnakmSTHViMbJrWDnT8CfUM07DM3qlMkA == X-Google-Smtp-Source: APXvYqzlBxqfBWv/FZJm5AIyEW8PwgJ2rqUU6F6V0StbxC2+GQy+IrB0MXujkZWBeWSmRY8qORrq84K1yVppqfF36rg= X-Received: by 2002:a67:e316:: with SMTP id j22mr777093vsf.152.1571971919973; Thu, 24 Oct 2019 19:51:59 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:26 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 6/9] bugreport: count loose objects 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 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. Rather than directly invoking 'git-count-objects', which may sometimes fail unexpectedly on Git for Windows, manually count the contents of .git/objects. Additionally, since we may wish to inspect other directories' contents for bugreport in the future, put the directory listing into a helper function. Signed-off-by: Emily Shaffer --- bugreport.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ bugreport.h | 6 ++++ builtin/bugreport.c | 4 +++ 3 files changed, 82 insertions(+) diff --git a/bugreport.c b/bugreport.c index 9d7f44ff28..54e1d47103 100644 --- a/bugreport.c +++ b/bugreport.c @@ -5,8 +5,11 @@ #include "exec-cmd.h" #include "help.h" #include "run-command.h" +#include "strbuf.h" #include "version.h" +#include "dirent.h" + /** * A sorted list of config options which we will add to the bugreport. Managed * by 'gather_whitelist(...)'. @@ -147,3 +150,72 @@ void get_populated_hooks(struct strbuf *hook_info) } } } + +/** + * Fill 'contents' with the contents of the dir at 'dirpath'. + * If 'filter' is nonzero, the contents are filtered on d_type as 'type' - see + * 'man readdir'. opendir() doesn't take string length as an arg, so don't + * bother passing it in. + */ +void list_contents_of_dir(struct string_list *contents, struct strbuf *dirpath, + int filter, unsigned char type) +{ + struct dirent *dir = NULL; + DIR *dh = NULL; + + dh = opendir(dirpath->buf); + while (dh && (dir = readdir(dh))) { + if (!filter || type == dir->d_type) { + string_list_append(contents, dir->d_name); + } + } +} + + +void get_object_counts(struct strbuf *obj_info) +{ + struct child_process cp = CHILD_PROCESS_INIT; + struct strbuf std_out = STRBUF_INIT; + + argv_array_push(&cp.args, "count-objects"); + argv_array_push(&cp.args, "-vH"); + cp.git_cmd = 1; + capture_command(&cp, &std_out, 0); + + strbuf_reset(obj_info); + strbuf_addstr(obj_info, "git-count-objects -vH:\n"); + strbuf_addbuf(obj_info, &std_out); +} + +void get_loose_object_summary(struct strbuf *obj_info) +{ + struct strbuf dirpath = STRBUF_INIT; + struct string_list subdirs = STRING_LIST_INIT_DUP; + struct string_list_item *subdir; + + strbuf_reset(obj_info); + + strbuf_addstr(&dirpath, get_object_directory()); + strbuf_complete(&dirpath, '/'); + + list_contents_of_dir(&subdirs, &dirpath, 1, DT_DIR); + + for_each_string_list_item(subdir, &subdirs) + { + struct strbuf subdir_buf = STRBUF_INIT; + struct string_list objects = STRING_LIST_INIT_DUP; + + /* + * Only interested in loose objects - so dirs named with the + * first byte of the object ID + */ + if (strlen(subdir->string) != 2 || !strcmp(subdir->string, "..")) + continue; + + strbuf_addbuf(&subdir_buf, &dirpath); + strbuf_addstr(&subdir_buf, subdir->string); + list_contents_of_dir(&objects, &subdir_buf, 0, 0); + strbuf_addf(obj_info, "%s: %d objects\n", subdir->string, + objects.nr); + } +} diff --git a/bugreport.h b/bugreport.h index 942a5436e3..09ad0c2599 100644 --- a/bugreport.h +++ b/bugreport.h @@ -18,3 +18,9 @@ void get_whitelisted_config(struct strbuf *sys_info); * contents of hook_info will be discarded. */ void get_populated_hooks(struct strbuf *hook_info); + +/** + * Adds the output of `git count-object -vH`. The previous contents of hook_info + * will be discarded. + */ +void get_loose_object_summary(struct strbuf *obj_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index a0eefba498..b2ab194207 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -64,6 +64,10 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_populated_hooks(&buffer); strbuf_write(&buffer, report); + add_header(report, "Object Counts"); + get_loose_object_summary(&buffer); + strbuf_write(&buffer, report); + fclose(report); launch_editor(report_path.buf, NULL, NULL); From patchwork Fri Oct 25 02:51:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211257 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 773A8139A for ; Fri, 25 Oct 2019 02:52:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 560F221D71 for ; Fri, 25 Oct 2019 02:52:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Oeo1Amxb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391266AbfJYCwE (ORCPT ); Thu, 24 Oct 2019 22:52:04 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:39415 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCwE (ORCPT ); Thu, 24 Oct 2019 22:52:04 -0400 Received: by mail-pf1-f202.google.com with SMTP id l20so776773pff.6 for ; Thu, 24 Oct 2019 19:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=djyI6SNlQ0jDLXCD3DOue9Fp7Psc2/wAxoMej5JQWjI=; b=Oeo1AmxbP8dRMTaljvpr+2ulSQrr3cdxw3Vs82WEgyW2UEg0WCdRZay1ddrNM+7O7q sZ/vhkpGgcbWafca8V3Rp6FFFPGffmD/iKRGc5e6lIrB20kNIvhrM3pNmGLO0sYfe3uH Bg63n6Ix1raxxUmd8/TlOuRStO28wdiXip2AafvBnqXRhWlZ43dx2FxYcYzMUJx5QHxM 8V7rijEFov8pn0awu830nxLIeVtl1Nvpkfsl6uouj+rcZzksUytI5TBQlLXnuv1kbOt3 7UFFuEkIrbPIYemt4mvDHnVNgMa6iTU7b5krGyYWo2T9shXbHJOrv56uDDR5EFd5CBLD qkzw== 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=djyI6SNlQ0jDLXCD3DOue9Fp7Psc2/wAxoMej5JQWjI=; b=DQRkra1GBUaDJ6CyNtKjbYLnV6CAjzV/mSAl+VbkkgMHop+XQBNaG756i9VlxKSSsc iSzLBg7unnxk4rVnID9vRVO8WCUxLN9Yu+rCeKN0TkyRbAw+B8enWsYr5SkcDIj0fjbS jWYnOWcfe6utept0LaT6lBCIiyLJQYmAI/Qry11jSkt2JBR3IsSNo8dazKEsvgFSywsT Jd3xcHy5/cKaLgxrjgym2cxPgLWDc1Mee6lUuh1LsUjQt6GUV8YGc6ShB/uxQBgpCEsY vX3IJNVe8FPXKllCicsI5k0ngM+19ArMETLU9d9UIChVj0sbvXmQG//hjg7WHyEVRzBT 5ueQ== X-Gm-Message-State: APjAAAW7zR/wJLKnPL5GH9O3xklUci7parJvv/p4fAcp7S2bCxPPlUvl GJs4+J2vlh0od9Fo52mrC07S4WX6lQqEaZ7mzQk4LoX2+LiUwiutsGqpvnWDDwBC4CySI7BTu+b 7PxGk/QHGGK1nIOeP5otvoUjpP8ih8qh7mkO4oTvghSRfR/j4PivT8rDYxrr1Sd0fgWJukvsnFA == X-Google-Smtp-Source: APXvYqxteAZHBLlOzNCWnLra/tP7eq9hdovAl1JHdRFQ7qUvFhTgnrl9J08+pnjNKc39wmlCKfnBNMdVtqCe4vAXbEA= X-Received: by 2002:a63:df42:: with SMTP id h2mr1347789pgj.405.1571971923372; Thu, 24 Oct 2019 19:52:03 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:27 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 7/9] 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 list of loose objects, it's useful to see the list of object packs as well. It can help us to examine what Git did and did not pack. Signed-off-by: Emily Shaffer --- bugreport.c | 21 +++++++++++++++++++++ bugreport.h | 6 ++++++ builtin/bugreport.c | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/bugreport.c b/bugreport.c index 54e1d47103..79ddb8baaa 100644 --- a/bugreport.c +++ b/bugreport.c @@ -219,3 +219,24 @@ void get_loose_object_summary(struct strbuf *obj_info) objects.nr); } } + +void get_packed_object_summary(struct strbuf *obj_info) +{ + struct strbuf dirpath = STRBUF_INIT; + struct string_list contents = STRING_LIST_INIT_DUP; + struct string_list_item *entry; + + strbuf_reset(obj_info); + + strbuf_addstr(&dirpath, get_object_directory()); + strbuf_complete(&dirpath, '/'); + strbuf_addstr(&dirpath, "pack/"); + list_contents_of_dir(&contents, &dirpath, 0, 0); + + // list full contents of $GIT_OBJECT_DIRECTORY/pack/ + for_each_string_list_item(entry, &contents) { + strbuf_addbuf(obj_info, &dirpath); + strbuf_addstr(obj_info, entry->string); + strbuf_complete_line(obj_info); + } +} diff --git a/bugreport.h b/bugreport.h index 09ad0c2599..11ff7df41b 100644 --- a/bugreport.h +++ b/bugreport.h @@ -24,3 +24,9 @@ void get_populated_hooks(struct strbuf *hook_info); * will be discarded. */ void get_loose_object_summary(struct strbuf *obj_info); + +/** + * Adds a list of the contents of '.git/objects/pack'. The previous contents of + * hook_info will be discarded. + */ +void get_packed_object_summary(struct strbuf *obj_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index b2ab194207..da91a3944e 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -68,6 +68,10 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_loose_object_summary(&buffer); strbuf_write(&buffer, report); + add_header(report, "Packed Object Summary"); + get_packed_object_summary(&buffer); + strbuf_write(&buffer, report); + fclose(report); launch_editor(report_path.buf, NULL, NULL); From patchwork Fri Oct 25 02:51:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211259 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 6D406139A for ; Fri, 25 Oct 2019 02:52:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B3AE21D71 for ; Fri, 25 Oct 2019 02:52:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PMKrbzKh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391279AbfJYCwK (ORCPT ); Thu, 24 Oct 2019 22:52:10 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:44676 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCwK (ORCPT ); Thu, 24 Oct 2019 22:52:10 -0400 Received: by mail-qt1-f201.google.com with SMTP id t16so659534qtp.11 for ; Thu, 24 Oct 2019 19:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=chedpYzZpSl1sb5bBmFQq5AiopcUWdk/3H89WTN8dl0=; b=PMKrbzKhoUwSMCOjHkpigCTpVshrClxlLEd6iI9c6osQ3IQse8Q4zTYrD/WtBYowtv 2c4xatBz21vKcUMT0mvxyhlclDnZHTBr7omHnA6Yw3Vx0CDusp/hN4Q2erzivMeSay0z koK46NfTHtkX0wJHlqtx7xQo2DJfaI+PlzsXnAquex8xYBCfI6ROXy1PORSR6rkyk9rG 0XXZ7DpgKZKEM5H00ODmQkF8uW9+wsts7+PsciU/htP0fLt83yDzQu0TR8hOa0U1mn5j +3SheHw2CTnlHeZiju/lO67qKhodl1EgZuSy766fbKHRGbxHjCV1Hq1Ma7kOpnpkT+jY CcPQ== 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=chedpYzZpSl1sb5bBmFQq5AiopcUWdk/3H89WTN8dl0=; b=UIhBJfxuL6sKYe6O37FImKQJAkjMs0OIbRaluE5jqfC6IJdk8C3zygpAHbE/+3NY27 HjJ/3fQgDaNfrLqrB/40eswzyayA8zzjNbhEZt/ejbgQkpt/zb3zhr3m8/s7JXsyxnVQ 2cwBQbqDxtvfspnc6HZ/IniZ2ial5u0vhp7lmW8fFhvxq30esz5fkoEXm0LJ8ZFc1KhJ Wz2gpWju2CiWqXCNc4eBKJGrc23nbPA4iKZcxZ/ZYaY5r1mOnYZgHv6hCWeSmfUrqpkK E3DEOKWGd1TMr4etOYPLb4TcWCmNcu3bsY00x/60Sk9d4u3P/ZIfop31Ke99JiTQWrym PSxQ== X-Gm-Message-State: APjAAAVwktmAO60TSSazbtDPsW2YyQEUwV0/eL0LCMf8Nawr5YYvkQdb xiztRiYlDDpd6apb1bs5NhmUzDOtMyYE7kjVEcbbZ4x1VyoeKdEZUWny4QCI+qc24TXORqt9DSj 16xXZz3cM87T7fiy7WSzCwjVEg/hKSsH3CnDM+ARapWkIbzajgfqDquiD6l1vbk2qttAQog6jEw == X-Google-Smtp-Source: APXvYqwu/FtdYmtTsUdzbCnCfckC8lL9LLZmRQENkYZhQktqBHTyYTkDxLkA6LBa6/72G3H5RJb9rFoNpsnHD1APbpE= X-Received: by 2002:a0c:eb90:: with SMTP id x16mr1151282qvo.140.1571971927388; Thu, 24 Oct 2019 19:52:07 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:28 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 8/9] 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 --- bugreport.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ bugreport.h | 6 +++++ builtin/bugreport.c | 7 ++++++ 3 files changed, 71 insertions(+) diff --git a/bugreport.c b/bugreport.c index 79ddb8baaa..ce15904fec 100644 --- a/bugreport.c +++ b/bugreport.c @@ -6,6 +6,7 @@ #include "help.h" #include "run-command.h" #include "strbuf.h" +#include "string-list.h" #include "version.h" #include "dirent.h" @@ -171,6 +172,41 @@ void list_contents_of_dir(struct string_list *contents, struct strbuf *dirpath, } } +/** + * Fills 'contents' with a list of all directories within the provided + * directory, recursing into each directory. + */ +void list_contents_of_dir_recursively(struct string_list *contents, + struct strbuf *dirpath) +{ + struct string_list current_contents = STRING_LIST_INIT_DUP; + struct string_list current_subdirs = STRING_LIST_INIT_DUP; + struct string_list_item *it; + struct strbuf buf = STRBUF_INIT; + + list_contents_of_dir(¤t_contents, dirpath, 0, 0); + for_each_string_list_item(it, ¤t_contents) { + strbuf_reset(&buf); + strbuf_addbuf(&buf, dirpath); + strbuf_complete(&buf, '/'); + strbuf_addstr(&buf, it->string); + + string_list_append(contents, buf.buf); + } + + list_contents_of_dir(¤t_subdirs, dirpath, 1, DT_DIR); + for_each_string_list_item(it, ¤t_subdirs) { + if (strcmp(it->string, ".") == 0 + || strcmp(it->string, "..") == 0) + continue; + strbuf_reset(&buf); + strbuf_addbuf(&buf, dirpath); + strbuf_complete(&buf, '/'); + strbuf_addstr(&buf, it->string); + + list_contents_of_dir_recursively(contents, &buf); + } +} void get_object_counts(struct strbuf *obj_info) { @@ -240,3 +276,25 @@ void get_packed_object_summary(struct strbuf *obj_info) strbuf_complete_line(obj_info); } } + +void get_object_info_summary(struct strbuf *obj_info) +{ + // strbuf += GITDIR/info/: + // recursively list contents of $GIT_OBJECT_DIRECTORY/info + struct strbuf dirpath = STRBUF_INIT; + struct string_list contents = STRING_LIST_INIT_DUP; + struct string_list_item *entry; + + strbuf_reset(obj_info); + + strbuf_addstr(&dirpath, get_object_directory()); + strbuf_complete(&dirpath, '/'); + strbuf_addstr(&dirpath, "info/"); + + list_contents_of_dir_recursively(&contents, &dirpath); + + for_each_string_list_item(entry, &contents) { + strbuf_addstr(obj_info, entry->string); + strbuf_complete_line(obj_info); + } +} diff --git a/bugreport.h b/bugreport.h index 11ff7df41b..4f5e2d1b9a 100644 --- a/bugreport.h +++ b/bugreport.h @@ -30,3 +30,9 @@ void get_loose_object_summary(struct strbuf *obj_info); * hook_info will be discarded. */ void get_packed_object_summary(struct strbuf *obj_info); + +/** + * Adds a list of all contents (recursively) of '.git/objects/info'. The + * previous contents of hook_info will be discarded. + */ +void get_object_info_summary(struct strbuf *obj_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index da91a3944e..8aad33a9b0 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -72,6 +72,13 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_packed_object_summary(&buffer); strbuf_write(&buffer, report); + add_header(report, "Object Info Data"); + get_object_info_summary(&buffer); + strbuf_write(&buffer, report); + + // Close file + // open file in editor + launch_editor(report_path, NULL, NULL); fclose(report); launch_editor(report_path.buf, NULL, NULL); From patchwork Fri Oct 25 02:51:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11211261 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 91172139A for ; Fri, 25 Oct 2019 02:52:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7189721D71 for ; Fri, 25 Oct 2019 02:52:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fA8NnQXc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391300AbfJYCwN (ORCPT ); Thu, 24 Oct 2019 22:52:13 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:53537 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732696AbfJYCwN (ORCPT ); Thu, 24 Oct 2019 22:52:13 -0400 Received: by mail-pf1-f202.google.com with SMTP id h2so755588pfr.20 for ; Thu, 24 Oct 2019 19:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aZQXms7nJG+d3PXGj7MQD2IhqYwTjFVvl0TzUNRQbl4=; b=fA8NnQXc6wx1Ka58xuiCtfHdJm8M809kqEvm6buYtBKtqb4KEjedlRnbR1Fw148gAW zSgXNarRyoN4Wvqukw+bMQHQbWbZL33/gXR7BFmue6WWh2wYD0TJ1RYU3ODEi7U2PqSX pG3Xf7I7za7obzbkj8aeiokHSdk1bAKUZXQbsS/0LHvbeSKESLIso95+92HhQwkQJBg6 qg3g5Ln/mIkcsUxU7FsuwYddSyexXC7OhWFDdkj/Tjq8ASCG49GjCkwDCxafOh0hpAGd qOEMJif/KMWbMIgTgH2itRY1WXZ74JGwrNicZNG1c4SAFTtL0mNtb7yEOAvkszZ0VE/V sGGA== 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=aZQXms7nJG+d3PXGj7MQD2IhqYwTjFVvl0TzUNRQbl4=; b=ha5sQUn8UfWtS22DSfSEoXysv78cPWKliO9a1IbY7arEeQ5u3n2Yv0U3/m72CbOQD+ SlCFGlkrxM3+/6w/bwmYSy7DmYV1KbZt7FqDnc8ESY8hgv3fHZ87NnVLNz32tjep7Qqf mLFAgEpygwB3uKCET7NN+TEeirxQvTIPLyzuBASVaJblSuXl6GDgfEoUkSA8X2gv7dhc gK0PCdPzd0gt7zCz+NJsQs6Lrkm9ZQFZXIB+7c7rW7Ln4IF2NbjQCEs6xkPQGehorlo6 XRzLZWP8wFtv0Cbilx62mg2jBpdAXs+NRMMsyMc1vVskgKEkeGiBoaZAmA6P/uwGMJCh 2Ukw== X-Gm-Message-State: APjAAAX/uUrBraRKTc5l+B9OJDgqq3eN+YFVh8Eo6ExNWxwvZOf3D0O/ Un7jTC0NfCbhgG0Iu2sBBkqli6xZJhj+4jieXJDIcJM+fF6Tmt3prbCD62jxkqJBXeNI1nUZE8E rigEAvbQNHBnOSu+A/fmG4oHNetY+nbCxVW2ZkVx77EtWEctvAx3vDwyMrAot30gPTky+qVUBpQ == X-Google-Smtp-Source: APXvYqzKRAN0TTMZ8lU+0Huic7RfUJOxnFjY0QI8tudb2ZrbDT8Ke8ah3P6GyuHK4Aj27mscKoPsPbZc5jH9rfBPIPI= X-Received: by 2002:a63:4304:: with SMTP id q4mr1252641pga.218.1571971930857; Thu, 24 Oct 2019 19:52:10 -0700 (PDT) Date: Thu, 24 Oct 2019 19:51:29 -0700 In-Reply-To: <20191025025129.250049-1-emilyshaffer@google.com> Message-Id: <20191025025129.250049-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20191025025129.250049-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH v3 9/9] bugreport: print 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. Signed-off-by: Emily Shaffer --- bugreport.c | 14 ++++++++++++++ bugreport.h | 6 ++++++ builtin/bugreport.c | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/bugreport.c b/bugreport.c index ce15904fec..a7bdc72b7f 100644 --- a/bugreport.c +++ b/bugreport.c @@ -298,3 +298,17 @@ void get_object_info_summary(struct strbuf *obj_info) strbuf_complete_line(obj_info); } } + +void get_alternates_file(struct strbuf *alternates_info) +{ + struct strbuf alternates_path = STRBUF_INIT; + + strbuf_addstr(&alternates_path, get_object_directory()); + strbuf_complete(&alternates_path, '/'); + strbuf_addstr(&alternates_path, "info/alternates"); + + strbuf_reset(alternates_info); + strbuf_addbuf(alternates_info, &alternates_path); + strbuf_complete_line(alternates_info); + strbuf_read_file(alternates_info, alternates_path.buf, 0); +} diff --git a/bugreport.h b/bugreport.h index 4f5e2d1b9a..74d1f79960 100644 --- a/bugreport.h +++ b/bugreport.h @@ -36,3 +36,9 @@ void get_packed_object_summary(struct strbuf *obj_info); * previous contents of hook_info will be discarded. */ void get_object_info_summary(struct strbuf *obj_info); + +/** + * Adds the contents of '.git/info/alternates'. The previous contents of + * alternates_info will be discarded. + */ +void get_alternates_file(struct strbuf *alt_info); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 8aad33a9b0..0784bdc42a 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -76,6 +76,10 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) get_object_info_summary(&buffer); strbuf_write(&buffer, report); + add_header(report, "Alternates File"); + get_alternates_file(&buffer); + strbuf_write(&buffer, report); + // Close file // open file in editor launch_editor(report_path, NULL, NULL);