From patchwork Sun Oct 15 03:42:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Stopak X-Patchwork-Id: 13422171 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C3501C20 for ; Sun, 15 Oct 2023 03:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=initialcommit-io.20230601.gappssmtp.com header.i=@initialcommit-io.20230601.gappssmtp.com header.b="bxbHnit9" Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC1E5DD for ; Sat, 14 Oct 2023 20:43:07 -0700 (PDT) Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-57b67c84999so2243596eaf.3 for ; Sat, 14 Oct 2023 20:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=initialcommit-io.20230601.gappssmtp.com; s=20230601; t=1697341387; x=1697946187; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UgpirPUs1/aLlsdSbhL37G4kCfsWU4Sonlc+dqNu3Co=; b=bxbHnit9z3du/SNSg1NEQ+AX9/i8GzjJ3twj6JRsj+5gKv+UsAofln0/BUppOdWaiv +mb+AUNFoI7kGdkSMeXoR4GcbK0BLzvSIM+63dWFvPYcvJeJX4Wrv7WiXZYTRcdNVJvr +mMqJ9zaaurmaMr4L6n08VbhLw+jUPRRwgwTrCfvbLiwTCxnEkeq9NxREvGBfA/eg8d8 GTxQN4O83zwUYX6YzUT0zYSgNcBwTwJnUrUqeM1753xVBcCy/S5kevimTU4ts2xJqAG4 GWQUCSu2+KsGBTF8DWjGipCMfIRF47iKP1FtdwPtUORJzE8Jw/T+JtQfU21kx25ztI+4 +kCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697341387; x=1697946187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UgpirPUs1/aLlsdSbhL37G4kCfsWU4Sonlc+dqNu3Co=; b=Kh3JBtYNB2zZVji4eYLoeHmqGVytGEw8lAB5Hz0ZQpIFIs/OGp9oqM2TbOJsMbWNci D7nmE+Gi8biv+Tofeeg46ky/qqkrhHfQnHW7OKobUlvMdN0YF7MwikkisnRTxbWzG1ks /VWpDITynly6AgBRK81V4fLTQ+AfCJ0k073iw9etJM/NVOZey+z4fX77HgXjIbxRpvpQ IQShjdoaKWZoqAb3Y+Mw8KV4bkv1nbvh6Cifvz8Tf9PGBO2WDpQ4JrqTotQ3SxhZLZqS Kc/fZTemuU40qx8bmM5X74tJ3+xmIcbldEeP8vEvLJtm/mlfqmz/2tUI+IP7rGbZNR3d YfWA== X-Gm-Message-State: AOJu0YzQCCfZuu5yTefHp2y+4HGMONQCzi0KOM0ECzz1/qsO+4ByGTb0 THCddOX8YlEZGZ+H6yOIhR6I/JFjD+sZ6VXhp04= X-Google-Smtp-Source: AGHT+IHJ4G7yV3EldxoLNAabx+ayulwtYrvfmp894QKlzkiwiTGpji8qoJEF/p8+KA7GoKmqsfDIvw== X-Received: by 2002:a05:6358:52c5:b0:135:85ec:a080 with SMTP id z5-20020a05635852c500b0013585eca080mr38365343rwz.32.1697341386788; Sat, 14 Oct 2023 20:43:06 -0700 (PDT) Received: from localhost.localdomain (ip68-7-58-180.sd.sd.cox.net. [68.7.58.180]) by smtp.gmail.com with ESMTPSA id bq10-20020a056a02044a00b0059ce3d1def5sm510777pgb.45.2023.10.14.20.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 20:43:06 -0700 (PDT) From: Jacob Stopak To: git@vger.kernel.org Cc: Jacob Stopak Subject: [PATCH v2 1/3] bugreport: include +i in outfile suffix as needed Date: Sat, 14 Oct 2023 20:42:35 -0700 Message-ID: <20231015034238.100675-2-jacob@initialcommit.io> X-Mailer: git-send-email 2.42.0.298.gd89efca819.dirty In-Reply-To: <20231015034238.100675-1-jacob@initialcommit.io> References: <20231014040101.8333-1-jacob@initialcommit.io> <20231015034238.100675-1-jacob@initialcommit.io> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net When the -s flag is absent, git bugreport includes the current hour and minute values in the default bugreport filename (and diagnostics zip filename if --diagnose is supplied). If a user runs the bugreport command more than once within a calendar minute, a filename conflict with an existing file occurs and the program errors, since the new output filename was already used for the previous file. If the user waits anywhere from 1 to 60 seconds (depending on _when during the calendar minute_ the first command was run) the command works again with no error since the default filename is now unique, and multiple bug reports are able to be created with default settings. This is a minor thing but can cause confusion especially for first time users of the bugreport command, who are likely to run it multiple times in quick succession to learn how it works, (like I did). Add a '+i' into the bugreport filename suffix to make the filename unique, where 'i' is an integer starting at 1 and able to grow up to 9 in the unlikely event a user runs the command 9 times in a single minute. This leads to default output filenames like: git-bugreport-%Y-%m-%d-%H%M+1.txt git-bugreport-%Y-%m-%d-%H%M+2.txt ... git-bugreport-%Y-%m-%d-%H%M+9.txt This means the user will end up with multiple bugreport files being created if they run the command multiple times quickly, but that feels more intuitive and consistent than an error arbitrarily occuring within a calendar minute, especially given that the time window in which the error currently occurs is variable as described above. Signed-off-by: Jacob Stopak --- builtin/bugreport.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index d2ae5c305d..71ee7d7f4b 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -3,7 +3,6 @@ #include "editor.h" #include "gettext.h" #include "parse-options.h" -#include "strbuf.h" #include "help.h" #include "compat/compiler.h" #include "hook.h" @@ -11,6 +10,7 @@ #include "diagnose.h" #include "object-file.h" #include "setup.h" +#include "dir.h" static void get_system_info(struct strbuf *sys_info) { @@ -101,12 +101,13 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) { struct strbuf buffer = STRBUF_INIT; struct strbuf report_path = STRBUF_INIT; + struct strbuf option_suffix = STRBUF_INIT; + struct strbuf default_option_suffix = STRBUF_INIT; int report = -1; time_t now = time(NULL); struct tm tm; enum diagnose_mode diagnose = DIAGNOSE_NONE; 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; @@ -118,11 +119,14 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) PARSE_OPT_OPTARG, option_parse_diagnose), 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"), + OPT_STRING('s', "suffix", &option_suffix.buf, N_("format"), N_("specify a strftime format suffix for the filename(s)")), OPT_END() }; + strbuf_addstr(&default_option_suffix, "%Y-%m-%d-%H%M"); + strbuf_addstr(&option_suffix, default_option_suffix.buf); + argc = parse_options(argc, argv, prefix, bugreport_options, bugreport_usage, 0); @@ -134,9 +138,20 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) output_path_len = report_path.len; strbuf_addstr(&report_path, "git-bugreport-"); - strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0); + strbuf_addftime(&report_path, option_suffix.buf, localtime_r(&now, &tm), 0, 0); strbuf_addstr(&report_path, ".txt"); + if (strbuf_cmp(&option_suffix, &default_option_suffix) == 0) { + int i = 1; + int pos = report_path.len - 4; + while (file_exists(report_path.buf) && i < 10) { + if (i > 1) + strbuf_remove(&report_path, pos, 2); + strbuf_insertf(&report_path, pos, "+%d", i); + i++; + } + } + switch (safe_create_leading_directories(report_path.buf)) { case SCLD_OK: case SCLD_EXISTS: @@ -151,7 +166,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) 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_addftime(&zip_path, option_suffix.buf, localtime_r(&now, &tm), 0, 0); strbuf_addstr(&zip_path, ".zip"); if (create_diagnostics_archive(&zip_path, diagnose)) @@ -188,6 +203,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) free(prefixed_filename); strbuf_release(&buffer); + strbuf_release(&default_option_suffix); ret = !!launch_editor(report_path.buf, NULL, NULL); strbuf_release(&report_path); From patchwork Sun Oct 15 03:42:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Stopak X-Patchwork-Id: 13422172 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69893523D for ; Sun, 15 Oct 2023 03:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=initialcommit-io.20230601.gappssmtp.com header.i=@initialcommit-io.20230601.gappssmtp.com header.b="Kjyw0D01" Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92968E8 for ; Sat, 14 Oct 2023 20:43:22 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1dcdfeb7e44so2191312fac.0 for ; Sat, 14 Oct 2023 20:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=initialcommit-io.20230601.gappssmtp.com; s=20230601; t=1697341401; x=1697946201; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IY9+4TGZSEExMsw+da3TTbVRyFdWkcNxrGnfhd7UkDM=; b=Kjyw0D0186VyhLXZWLWwQXflKd1UgMzdanC0IZX1cI5l5j6v+9C2lPD9M5jgZaFkRQ UGmD/cZu7iXW+yj9Zodn84JYfc6VO+shptZyUHBhkywj0rPsTH5X5PLdpiRevawxBzrB nf2fvVUvJT/QdhILmczE03oNe8vbPu8mvESdLeaXmI6cVwX/DO/Zc+rSu8BmmYmMRBSa yhjsGIGu2C+Wlh7iYEJa7Wh1Kyyf2K/8e//l9rRD3c/dTnaOHIiGsGIfpu0AURYgEEuT t8Y9822M4SyJmtXkS5ey9UuRRA+bgyicoLIipQ4lQplc8Hgdi/E6DY/vbddPbRZX8QHm e/1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697341401; x=1697946201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IY9+4TGZSEExMsw+da3TTbVRyFdWkcNxrGnfhd7UkDM=; b=XPFbDL9ysfQa0GM0xbJxao0yleVw5VLV8/G8F2+Q9hP0/q9SavPl+m9r5PdlTNWNHr N3om5hmd0dM+ivV2UkdJxpjEmFy4CfcDt0HGcYbFvQuEppSCu1VnreszeRESXdd3f2p+ 2635GqXmGxGaFRaBdNA1RnmdNPplIkiZFv8gXZg1OkzoLJMHydm6vHiniAejqPTkn/up Bx+faxh0apOqSsCCdXtr1Bxh63g6Xycn7mjSoq3EavdqUitgHLQhidcHXFvVcQXyEvc9 svc9et1FoVvDWoYydLNugrtw9F+qTmb+oc7x6qlu2xVtjiJsJLrtMQPPAv+GptaLbbZR 1Jzg== X-Gm-Message-State: AOJu0YyAt3HfmbeCiLZSHwaPdO7bgofz8U3nfnLY14hHZL4mehC3K4tO 4e88S4tXu7eMZNsLJpbyu0GG0ICaVrIM1yGbMRM= X-Google-Smtp-Source: AGHT+IHq+xIARV5jNif2wFvb/YnQ1pY/cufpdWL0Irg8E6E8pU7cFNDHEEDS/TwYim7b49l9LOSpWg== X-Received: by 2002:a05:6871:610d:b0:1e9:bd5c:ae38 with SMTP id ra13-20020a056871610d00b001e9bd5cae38mr10657458oab.2.1697341401285; Sat, 14 Oct 2023 20:43:21 -0700 (PDT) Received: from localhost.localdomain (ip68-7-58-180.sd.sd.cox.net. [68.7.58.180]) by smtp.gmail.com with ESMTPSA id bq10-20020a056a02044a00b0059ce3d1def5sm510777pgb.45.2023.10.14.20.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 20:43:20 -0700 (PDT) From: Jacob Stopak To: git@vger.kernel.org Cc: Jacob Stopak Subject: [PATCH v2 2/3] bugreport: match diagnostics filename with report Date: Sat, 14 Oct 2023 20:42:36 -0700 Message-ID: <20231015034238.100675-3-jacob@initialcommit.io> X-Mailer: git-send-email 2.42.0.298.gd89efca819.dirty In-Reply-To: <20231015034238.100675-1-jacob@initialcommit.io> References: <20231014040101.8333-1-jacob@initialcommit.io> <20231015034238.100675-1-jacob@initialcommit.io> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net When using the --diagnose flag, match the diagnostics zip filename with the bugreport filename in the scenario where '+i' syntax is used. Signed-off-by: Jacob Stopak --- builtin/bugreport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 71ee7d7f4b..573d270677 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -112,6 +112,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) char *prefixed_filename; size_t output_path_len; int ret; + int i = 1; const struct option bugreport_options[] = { OPT_CALLBACK_F(0, "diagnose", &diagnose, N_("mode"), @@ -142,7 +143,6 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) strbuf_addstr(&report_path, ".txt"); if (strbuf_cmp(&option_suffix, &default_option_suffix) == 0) { - int i = 1; int pos = report_path.len - 4; while (file_exists(report_path.buf) && i < 10) { if (i > 1) @@ -167,6 +167,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) strbuf_add(&zip_path, report_path.buf, output_path_len); strbuf_addstr(&zip_path, "git-diagnostics-"); strbuf_addftime(&zip_path, option_suffix.buf, localtime_r(&now, &tm), 0, 0); + if (i > 1) strbuf_addf(&zip_path, "+%d", i-1); strbuf_addstr(&zip_path, ".zip"); if (create_diagnostics_archive(&zip_path, diagnose)) From patchwork Sun Oct 15 03:42:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Stopak X-Patchwork-Id: 13422173 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF6D353B5 for ; Sun, 15 Oct 2023 03:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=initialcommit-io.20230601.gappssmtp.com header.i=@initialcommit-io.20230601.gappssmtp.com header.b="P0DvzK/+" Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63FE1D6 for ; Sat, 14 Oct 2023 20:43:27 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1e562706d29so1942531fac.2 for ; Sat, 14 Oct 2023 20:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=initialcommit-io.20230601.gappssmtp.com; s=20230601; t=1697341406; x=1697946206; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3QpXSNr/Uo9V+OS81+Envn5yr9RoYGnankRhO8BtBj0=; b=P0DvzK/+9vpSM97qGwZypjwDQZSqYnbTaoGULF9/clyhKRtZVpd9YImj1m84qwUjL8 GJEa7OKZEAv/EcVqgQTsAeDlQYRT9/7+npOec0LX9mWaKmaOlVIFDBgCtUscLaKfYixv DcNtn4Okg3hpvIuWCj6nH7GYHOjE49h5S93JKZe1Ax4TKjh4Qq7DSgaamJ8/2JiCzj4h yqMPo6JX2HRI0QV9CuZlNtAO+cFaLZUqgwTJzHAKp61MKbTgB0vV6XX4fQPzFuIbM32P 8bYOcIXFFJaRVaVQQ6085Le/jsjbxOQHtgG8C81a1b4bAZQaQIsEKP4qeVLNNAFbhjYg WbcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697341406; x=1697946206; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3QpXSNr/Uo9V+OS81+Envn5yr9RoYGnankRhO8BtBj0=; b=JKJ5ghnDqKWIFH22blEiRKuHUTHfs3OxCBLW1oLLGYtwfQIYhdX+eZF0eu1ltHdM19 tpQemVdbJGuV+CzHdnP6WFH9YEmEPdCRGqVPq0CRObezSu3pE0sWOfRd9oizM5KJHYU5 lnDNkumYR4C1NivvdhEr8bwj6kJxnHxIifqsBwEQ2z+Y26Wd3blefs2wrl8pE9w9FSSP QFh8Qc73Ksi+7fjd9Ma++LjQXDMAARmBYfJWzdafYuppAZblvLZ7Cb4R0KZzhMgblG2+ YIWQYNyNMVREyA5DESJPhSfvbzfWKOV43RIpOuKfNRSyLqnNEo6vCQm9oR7mgCjK6oER ydNQ== X-Gm-Message-State: AOJu0Yz1mHPxYL0UP+wzajtkNlvodVTpIl2zCNUjBz6L7Y+rOt14n7Oz NAX0z6bpcyjWACSf5eczTyRm1NR28QOzFKMeG4E= X-Google-Smtp-Source: AGHT+IHc7oW74pOjpd7MeblGe8NOjlMY3isyRaWAwLIe9/C7faG1tgv0oLnhXYZHnA7doNtiSnPlrw== X-Received: by 2002:a05:6871:528d:b0:1e9:96c6:e04c with SMTP id hu13-20020a056871528d00b001e996c6e04cmr12750220oac.32.1697341406403; Sat, 14 Oct 2023 20:43:26 -0700 (PDT) Received: from localhost.localdomain (ip68-7-58-180.sd.sd.cox.net. [68.7.58.180]) by smtp.gmail.com with ESMTPSA id bq10-20020a056a02044a00b0059ce3d1def5sm510777pgb.45.2023.10.14.20.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 20:43:26 -0700 (PDT) From: Jacob Stopak To: git@vger.kernel.org Cc: Jacob Stopak Subject: [PATCH v2 3/3] bugreport: don't create --diagnose zip w/o report Date: Sat, 14 Oct 2023 20:42:37 -0700 Message-ID: <20231015034238.100675-4-jacob@initialcommit.io> X-Mailer: git-send-email 2.42.0.298.gd89efca819.dirty In-Reply-To: <20231015034238.100675-1-jacob@initialcommit.io> References: <20231014040101.8333-1-jacob@initialcommit.io> <20231015034238.100675-1-jacob@initialcommit.io> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Prevent the diagnostics zip file from being created when the bugreport itself is not created due to an error. Signed-off-by: Jacob Stopak --- builtin/bugreport.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 573d270677..91567806c9 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -161,21 +161,6 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) report_path.buf); } - /* Prepare diagnostics, if requested */ - if (diagnose != DIAGNOSE_NONE) { - 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.buf, localtime_r(&now, &tm), 0, 0); - if (i > 1) strbuf_addf(&zip_path, "+%d", i-1); - strbuf_addstr(&zip_path, ".zip"); - - if (create_diagnostics_archive(&zip_path, diagnose)) - die_errno(_("unable to create diagnostics archive %s"), zip_path.buf); - - strbuf_release(&zip_path); - } - /* Prepare the report contents */ get_bug_template(&buffer); @@ -202,6 +187,22 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) fprintf(stderr, _("Created new report at '%s'.\n"), user_relative_path); + /* Prepare diagnostics, if requested */ + if (diagnose != DIAGNOSE_NONE) { + 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.buf, localtime_r(&now, &tm), 0, 0); + if (i > 1) strbuf_addf(&zip_path, "+%d", i-1); + strbuf_addstr(&zip_path, ".zip"); + + if (create_diagnostics_archive(&zip_path, diagnose)) + die_errno(_("unable to create diagnostics archive %s"), zip_path.buf); + + strbuf_release(&zip_path); + } + + free(prefixed_filename); strbuf_release(&buffer); strbuf_release(&default_option_suffix);