From patchwork Mon Aug 1 21:14:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92632C19F2C for ; Mon, 1 Aug 2022 21:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbiHAVPF (ORCPT ); Mon, 1 Aug 2022 17:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232936AbiHAVPD (ORCPT ); Mon, 1 Aug 2022 17:15:03 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A69186DE for ; Mon, 1 Aug 2022 14:15:02 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id bk11so5738333wrb.10 for ; Mon, 01 Aug 2022 14:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=UWkmwEMmDQA88Knl6wRhhl/jDXRNKzlTXKO5NvbUwn8=; b=GQWuEBLm5vgLXo7y6JyfqGR0zBiyd1mhFBfSCuwyw1/hFaaPtZoRRIQqmIH8drhGOn cVhKoQwSl+98FTKmd4eCKtIIe1805MEcUZpvUEPvTld+U/Ds+z34sv/nGERBrNdvgfn6 HYXba2kdpT66I3pEZTUDVEXL8i4EvExGq2S2xd8Z++1dd5H+V769uSetAsypahJPljgg my5lBVZWja5GGu/LIVe4cpf/JTPHr2RHZuzfViJvBZN4axnvx6Q/rKccKKB+3YJYHcan TFCzXLmVPtx3kcXUs/DB8EM2IEqG0YXrFAI3slkwg/Rl26zSxNVGagDWulAJL5JsR9Rr 3+4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=UWkmwEMmDQA88Knl6wRhhl/jDXRNKzlTXKO5NvbUwn8=; b=uy9RecvDbs0Ku75xWnMMkqnJdxLESk63g3uFL7kMupgnDVxuwIPDUngi8VGwqTntdI toek+F51tM9GWYhPQZbMNALIXSsnGwKMNaVqp+5dAH3lGytv3GQ36tea870GzCL6o0xc dbLSFPEVkuz1LYllONhVteLe+bICc3FfmSEJWFXTvwxMVPb9puIxjzf1a8fvDysCwszw 588l9RR3kQXun67+gsSlvhnOlSy1vU/bVnrrDntaPynUuZCvLDwbzr/cQCqQpIs1z+IQ RcjKft4CcnysiiXWVfZA4ZFbZpICtTjaVW2EtHpTWnM0zzDPqnvU2gsW5zoWguIGOzvI xkhg== X-Gm-Message-State: ACgBeo1X4X/ZuwEwbaSct4PpE+Yeb4STWoxyJIJ6VNFbCdbnHtJzx0aO glsu0mNKhbcjoA4lnzClHG4YQh43XlE= X-Google-Smtp-Source: AA6agR4V9fckUyLAnws7aHjxQd1lgME4pCP2Zz/3Hvcp1nlyKzBq5HBk6crhNhqDLZDF9BFAr/XOOw== X-Received: by 2002:adf:ea0f:0:b0:220:5c01:22b7 with SMTP id q15-20020adfea0f000000b002205c0122b7mr7114760wrm.597.1659388500757; Mon, 01 Aug 2022 14:15:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o9-20020a05600c4fc900b003a31c4f6f74sm22794113wmq.32.2022.08.01.14.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:00 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:52 +0000 Subject: [PATCH 1/7] scalar: use "$GIT_UNZIP" in 'scalar diagnose' test Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Use the "$GIT_UNZIP" test variable rather than verbatim 'unzip' to unzip the 'scalar diagnose' archive. Using "$GIT_UNZIP" is needed to run the Scalar tests on systems where 'unzip' is not in the system path. Signed-off-by: Victoria Dye --- contrib/scalar/t/t9099-scalar.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index 10b1172a8aa..fac86a57550 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -109,14 +109,14 @@ test_expect_success UNZIP 'scalar diagnose' ' sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" zip_path && zip_path=$(cat zip_path) && test -n "$zip_path" && - unzip -v "$zip_path" && + "$GIT_UNZIP" -v "$zip_path" && folder=${zip_path%.zip} && test_path_is_missing "$folder" && - unzip -p "$zip_path" diagnostics.log >out && + "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out && test_file_not_empty out && - unzip -p "$zip_path" packs-local.txt >out && + "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out && grep "$(pwd)/.git/objects" out && - unzip -p "$zip_path" objects-local.txt >out && + "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out && grep "^Total: [1-9]" out ' From patchwork Mon Aug 1 21:14:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A868C00144 for ; Mon, 1 Aug 2022 21:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234441AbiHAVPJ (ORCPT ); Mon, 1 Aug 2022 17:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232936AbiHAVPF (ORCPT ); Mon, 1 Aug 2022 17:15:05 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B4517E09 for ; Mon, 1 Aug 2022 14:15:03 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id p10so11398953wru.8 for ; Mon, 01 Aug 2022 14:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:mime-version :content-transfer-encoding:fcc:to:cc; bh=ZxH1M4hxoHyOY1tbJ6GxwsP9UZIUbS7BDtmvR1S2mV8=; b=fEgivA7naW3IoyE40NZ0HMy7FayqAHuE4hAoyLutmUe+nzd9rUD+QfUu8Pt7tEZV5k Zd5PeVtFslprH4pb78nHVqUB+wcMBXoVJnDWw1Be5q9aJGyegiZZAVVskwj1lK669Cnl JdCgoI5W7f5Er9uuwddd9wHfjG59Rnjm5yUs/Ngnf57iGaen3CANGDCa3ffFlWkpfs29 BGGrJw3zoNCRokjhkWhz311F2eJvFl9fZdprZ+2ntMr7my8PRAp4YqzXfRfb6kWyXAtL iUYUwDBAcw6wG4R3uzJg+MzMSthjCvzSGJCJBhVwTu90cZzx1QucpHtbrjyAgcOy8J7B iv0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:mime-version:content-transfer-encoding:fcc:to:cc; bh=ZxH1M4hxoHyOY1tbJ6GxwsP9UZIUbS7BDtmvR1S2mV8=; b=qqVqT04y5Etq3MXR0+erqyasBiYI1WX44kSJbq9AcK4V6ZqiYOO6nnt+QjXu2C0cf/ s17mOdilHbZgFZRJqvSHyYNih/pCp1X1KXix6UZTyMtaHArftu1wUi8cEfS3zjTuBgDm nlS/q/lDjnVm9UXYt7ht5bpxYCX6YEy4lg3ErI/F4loqg+m0QI/0OadtmxLX+3T7C9DB BPe0DVHGRoJdvzenaXy0V2cJOcbRM90XAwVwQva+oD40sBICsOar3Omv3s9Fr5ZJL7I1 roclFcoG3JMhfnNx/MdrIv/L2ne/Kh2MpLgDylvWbtjrtdJV3Co0+rAdX4fhDUfJp6BF GSTQ== X-Gm-Message-State: ACgBeo2EuI1PEyaZWXJsPJT2ZExHL8sNSFGRS+9ycBIHB9k43vwKkCTN CAoF1UDXgYdY0drZ3mpzcn/pa9CH41M= X-Google-Smtp-Source: AA6agR6LhByqXScdDyApqbuFN6e2CQx902JkbQ7TLwt/f1yKp1lAW+BBJbV8Iwyr2idCiabTRlxzmA== X-Received: by 2002:a5d:48d2:0:b0:21e:8f48:e362 with SMTP id p18-20020a5d48d2000000b0021e8f48e362mr12171575wrs.356.1659388501960; Mon, 01 Aug 2022 14:15:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u1-20020a7bcb01000000b003a3253b705dsm16231343wmj.35.2022.08.01.14.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:01 -0700 (PDT) Message-Id: <932dc8cddacf1841996cd3e0d512b95828213015.1659388498.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:53 +0000 Subject: [PATCH 2/7] builtin/bugreport.c: create '--diagnose' option MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Create a '--diagnose' option for 'git bugreport' to collect additional information about the repository and write it to a zipped archive. The "diagnose" functionality was originally implemented for Scalar in aa5c79a331 (scalar: implement `scalar diagnose`, 2022-05-28). However, the diagnostics gathered are not specific to Scalar-cloned repositories and could be useful when diagnosing issues in any Git repository. Note that, while this patch appears large, it is mostly copied directly out of 'scalar.c'. Specifically, the functions - dir_file_stats_objects() - dir_file_stats() - count_files() - loose_objs_stats() - add_directory_to_archiver() - get_disk_info() are all copied verbatim from 'scalar.c'. The 'create_diagnostics_archive()' function is a mostly unmodified copy of 'cmd_diagnose()', with the primary changes being that 'zip_path' is an input and "Enlistment root" is corrected to "Repository root" in the logs. The remainder of the patch is made up of adding the '--diagnose' option to 'cmd_bugreport()' (including generation of the archive's 'zip_path'), updating documentation, and adding a test. Note that the test is 'test_expect_failure' due to bugs in the original 'scalar diagnose'. These will be fixed in subsequent patches. Suggested-by: Ævar Arnfjörð Bjarmason Signed-off-by: Victoria Dye --- Documentation/git-bugreport.txt | 11 +- builtin/bugreport.c | 282 +++++++++++++++++++++++++++++++- t/t0091-bugreport.sh | 20 +++ 3 files changed, 309 insertions(+), 4 deletions(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index d8817bf3cec..b55658bc287 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -8,7 +8,7 @@ git-bugreport - Collect information for user to file a bug report SYNOPSIS -------- [verse] -'git bugreport' [(-o | --output-directory) ] [(-s | --suffix) ] +'git bugreport' [] DESCRIPTION ----------- @@ -31,6 +31,9 @@ The following information is captured automatically: - A list of enabled hooks - $SHELL +Additional information may be gathered into a separate zip archive using the +`--diagnose` option. + This tool is invoked via the typical Git setup process, which means that in some cases, it might not be able to launch - for example, if a relevant config file is unreadable. In this kind of scenario, it may be helpful to manually gather @@ -49,6 +52,12 @@ OPTIONS named 'git-bugreport-'. This should take the form of a strftime(3) format string; the current local time will be used. +--diagnose:: + Create a zip archive of information about the repository including logs + and certain statistics describing the data shape of the repository. The + archive is written to the same output directory as the bug report and is + named 'git-diagnostics-'. + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 9de32bc96e7..35b1fc48bf1 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -5,6 +5,10 @@ #include "compat/compiler.h" #include "hook.h" #include "hook-list.h" +#include "dir.h" +#include "object-store.h" +#include "packfile.h" +#include "archive.h" static void get_system_info(struct strbuf *sys_info) @@ -59,7 +63,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) } static const char * const bugreport_usage[] = { - N_("git bugreport [-o|--output-directory ] [-s|--suffix ]"), + N_("git bugreport []"), NULL }; @@ -91,6 +95,259 @@ static void get_header(struct strbuf *buf, const char *title) strbuf_addf(buf, "\n\n[%s]\n", title); } +static void dir_file_stats_objects(const char *full_path, size_t full_path_len, + const char *file_name, void *data) +{ + struct strbuf *buf = data; + struct stat st; + + if (!stat(full_path, &st)) + strbuf_addf(buf, "%-70s %16" PRIuMAX "\n", file_name, + (uintmax_t)st.st_size); +} + +static int dir_file_stats(struct object_directory *object_dir, void *data) +{ + struct strbuf *buf = data; + + strbuf_addf(buf, "Contents of %s:\n", object_dir->path); + + for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects, + data); + + return 0; +} + +static int count_files(char *path) +{ + DIR *dir = opendir(path); + struct dirent *e; + int count = 0; + + if (!dir) + return 0; + + while ((e = readdir(dir)) != NULL) + if (!is_dot_or_dotdot(e->d_name) && e->d_type == DT_REG) + count++; + + closedir(dir); + return count; +} + +static void loose_objs_stats(struct strbuf *buf, const char *path) +{ + DIR *dir = opendir(path); + struct dirent *e; + int count; + int total = 0; + unsigned char c; + struct strbuf count_path = STRBUF_INIT; + size_t base_path_len; + + if (!dir) + return; + + strbuf_addstr(buf, "Object directory stats for "); + strbuf_add_absolute_path(buf, path); + strbuf_addstr(buf, ":\n"); + + strbuf_add_absolute_path(&count_path, path); + strbuf_addch(&count_path, '/'); + base_path_len = count_path.len; + + while ((e = readdir(dir)) != NULL) + if (!is_dot_or_dotdot(e->d_name) && + e->d_type == DT_DIR && strlen(e->d_name) == 2 && + !hex_to_bytes(&c, e->d_name, 1)) { + strbuf_setlen(&count_path, base_path_len); + strbuf_addstr(&count_path, e->d_name); + total += (count = count_files(count_path.buf)); + strbuf_addf(buf, "%s : %7d files\n", e->d_name, count); + } + + strbuf_addf(buf, "Total: %d loose objects", total); + + strbuf_release(&count_path); + closedir(dir); +} + +static int add_directory_to_archiver(struct strvec *archiver_args, + const char *path, int recurse) +{ + int at_root = !*path; + DIR *dir = opendir(at_root ? "." : path); + struct dirent *e; + struct strbuf buf = STRBUF_INIT; + size_t len; + int res = 0; + + if (!dir) + return error_errno(_("could not open directory '%s'"), path); + + if (!at_root) + strbuf_addf(&buf, "%s/", path); + len = buf.len; + strvec_pushf(archiver_args, "--prefix=%s", buf.buf); + + while (!res && (e = readdir(dir))) { + if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name)) + continue; + + strbuf_setlen(&buf, len); + strbuf_addstr(&buf, e->d_name); + + if (e->d_type == DT_REG) + strvec_pushf(archiver_args, "--add-file=%s", buf.buf); + else if (e->d_type != DT_DIR) + warning(_("skipping '%s', which is neither file nor " + "directory"), buf.buf); + else if (recurse && + add_directory_to_archiver(archiver_args, + buf.buf, recurse) < 0) + res = -1; + } + + closedir(dir); + strbuf_release(&buf); + return res; +} + +#ifndef WIN32 +#include +#endif + +static int get_disk_info(struct strbuf *out) +{ +#ifdef WIN32 + struct strbuf buf = STRBUF_INIT; + char volume_name[MAX_PATH], fs_name[MAX_PATH]; + DWORD serial_number, component_length, flags; + ULARGE_INTEGER avail2caller, total, avail; + + strbuf_realpath(&buf, ".", 1); + if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) { + error(_("could not determine free disk size for '%s'"), + buf.buf); + strbuf_release(&buf); + return -1; + } + + strbuf_setlen(&buf, offset_1st_component(buf.buf)); + if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name), + &serial_number, &component_length, &flags, + fs_name, sizeof(fs_name))) { + error(_("could not get info for '%s'"), buf.buf); + strbuf_release(&buf); + return -1; + } + strbuf_addf(out, "Available space on '%s': ", buf.buf); + strbuf_humanise_bytes(out, avail2caller.QuadPart); + strbuf_addch(out, '\n'); + strbuf_release(&buf); +#else + struct strbuf buf = STRBUF_INIT; + struct statvfs stat; + + strbuf_realpath(&buf, ".", 1); + if (statvfs(buf.buf, &stat) < 0) { + error_errno(_("could not determine free disk size for '%s'"), + buf.buf); + strbuf_release(&buf); + return -1; + } + + strbuf_addf(out, "Available space on '%s': ", buf.buf); + strbuf_humanise_bytes(out, st_mult(stat.f_bsize, stat.f_bavail)); + strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag); + strbuf_release(&buf); +#endif + return 0; +} + +static int create_diagnostics_archive(struct strbuf *zip_path) +{ + struct strvec archiver_args = STRVEC_INIT; + char **argv_copy = NULL; + int stdout_fd = -1, archiver_fd = -1; + struct strbuf buf = STRBUF_INIT; + int res = 0; + + stdout_fd = dup(1); + if (stdout_fd < 0) { + res = error_errno(_("could not duplicate stdout")); + goto diagnose_cleanup; + } + + archiver_fd = xopen(zip_path->buf, O_CREAT | O_WRONLY | O_TRUNC, 0666); + if (archiver_fd < 0 || dup2(archiver_fd, 1) < 0) { + res = error_errno(_("could not redirect output")); + goto diagnose_cleanup; + } + + init_zip_archiver(); + strvec_pushl(&archiver_args, "scalar-diagnose", "--format=zip", NULL); + + strbuf_reset(&buf); + strbuf_addstr(&buf, "Collecting diagnostic info\n\n"); + get_version_info(&buf, 1); + + strbuf_addf(&buf, "Repository root: %s\n", the_repository->worktree); + get_disk_info(&buf); + write_or_die(stdout_fd, buf.buf, buf.len); + strvec_pushf(&archiver_args, + "--add-virtual-file=diagnostics.log:%.*s", + (int)buf.len, buf.buf); + + strbuf_reset(&buf); + strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:"); + dir_file_stats(the_repository->objects->odb, &buf); + foreach_alt_odb(dir_file_stats, &buf); + strvec_push(&archiver_args, buf.buf); + + strbuf_reset(&buf); + strbuf_addstr(&buf, "--add-virtual-file=objects-local.txt:"); + loose_objs_stats(&buf, ".git/objects"); + strvec_push(&archiver_args, buf.buf); + + if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) || + (res = add_directory_to_archiver(&archiver_args, ".git/hooks", 0)) || + (res = add_directory_to_archiver(&archiver_args, ".git/info", 0)) || + (res = add_directory_to_archiver(&archiver_args, ".git/logs", 1)) || + (res = add_directory_to_archiver(&archiver_args, ".git/objects/info", 0))) + goto diagnose_cleanup; + + strvec_pushl(&archiver_args, "--prefix=", + oid_to_hex(the_hash_algo->empty_tree), "--", NULL); + + /* `write_archive()` modifies the `argv` passed to it. Let it. */ + argv_copy = xmemdupz(archiver_args.v, + sizeof(char *) * archiver_args.nr); + res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL, + the_repository, NULL, 0); + if (res) { + error(_("failed to write archive")); + goto diagnose_cleanup; + } + + if (!res) + fprintf(stderr, "\n" + "Diagnostics complete.\n" + "All of the gathered info is captured in '%s'\n", + zip_path->buf); + +diagnose_cleanup: + if (archiver_fd >= 0) { + close(1); + dup2(stdout_fd, 1); + } + free(argv_copy); + strvec_clear(&archiver_args); + strbuf_release(&buf); + + return res; +} + int cmd_bugreport(int argc, const char **argv, const char *prefix) { struct strbuf buffer = STRBUF_INIT; @@ -98,16 +355,20 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) int report = -1; time_t now = time(NULL); struct tm tm; + int diagnose = 0; char *option_output = NULL; char *option_suffix = "%Y-%m-%d-%H%M"; const char *user_relative_path = NULL; char *prefixed_filename; + size_t output_path_len; const struct option bugreport_options[] = { + OPT_BOOL(0, "diagnose", &diagnose, + N_("generate a diagnostics zip archive")), OPT_STRING('o', "output-directory", &option_output, N_("path"), - N_("specify a destination for the bugreport file")), + N_("specify a destination for the bugreport file(s)")), OPT_STRING('s', "suffix", &option_suffix, N_("format"), - N_("specify a strftime format suffix for the filename")), + N_("specify a strftime format suffix for the filename(s)")), OPT_END() }; @@ -119,6 +380,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) option_output ? option_output : ""); strbuf_addstr(&report_path, prefixed_filename); strbuf_complete(&report_path, '/'); + output_path_len = report_path.len; strbuf_addstr(&report_path, "git-bugreport-"); strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0); @@ -133,6 +395,20 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) report_path.buf); } + /* Prepare diagnostics, if requested */ + if (diagnose) { + struct strbuf zip_path = STRBUF_INIT; + strbuf_add(&zip_path, report_path.buf, output_path_len); + strbuf_addstr(&zip_path, "git-diagnostics-"); + strbuf_addftime(&zip_path, option_suffix, localtime_r(&now, &tm), 0, 0); + strbuf_addstr(&zip_path, ".zip"); + + if (create_diagnostics_archive(&zip_path)) + die_errno(_("unable to create diagnostics archive %s"), zip_path.buf); + + strbuf_release(&zip_path); + } + /* Prepare the report contents */ get_bug_template(&buffer); diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh index 08f5fe9caef..3cf983aa67f 100755 --- a/t/t0091-bugreport.sh +++ b/t/t0091-bugreport.sh @@ -78,4 +78,24 @@ test_expect_success 'indicates populated hooks' ' test_cmp expect actual ' +test_expect_failure UNZIP '--diagnose creates diagnostics zip archive' ' + test_when_finished rm -rf report && + + git bugreport --diagnose -o report -s test >out && + + zip_path=report/git-diagnostics-test.zip && + grep "Available space" out && + test_path_is_file "$zip_path" && + + # Check zipped archive content + "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out && + test_file_not_empty out && + + "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out && + grep ".git/objects" out && + + "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out && + grep "^Total: [0-9][0-9]*" out +' + test_done From patchwork Mon Aug 1 21:14:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A846C3F6B0 for ; Mon, 1 Aug 2022 21:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234782AbiHAVPK (ORCPT ); Mon, 1 Aug 2022 17:15:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbiHAVPG (ORCPT ); Mon, 1 Aug 2022 17:15:06 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1AB7186DE for ; Mon, 1 Aug 2022 14:15:04 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id m13so11656274wrq.6 for ; Mon, 01 Aug 2022 14:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=U/XZpKfFcJKIdssrs3gETOYX7HaU26FzV0n23UpU6+g=; b=ZDrKK+Vf4xE3Wh0kL4/4JqLXc2qh2uKw9amP7ywE3xYutcyHHyR3mWZlRgqHxQULmW O8V43szfzCu9QsMqxPL5RspyVreZj3snhfU4A/ahdGoODuyOFpo9VPROxVmHLuY5wGSX NiLCcm84oUJt6Iiz9HjzwL/4QUQAa1Mb+sqkBpNm6BF+R0U2/OBIzdh6DzRm1KPPdWxp mUeKexbVH/0zTeNBXtg+uXaRBKqSI7s7KH0SvVCHPcorBpVYAOUGCD3PmyBSDAmhG4AE X0+V7q9xgnHYUB1I3pA/K0GkzHcTZ03kmCwfdrXm1PoaBMZ8HatOLyLPXpvACqE4CLRP zUPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=U/XZpKfFcJKIdssrs3gETOYX7HaU26FzV0n23UpU6+g=; b=ZfwrSGG0fp58oSb7rrbMwlIfWuQWvhzLBoSy2j+WGdlblcFNqnsl11YdxYM1fFWN1E qzWKJ6A70ahtw2/Un2YEDcg1YLGDGBcNBqiLptl47BaBBBLBtwrvC++bIS8rHIE7Hx1a QmpJN0YIHT16lfMCIk0LP2ew2iOhKtUVLs9GNTjV8vJaD/jbFxkJEVSgQ6U9ZYw/uz+5 L4txRuMEqkN8/aawgMkqRg1c0f7KQRSZRo/rOVYKdWepGf1hk0KAVPXBT2AbcwoFYrFW bSdjqJ43g0DSxBIp2mjdU/caBNrcTFakr9CxVUAW2zgVeu/U00gR/Xnb8an80Mlw6IS7 wxbQ== X-Gm-Message-State: ACgBeo0w+SmbUwMTspWj/9cuH8PuqE/mFaOq3NN38MoojCz+BxXXni8I qU8xSDCFh3k1lXevTWoA473mWF6giAQ= X-Google-Smtp-Source: AA6agR4a8g2LfuIvPrGXw/pr6AA3HRFNo60Vft8khQqOJG3g6KyrnHuwjNiweDH6dhTMnKnMiHUMsg== X-Received: by 2002:a05:6000:1a4e:b0:220:5e43:9843 with SMTP id t14-20020a0560001a4e00b002205e439843mr5934744wry.566.1659388502966; Mon, 01 Aug 2022 14:15:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j7-20020adfe507000000b0021d65675583sm13174421wrm.52.2022.08.01.14.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:02 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:54 +0000 Subject: [PATCH 3/7] builtin/bugreport.c: avoid size_t overflow Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Avoid size_t overflow when reporting the available disk space in 'get_disk_info' by casting the block size and available block count to 'uint64_t' before multiplying them. Without this change, 'st_mult' would (correctly) report size_t overflow on 32-bit systems at or exceeding 2^32 bytes of available space. Signed-off-by: Victoria Dye --- builtin/bugreport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 35b1fc48bf1..720889a37ad 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -258,7 +258,7 @@ static int get_disk_info(struct strbuf *out) } strbuf_addf(out, "Available space on '%s': ", buf.buf); - strbuf_humanise_bytes(out, st_mult(stat.f_bsize, stat.f_bavail)); + strbuf_humanise_bytes(out, (uint64_t)stat.f_bsize * (uint64_t)stat.f_bavail); strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag); strbuf_release(&buf); #endif From patchwork Mon Aug 1 21:14:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8578C00144 for ; Mon, 1 Aug 2022 21:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234093AbiHAVPM (ORCPT ); Mon, 1 Aug 2022 17:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbiHAVPH (ORCPT ); Mon, 1 Aug 2022 17:15:07 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27A4402D9 for ; Mon, 1 Aug 2022 14:15:05 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id u14-20020a05600c00ce00b003a323062569so6121013wmm.4 for ; Mon, 01 Aug 2022 14:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=y51TaP+IJMtsFUvRMGdpsaRCdcGTfrxNBDRErSskFqQ=; b=eARG2ILz0+0z3oE1ZHSlBYRFRNqkDKv4jZ3Xolj8BqpfBbJbPE/kAxfyf4xjz+n2BY +IVE+tscjavnbbrEviirWBi4AvaqeWVZPf6hn5xvfudsnF9ee5q3cit0yLHKYhBCA0oC hLguQ59DsLu301qCougB+WjysswMRyxt38uGCKGMrd2EL+x0/vvW9M9phxJ5qDoN+hif HTt3cKj9ZGipOnmf/yLUfsShfSOXRbpArxidxw3q/Pbh7w/UKWnxSoT53CPIrrc0aOJa rNBfXDFLl6ToukiCyBjgZcBqGp4M8sfhhr7J6ctH6NzCM1LeHzeTYngpgS+e6cQdonAT 0czA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=y51TaP+IJMtsFUvRMGdpsaRCdcGTfrxNBDRErSskFqQ=; b=ar4r3FSjMni5av9hvZPO3uwthb/5nZtTcNxfvH/S9vOSjQSMEuQNKXJJawHZm5v4ON ESFShftFipG9BJTuX5TcAU8lLrDNN/CuKVg3xvmmzxQgxTQea6czFnIgJ5EjSxczcz6d taW3zNMlbs+PsvjTJRkSaBmKaSqh2jS9D8P5sUMbgLaZiOjjuLs22c3+S6h0PmYdyE2W xSBoiIdWlayP/WMukZSr5yy6unaSBws3LC3rIYZyv1iJrwtzu/7DscXf0HG5/ceTkGfD LXzHTHlz+I61c6jKOdMrahqpIhhD8jSI+asgjo4hgxBZYmDOvyqLmM+zwRk8g4jauKf3 bw7g== X-Gm-Message-State: AJIora+I6xUogqkLE+txrmKghraWGSV262XJZkJ+HHgjrEl7VJCA1bIP bsFkWLVBJuTtiY5g0d7GOBxRPyaUt7o= X-Google-Smtp-Source: AGRyM1vicj8YTEta+VtvSG8pdpRfKuI5bxiofvqN7OCEhB+fmsyrJRpZRqC1qSEOoC2olfwsGvstQg== X-Received: by 2002:a05:600c:22da:b0:3a3:3139:d8ff with SMTP id 26-20020a05600c22da00b003a33139d8ffmr12350853wmg.178.1659388504072; Mon, 01 Aug 2022 14:15:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b5-20020adff905000000b0021b970a68f9sm12908835wrr.26.2022.08.01.14.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:03 -0700 (PDT) Message-Id: <4bc290fbf43e0193aae288b79249014d899ea34a.1659388498.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:55 +0000 Subject: [PATCH 4/7] builtin/bugreport.c: add directory to archiver more gently Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye If a directory added to the '--diagnose' archiver does not exist, warn and return 0 from 'add_directory_to_archiver()' rather than failing with a fatal error. This handles a failure edge case where the '.git/logs' has not yet been created when running 'git bugreport --diagnose', but extends to any situation where a directory may be missing in the '.git' dir. Now, when a directory is missing a warning is captured in the diagnostic logs. This provides a user with more complete information than if 'git bugreport' simply failed with an error. Signed-off-by: Victoria Dye --- builtin/bugreport.c | 8 +++++++- t/t0091-bugreport.sh | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 720889a37ad..dea11f91386 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -176,12 +176,18 @@ static int add_directory_to_archiver(struct strvec *archiver_args, const char *path, int recurse) { int at_root = !*path; - DIR *dir = opendir(at_root ? "." : path); + DIR *dir; struct dirent *e; struct strbuf buf = STRBUF_INIT; size_t len; int res = 0; + if (!file_exists(at_root ? "." : path)) { + warning(_("directory '%s' does not exist, will not be archived"), path); + return 0; + } + + dir = opendir(at_root ? "." : path); if (!dir) return error_errno(_("could not open directory '%s'"), path); diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh index 3cf983aa67f..e9db89ef2c8 100755 --- a/t/t0091-bugreport.sh +++ b/t/t0091-bugreport.sh @@ -78,7 +78,7 @@ test_expect_success 'indicates populated hooks' ' test_cmp expect actual ' -test_expect_failure UNZIP '--diagnose creates diagnostics zip archive' ' +test_expect_success UNZIP '--diagnose creates diagnostics zip archive' ' test_when_finished rm -rf report && git bugreport --diagnose -o report -s test >out && @@ -98,4 +98,13 @@ test_expect_failure UNZIP '--diagnose creates diagnostics zip archive' ' grep "^Total: [0-9][0-9]*" out ' +test_expect_success '--diagnose warns when archived dir does not exist' ' + test_when_finished rm -rf report && + + # Remove logs - not guaranteed to exist + rm -rf .git/logs && + git bugreport --diagnose -o report -s test 2>err && + grep "directory .\.git/logs. does not exist, will not be archived" err +' + test_done From patchwork Mon Aug 1 21:14:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CF1EC19F2C for ; Mon, 1 Aug 2022 21:15:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234231AbiHAVPO (ORCPT ); Mon, 1 Aug 2022 17:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234415AbiHAVPI (ORCPT ); Mon, 1 Aug 2022 17:15:08 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0841C419A1 for ; Mon, 1 Aug 2022 14:15:07 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id z16so15535604wrh.12 for ; Mon, 01 Aug 2022 14:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=oErV39Ln4p2mM+CNPmuoTUqIvjmR9dGkcIkYXHeUTtA=; b=k6niEOm6JAFIH6wrz+j8NHS1FjFYKiXDLO0KTpwb/5uaV01qgvWFiig+82FYTSjf01 q9lJQSt2MeQTvGw9rmawqO821kXb7dWk0xZZ1mFs4t8maqvUIzp6NW6i3TLp+cB8TOag O/iVijnP+OH98E6zfiv4LNBldaVktDoU0Fm/GEMg5kNUr5l/ReGcyJdmZ1ol/zvfoetu s8fJVYZW5YENRA0HwZ/b34wwpb+ZCQ5jhviG0XSaKtfzad909up1P75HgDFO2nWnng0T rV7riWbEnYFLYJzejrdezcdGioAvsAD5Wb7VPMGzqdmxMixtHt+pZB92jYlMmKSRDbsm 9KgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=oErV39Ln4p2mM+CNPmuoTUqIvjmR9dGkcIkYXHeUTtA=; b=PqLraDa2Oz9cUGETYwiHyTqtUNFDcYS6066C4LFiJ3XBS3xNCa+qLKUF42U1Oln8Jm q44zXjP/emLrFOlC3bKdPgHTlT48feRvxeSUG8B/Cg7Xfhwwur2fd68450IVJQYlmeX0 g7SuMpjjutNljbGoY5RJq6zws1I/iDfx39OHHpNq5GEHjjDfoLLK2TeFZDezoX4xt6j8 Noap9TKL5WGWVUgHL9lnpcVX17hhgB4/a3cTcCs6fwPxW5VRkkmXtbM0qVaiig7mHj9Q FHzWd62oFJBWx0Tg/ZsASUERBYli8PFOxXo7qM8AWKffppMJCh9UTJrpJDVg6ypUhNEm P4OA== X-Gm-Message-State: ACgBeo0hMHfHMagdYoWjeEzeoutPpbHKlFxxnH0bJfYEtZfC2Xib70Ed kTWVij7QB8kIVOb5arxS+7WoCT0OE/8= X-Google-Smtp-Source: AA6agR469iakm8zY0uRcPy9knV6dVlAbSdChGffLPCrPK5ZIccAbwLnbTPobD+QCk391wHSeLpDABw== X-Received: by 2002:adf:f94b:0:b0:21e:46fe:bcdb with SMTP id q11-20020adff94b000000b0021e46febcdbmr10885214wrr.143.1659388505057; Mon, 01 Aug 2022 14:15:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j20-20020a5d6e54000000b0021e5e5cd3a8sm12832663wrz.87.2022.08.01.14.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:04 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:56 +0000 Subject: [PATCH 5/7] builtin/bugreport.c: add '--no-report' option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Add a '--no-report' option to 'git bugreport' to avoid writing the 'git-bugreport-.txt' file. This gives users the option of creating only the diagnostic archive with '--diagnose' and mirroring the behavior of the original 'scalar diagnose' as closely as possible. If a user specifies '--no-report' *without* also specifying '--diagnose', the 'git bugreport' operation is a no-op; a warning message is printed and the command returns with a non-error exit code. Signed-off-by: Victoria Dye --- Documentation/git-bugreport.txt | 6 ++++++ builtin/bugreport.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt index b55658bc287..5eae7a4f950 100644 --- a/Documentation/git-bugreport.txt +++ b/Documentation/git-bugreport.txt @@ -58,6 +58,12 @@ OPTIONS archive is written to the same output directory as the bug report and is named 'git-diagnostics-'. +--no-report:: + Do not write out a 'git-bugreport-.txt' file. This option is + intended for use with `--diagnose` when only the diagnostic archive is + needed. If `--no-report` is used without `--diagnose`, `git bugreport` + is a no-op. + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/bugreport.c b/builtin/bugreport.c index dea11f91386..5ecff70276a 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -361,7 +361,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) int report = -1; time_t now = time(NULL); struct tm tm; - int diagnose = 0; + int diagnose = 0, skip_summary = 0; char *option_output = NULL; char *option_suffix = "%Y-%m-%d-%H%M"; const char *user_relative_path = NULL; @@ -371,6 +371,8 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) const struct option bugreport_options[] = { OPT_BOOL(0, "diagnose", &diagnose, N_("generate a diagnostics zip archive")), + OPT_BOOL(0, "no-report", &skip_summary, + N_("do not create a summary report")), OPT_STRING('o', "output-directory", &option_output, N_("path"), N_("specify a destination for the bugreport file(s)")), OPT_STRING('s', "suffix", &option_suffix, N_("format"), @@ -381,6 +383,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, bugreport_options, bugreport_usage, 0); + if (skip_summary && !diagnose) { + warning(_("Nothing to do!")); + return 0; + } + /* Prepare the path to put the result */ prefixed_filename = prefix_filename(prefix, option_output ? option_output : ""); @@ -415,6 +422,13 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) strbuf_release(&zip_path); } + if (skip_summary) { + free(prefixed_filename); + strbuf_release(&buffer); + strbuf_release(&report_path); + return 0; + } + /* Prepare the report contents */ get_bug_template(&buffer); From patchwork Mon Aug 1 21:14:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3D8CC00144 for ; Mon, 1 Aug 2022 21:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234356AbiHAVPQ (ORCPT ); Mon, 1 Aug 2022 17:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbiHAVPK (ORCPT ); Mon, 1 Aug 2022 17:15:10 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D8693FA29 for ; Mon, 1 Aug 2022 14:15:08 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id u14-20020a05600c00ce00b003a323062569so6121043wmm.4 for ; Mon, 01 Aug 2022 14:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=jBanH8g650jd8hhYFKIlpC/xTXRfMgaS8p9up1D5wns=; b=heYIwKX0UVAsVQPyHgo+sWWknGtLJiQWudYmczXNzFbdTbf1icOyNXBCp5NCGcxPlW q5U5XDaxAGg9CwVZHZn0eMpoM6Ww/rhcByPIZuREvIFp6UrAXD4jvvdH4iVLuzBJFwwy 8eB2w/Vbx1qV622li9VdGAWQeWoXlEArSlDzKMSE6olk17EszjC6YIdZZEC7KfZGL1Y9 hMpt8dLCNbxXnwb/xo/38K/n45jHtX/jBxyESUQqJC+3NGCCGNDG2Qn4Xk1n/3US3Rdh UTpnWrh/7Yp/UufqEF70Hf5mRfZlLVIWJmHi9Mhh5t+lIzWoTCz3m7LyC99gjp0/mglK IB7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=jBanH8g650jd8hhYFKIlpC/xTXRfMgaS8p9up1D5wns=; b=I/nYNRZlGL5SshMKhpJJ3xES7x/YU3tvO1EEg5mwZZs4bqM7sLERtp2RwTLr2fW+43 GIgxRGtklW5fOacnvDN2xehQCErXNsBK6U5y/4jNPrszoVlfVSMcn/klT4f4riMKcb/1 kZLEDhEA65NYC4u5uVCtaCczcXULK3sDds5+LfOB4/GJSoWpsP9hS6aVnf7S13lXHt4a RZN5XRZywjIk/NduV4kqH9xclNCzj8vm/NYzIo/qRpRyXpcALbfGi5Qrnxm5fC/bPIOv wALXjhDSwN/KsF82wFkJJDjRK8ewoSZXyJ999J0nsnEgdAuVqNTOXN2Y/C+6vdjSTjwr 9xqw== X-Gm-Message-State: ACgBeo21jCKR0r6Quk5KvpR1AqMidwKAJBh+KTV9qI3XWCmHF0rxOLos M0DbWAG6AeXWocnEuWxbDdFP3z7LMNw= X-Google-Smtp-Source: AA6agR5GVW4RhIWsqOrdnV+D4n5JXyanaPO+g5D6+QBYH+UZ7DfUHJt8CtEn3/3MwLffSv6MUxjQug== X-Received: by 2002:a7b:cc94:0:b0:3a4:c228:b340 with SMTP id p20-20020a7bcc94000000b003a4c228b340mr6050070wma.13.1659388506225; Mon, 01 Aug 2022 14:15:06 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n10-20020a7bc5ca000000b003a2e7c13a3asm15663110wmk.42.2022.08.01.14.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:05 -0700 (PDT) Message-Id: <4eb3c43d48832150c53ee56c679ab13464185974.1659388498.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:57 +0000 Subject: [PATCH 6/7] scalar: use 'git bugreport --diagnose' in 'scalar diagnose' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Replace implementation of 'scalar diagnose' with an internal invocation of 'git bugreport --diagnose --no-report'. The '--diagnose' option of 'git bugreport' was implemented to mirror what 'scalar diagnose' does, taking most of its code directly from 'scalar.c'. Remove the now-duplicate code in 'scalar.c' and have 'scalar diagnose' call 'git bugreport' to create the diagnostics archive. This introduces two (minor) changes to the output of 'scalar diagnose': changing "Enlistment root" to "Repository root" in 'diagnostics.log' ("enlistment root" was inaccurate anyway, as the reported path always pointed to the root of the repository), and changing the prefix of the zip archive from 'scalar_' to 'git-diagnostics-'. Signed-off-by: Victoria Dye --- contrib/scalar/scalar.c | 271 ++-------------------------------------- 1 file changed, 7 insertions(+), 264 deletions(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 97e71fe19cd..7b1953605bd 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -11,7 +11,6 @@ #include "dir.h" #include "packfile.h" #include "help.h" -#include "archive.h" #include "object-store.h" /* @@ -262,99 +261,6 @@ static int unregister_dir(void) return res; } -static int add_directory_to_archiver(struct strvec *archiver_args, - const char *path, int recurse) -{ - int at_root = !*path; - DIR *dir = opendir(at_root ? "." : path); - struct dirent *e; - struct strbuf buf = STRBUF_INIT; - size_t len; - int res = 0; - - if (!dir) - return error_errno(_("could not open directory '%s'"), path); - - if (!at_root) - strbuf_addf(&buf, "%s/", path); - len = buf.len; - strvec_pushf(archiver_args, "--prefix=%s", buf.buf); - - while (!res && (e = readdir(dir))) { - if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name)) - continue; - - strbuf_setlen(&buf, len); - strbuf_addstr(&buf, e->d_name); - - if (e->d_type == DT_REG) - strvec_pushf(archiver_args, "--add-file=%s", buf.buf); - else if (e->d_type != DT_DIR) - warning(_("skipping '%s', which is neither file nor " - "directory"), buf.buf); - else if (recurse && - add_directory_to_archiver(archiver_args, - buf.buf, recurse) < 0) - res = -1; - } - - closedir(dir); - strbuf_release(&buf); - return res; -} - -#ifndef WIN32 -#include -#endif - -static int get_disk_info(struct strbuf *out) -{ -#ifdef WIN32 - struct strbuf buf = STRBUF_INIT; - char volume_name[MAX_PATH], fs_name[MAX_PATH]; - DWORD serial_number, component_length, flags; - ULARGE_INTEGER avail2caller, total, avail; - - strbuf_realpath(&buf, ".", 1); - if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) { - error(_("could not determine free disk size for '%s'"), - buf.buf); - strbuf_release(&buf); - return -1; - } - - strbuf_setlen(&buf, offset_1st_component(buf.buf)); - if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name), - &serial_number, &component_length, &flags, - fs_name, sizeof(fs_name))) { - error(_("could not get info for '%s'"), buf.buf); - strbuf_release(&buf); - return -1; - } - strbuf_addf(out, "Available space on '%s': ", buf.buf); - strbuf_humanise_bytes(out, avail2caller.QuadPart); - strbuf_addch(out, '\n'); - strbuf_release(&buf); -#else - struct strbuf buf = STRBUF_INIT; - struct statvfs stat; - - strbuf_realpath(&buf, ".", 1); - if (statvfs(buf.buf, &stat) < 0) { - error_errno(_("could not determine free disk size for '%s'"), - buf.buf); - strbuf_release(&buf); - return -1; - } - - strbuf_addf(out, "Available space on '%s': ", buf.buf); - strbuf_humanise_bytes(out, st_mult(stat.f_bsize, stat.f_bavail)); - strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag); - strbuf_release(&buf); -#endif - return 0; -} - /* printf-style interface, expects `=` argument */ static int set_config(const char *fmt, ...) { @@ -595,83 +501,6 @@ cleanup: return res; } -static void dir_file_stats_objects(const char *full_path, size_t full_path_len, - const char *file_name, void *data) -{ - struct strbuf *buf = data; - struct stat st; - - if (!stat(full_path, &st)) - strbuf_addf(buf, "%-70s %16" PRIuMAX "\n", file_name, - (uintmax_t)st.st_size); -} - -static int dir_file_stats(struct object_directory *object_dir, void *data) -{ - struct strbuf *buf = data; - - strbuf_addf(buf, "Contents of %s:\n", object_dir->path); - - for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects, - data); - - return 0; -} - -static int count_files(char *path) -{ - DIR *dir = opendir(path); - struct dirent *e; - int count = 0; - - if (!dir) - return 0; - - while ((e = readdir(dir)) != NULL) - if (!is_dot_or_dotdot(e->d_name) && e->d_type == DT_REG) - count++; - - closedir(dir); - return count; -} - -static void loose_objs_stats(struct strbuf *buf, const char *path) -{ - DIR *dir = opendir(path); - struct dirent *e; - int count; - int total = 0; - unsigned char c; - struct strbuf count_path = STRBUF_INIT; - size_t base_path_len; - - if (!dir) - return; - - strbuf_addstr(buf, "Object directory stats for "); - strbuf_add_absolute_path(buf, path); - strbuf_addstr(buf, ":\n"); - - strbuf_add_absolute_path(&count_path, path); - strbuf_addch(&count_path, '/'); - base_path_len = count_path.len; - - while ((e = readdir(dir)) != NULL) - if (!is_dot_or_dotdot(e->d_name) && - e->d_type == DT_DIR && strlen(e->d_name) == 2 && - !hex_to_bytes(&c, e->d_name, 1)) { - strbuf_setlen(&count_path, base_path_len); - strbuf_addstr(&count_path, e->d_name); - total += (count = count_files(count_path.buf)); - strbuf_addf(buf, "%s : %7d files\n", e->d_name, count); - } - - strbuf_addf(buf, "Total: %d loose objects", total); - - strbuf_release(&count_path); - closedir(dir); -} - static int cmd_diagnose(int argc, const char **argv) { struct option options[] = { @@ -681,106 +510,20 @@ static int cmd_diagnose(int argc, const char **argv) N_("scalar diagnose []"), NULL }; - struct strbuf zip_path = STRBUF_INIT; - struct strvec archiver_args = STRVEC_INIT; - char **argv_copy = NULL; - int stdout_fd = -1, archiver_fd = -1; - time_t now = time(NULL); - struct tm tm; - struct strbuf buf = STRBUF_INIT; + struct strbuf diagnostics_path = STRBUF_INIT; int res = 0; argc = parse_options(argc, argv, NULL, options, usage, 0); - setup_enlistment_directory(argc, argv, usage, options, &zip_path); - - strbuf_addstr(&zip_path, "/.scalarDiagnostics/scalar_"); - strbuf_addftime(&zip_path, - "%Y%m%d_%H%M%S", localtime_r(&now, &tm), 0, 0); - strbuf_addstr(&zip_path, ".zip"); - switch (safe_create_leading_directories(zip_path.buf)) { - case SCLD_EXISTS: - case SCLD_OK: - break; - default: - error_errno(_("could not create directory for '%s'"), - zip_path.buf); - goto diagnose_cleanup; - } - stdout_fd = dup(1); - if (stdout_fd < 0) { - res = error_errno(_("could not duplicate stdout")); - goto diagnose_cleanup; - } - - archiver_fd = xopen(zip_path.buf, O_CREAT | O_WRONLY | O_TRUNC, 0666); - if (archiver_fd < 0 || dup2(archiver_fd, 1) < 0) { - res = error_errno(_("could not redirect output")); - goto diagnose_cleanup; - } - - init_zip_archiver(); - strvec_pushl(&archiver_args, "scalar-diagnose", "--format=zip", NULL); - - strbuf_reset(&buf); - strbuf_addstr(&buf, "Collecting diagnostic info\n\n"); - get_version_info(&buf, 1); - - strbuf_addf(&buf, "Enlistment root: %s\n", the_repository->worktree); - get_disk_info(&buf); - write_or_die(stdout_fd, buf.buf, buf.len); - strvec_pushf(&archiver_args, - "--add-virtual-file=diagnostics.log:%.*s", - (int)buf.len, buf.buf); + setup_enlistment_directory(argc, argv, usage, options, &diagnostics_path); + strbuf_addstr(&diagnostics_path, "/.scalarDiagnostics"); - strbuf_reset(&buf); - strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:"); - dir_file_stats(the_repository->objects->odb, &buf); - foreach_alt_odb(dir_file_stats, &buf); - strvec_push(&archiver_args, buf.buf); - - strbuf_reset(&buf); - strbuf_addstr(&buf, "--add-virtual-file=objects-local.txt:"); - loose_objs_stats(&buf, ".git/objects"); - strvec_push(&archiver_args, buf.buf); - - if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) || - (res = add_directory_to_archiver(&archiver_args, ".git/hooks", 0)) || - (res = add_directory_to_archiver(&archiver_args, ".git/info", 0)) || - (res = add_directory_to_archiver(&archiver_args, ".git/logs", 1)) || - (res = add_directory_to_archiver(&archiver_args, ".git/objects/info", 0))) - goto diagnose_cleanup; - - strvec_pushl(&archiver_args, "--prefix=", - oid_to_hex(the_hash_algo->empty_tree), "--", NULL); - - /* `write_archive()` modifies the `argv` passed to it. Let it. */ - argv_copy = xmemdupz(archiver_args.v, - sizeof(char *) * archiver_args.nr); - res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL, - the_repository, NULL, 0); - if (res) { - error(_("failed to write archive")); - goto diagnose_cleanup; - } - - if (!res) - fprintf(stderr, "\n" - "Diagnostics complete.\n" - "All of the gathered info is captured in '%s'\n", - zip_path.buf); - -diagnose_cleanup: - if (archiver_fd >= 0) { - close(1); - dup2(stdout_fd, 1); - } - free(argv_copy); - strvec_clear(&archiver_args); - strbuf_release(&zip_path); - strbuf_release(&buf); + if (run_git("bugreport", "--diagnose", "--no-report", + "-s", "%Y%m%d_%H%M%S", "-o", diagnostics_path.buf, NULL) < 0) + res = -1; + strbuf_release(&diagnostics_path); return res; } From patchwork Mon Aug 1 21:14:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12934063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09F2EC19F29 for ; Mon, 1 Aug 2022 21:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235076AbiHAVPR (ORCPT ); Mon, 1 Aug 2022 17:15:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235006AbiHAVPL (ORCPT ); Mon, 1 Aug 2022 17:15:11 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1094CB34 for ; Mon, 1 Aug 2022 14:15:09 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id v131-20020a1cac89000000b003a4bb3f786bso2277329wme.0 for ; Mon, 01 Aug 2022 14:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=e86Lata680xF4IBrHAgj4iHEKpc70lcBjC912uqVMUU=; b=lNzGMCNAfSgNJyakvjqXPY3HjlKoac1Ztl7mHdpb/M/p3LPkLk8YbZeVYtnfnuyrg2 ilNqIARdHX3Ab5t72pnQZagA5Nb19GU8NAcnQ/SETvy1CnpQ38h5zA+ufNQb64T1bfz9 ge8THSMe64YZyA5KWPX2rFd6q0FpEs5A+Zo0fG7qpp03GEfHwv5l170VR7nWw/L6BUlI 0OmJLysMS0kRCqC7Y5wozzVHwofYKJC92MkF4OsPoWlwYYP3AYhN/TxRejLx3uy0+4Qz kyuBcrjtS5txpU6CbcB9zq+1YORUkM2K176CW6zldOgvAWpbAaVVB4l91o1W1AIZWpVz tpjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=e86Lata680xF4IBrHAgj4iHEKpc70lcBjC912uqVMUU=; b=3IsI7FJZldqGI+0wjYmmH25+pvm73u7NaBa4aAwwkt6X2opTL66HzP+Hlu5qr2d0pN x/eZzc0BXKUSZgXwI/GlcTGedVTtVqOmpb5fxwWA0fegt8XuMVdF5c47jBpx3m1VZfBs vQXGR3KfvPIMroT02dI2rfO3BjAiuwrdpg4XzFRUl1ZBHTXqv8xwCFXe1Cvnjm2qcDyZ XJZ/eQSfjiJoUcm/w4lECL7CPwRn6VKxJvrm6TabcldSjQtFr+ClV0jwJSpSx/ZteJke dqTwbfR8Fyx6Gyoc/OMOBd+z3z2IXlAM1WpQ2e1PU8KQ3P0p3aHiaVoTv7f60RM7M/3a vnsw== X-Gm-Message-State: AJIora/snOvEf28yw/crjkRrBnN0wHvBrDtT9VZ0w+1AwVazEUCjnQUC nbyCsw2UGGTk3U7HZr9mVozImF33vyk= X-Google-Smtp-Source: AGRyM1uxAIzDMoEzHxn8iKhN3Qa8yNzViVTStXiF+yO5m3CffeGQqIYc0fYPfumDJbyDRgOC36FaTg== X-Received: by 2002:a05:600c:4f95:b0:3a3:4612:6884 with SMTP id n21-20020a05600c4f9500b003a346126884mr12593110wmq.39.1659388507362; Mon, 01 Aug 2022 14:15:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm7567407wmb.6.2022.08.01.14.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 14:15:06 -0700 (PDT) Message-Id: <86d40a4bd15dc5f9198998f761f4c4cfa8f31e1d.1659388498.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 01 Aug 2022 21:14:58 +0000 Subject: [PATCH 7/7] scalar: update technical doc roadmap Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, johannes.schindelin@gmx.de, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Update the Scalar roadmap to reflect the completion of generalizing 'scalar diagnose' into 'git bugreport --diagnose'. Signed-off-by: Victoria Dye --- Documentation/technical/scalar.txt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Documentation/technical/scalar.txt b/Documentation/technical/scalar.txt index 08bc09c225a..1fa2f6d5f91 100644 --- a/Documentation/technical/scalar.txt +++ b/Documentation/technical/scalar.txt @@ -84,6 +84,9 @@ series have been accepted: - `scalar-diagnose`: The `scalar` command is taught the `diagnose` subcommand. +- `scalar-generalize-diagnose`: Move the functionality of `scalar diagnose` + into `git bugreport --diagnose`. + Roughly speaking (and subject to change), the following series are needed to "finish" this initial version of Scalar: @@ -91,12 +94,6 @@ Roughly speaking (and subject to change), the following series are needed to and implement `scalar help`. At the end of this series, Scalar should be feature-complete from the perspective of a user. -- Generalize features not specific to Scalar: In the spirit of making Scalar - configure only what is needed for large repo performance, move common - utilities into other parts of Git. Some of this will be internal-only, but one - major change will be generalizing `scalar diagnose` for use with any Git - repository. - - Move Scalar to toplevel: Move Scalar out of `contrib/` and into the root of `git`, including updates to build and install it with the rest of Git. This change will incorporate Scalar into the Git CI and test framework, as well as