From patchwork Thu Jul 22 12:54:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12394067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFF21C6377D for ; Thu, 22 Jul 2021 12:55:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5D216139A for ; Thu, 22 Jul 2021 12:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231924AbhGVMOi (ORCPT ); Thu, 22 Jul 2021 08:14:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbhGVMOh (ORCPT ); Thu, 22 Jul 2021 08:14:37 -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 1E8FCC061757 for ; Thu, 22 Jul 2021 05:55:12 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id m38-20020a05600c3b26b02902161fccabf1so1495678wms.2 for ; Thu, 22 Jul 2021 05:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AfXE2YPfrcya2S5gKxrerIGkt/VeI9ORrEjezAT9N/M=; b=pMwE4YVunOSoZ9Vh0Kbs7JVtAGYwJ8F8KA5LnfUfDTQ9L16dwfgZPn2oBnJ0tnoyUV mQGQ5WEcMqvDkuHVOXsBcbieY7xo/dd/sjkOQ+3OQx5Qrg7z64TQGt/s+dAzVPDw/QIy 38WL1epxKVgoQPDyewgClVCn1Q6SgkklvCawjrHciDg1KgIiwBx1WXP/d8K9n9mJhJ18 pxaUjr/c0c6ld9QLQGL5Q/xJJlFCAR272H6V7gBu+gYDd4MG5h1lBDol0rX8DVdFaJv2 rRVZ1hqPXwuHZZ+qA/DO7PNAqgaOU49fy5YlUrpDGp2uGAskPt4Vp8R4lFP71oFCkOyl Ssjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AfXE2YPfrcya2S5gKxrerIGkt/VeI9ORrEjezAT9N/M=; b=Ex0GRHt1K0gdL3K/ZPeYGTDdltVELNPjncQooW5OsJWW1m1RbUIPcHhnfUwoOY+NbJ DBFAzbx7YJvY2YwPlLTGeA5qULBA/2JEXUOQQNnikx7DunHxz0elc+f4PsMvBfPuMtY1 H7GvbAwVuELKVNnod050gkybk2hxy5jP9OWDLz3GUzz3Zc9sGvPQUtYqCzUUNA0c0ZM/ JSpawG0tX41CA6g1amZN5xhuAN2X7TR+LJ8UP+Dv21qAtV/o3fj0i8zXyJf+kFN7mOCn BpNgPwy6Gsl7I2hfcIE4jhcteEVh9zca0gTPHx7dTHUcn2shbRKuMp6U/F+x7WcVYmE0 K4Aw== X-Gm-Message-State: AOAM532lTGySshTZB23mRIYBj0tI3b9M9U6/YDZxmNP0a7Sx1U/Lzuux x7JsmKEfPjPX0FdwefO6cSHBBdPA/RfXfQ== X-Google-Smtp-Source: ABdhPJzazK0/8qJhbraUky2QNLgFQ6nG1WeQ7Uh8MXxMYPkvltlGfizh5Bd9CqFvCkJn8lWJ+YgOzQ== X-Received: by 2002:a1c:7918:: with SMTP id l24mr41999144wme.107.1626958510365; Thu, 22 Jul 2021 05:55:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:09 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 1/8] progress.c tests: make start/stop verbs on stdin Date: Thu, 22 Jul 2021 14:54:59 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: References: <20210620200303.2328957-1-szeder.dev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the usage of the "test-tool progress" introduced in 2bb74b53a49 (Test the progress display, 2019-09-16) to take command like "start" and "stop" on stdin, instead of running them implicitly. This makes for tests that are easier to read, since the recipe will mirror the API usage, and allows for easily testing invalid usage that would yield (or should yield) a BUG(), e.g. providing two "start" calls in a row. A subsequent commit will add such stress tests. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-progress.c | 43 +++++++++++++++++++-------- t/t0500-progress-display.sh | 59 +++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 5d05cbe789..685c0a7c49 100644 --- a/t/helper/test-progress.c +++ b/t/helper/test-progress.c @@ -3,6 +3,9 @@ * * Reads instructions from standard input, one instruction per line: * + * "start[ [ ]]" - Call start_progress(title, total), + * when "start" use a title of + * "Working hard" with a total of 0. * "progress <items>" - Call display_progress() with the given item count * as parameter. * "throughput <bytes> <millis> - Call display_throughput() with the given @@ -10,6 +13,7 @@ * specify the time elapsed since the * start_progress() call. * "update" - Set the 'progress_update' flag. + * "stop" - Call stop_progress(). * * See 't0500-progress-display.sh' for examples. */ @@ -22,31 +26,41 @@ int cmd__progress(int argc, const char **argv) { - int total = 0; - const char *title; + const char *default_title = "Working hard"; + char *detached_title = NULL; struct strbuf line = STRBUF_INIT; - struct progress *progress; + struct progress *progress = NULL; const char *usage[] = { - "test-tool progress [--total=<n>] <progress-title>", + "test-tool progress <stdin", NULL }; struct option options[] = { - OPT_INTEGER(0, "total", &total, "total number of items"), OPT_END(), }; argc = parse_options(argc, argv, NULL, options, usage, 0); - if (argc != 1) - die("need a title for the progress output"); - title = argv[0]; + if (argc) + usage_with_options(usage, options); progress_testing = 1; - progress = start_progress(title, total); while (strbuf_getline(&line, stdin) != EOF) { char *end; - if (skip_prefix(line.buf, "progress ", (const char **) &end)) { + if (!strcmp(line.buf, "start")) { + progress = start_progress(default_title, 0); + } else if (skip_prefix(line.buf, "start ", (const char **) &end)) { + uint64_t total = strtoull(end, &end, 10); + if (*end == '\0') { + progress = start_progress(default_title, total); + } else if (*end == ' ') { + free(detached_title); + detached_title = strbuf_detach(&line, NULL); + progress = start_progress(end + 1, total); + } else { + die("invalid input: '%s'\n", line.buf); + } + } else if (skip_prefix(line.buf, "progress ", (const char **) &end)) { uint64_t item_count = strtoull(end, &end, 10); if (*end != '\0') die("invalid input: '%s'\n", line.buf); @@ -63,12 +77,15 @@ int cmd__progress(int argc, const char **argv) die("invalid input: '%s'\n", line.buf); progress_test_ns = test_ms * 1000 * 1000; display_throughput(progress, byte_count); - } else if (!strcmp(line.buf, "update")) + } else if (!strcmp(line.buf, "update")) { progress_test_force_update(); - else + } else if (!strcmp(line.buf, "stop")) { + stop_progress(&progress); + } else { die("invalid input: '%s'\n", line.buf); + } } - stop_progress(&progress); + free(detached_title); return 0; } diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index 22058b503a..ca96ac1fa5 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -17,6 +17,7 @@ test_expect_success 'simple progress display' ' EOF cat >in <<-\EOF && + start 0 update progress 1 update @@ -25,8 +26,9 @@ test_expect_success 'simple progress display' ' progress 4 update progress 5 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -41,11 +43,13 @@ test_expect_success 'progress display with total' ' EOF cat >in <<-\EOF && + start 3 progress 1 progress 2 progress 3 + stop EOF - test-tool progress --total=3 "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -62,14 +66,14 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6 progress 100 progress 1000 progress 10000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6" \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -88,16 +92,15 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && - update + start 100000 Working hard.......2.........3.........4.........5.........6 progress 1 update progress 2 progress 10000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6" \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -116,14 +119,14 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6 progress 25000 progress 50000 progress 75000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6" \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -140,14 +143,14 @@ Working hard.......2.........3.........4.........5.........6.........7.........: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6.........7......... progress 25000 progress 50000 progress 75000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6.........7........." \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -164,12 +167,14 @@ test_expect_success 'progress shortens - crazy caller' ' EOF cat >in <<-\EOF && + start 1000 progress 100 progress 200 progress 1 progress 1000 + stop EOF - test-tool progress --total=1000 "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -185,6 +190,7 @@ test_expect_success 'progress display with throughput' ' EOF cat >in <<-\EOF && + start throughput 102400 1000 update progress 10 @@ -197,8 +203,9 @@ test_expect_success 'progress display with throughput' ' throughput 409600 4000 update progress 40 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -214,6 +221,7 @@ test_expect_success 'progress display with throughput and total' ' EOF cat >in <<-\EOF && + start 40 throughput 102400 1000 progress 10 throughput 204800 2000 @@ -222,8 +230,9 @@ test_expect_success 'progress display with throughput and total' ' progress 30 throughput 409600 4000 progress 40 + stop EOF - test-tool progress --total=40 "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -239,6 +248,7 @@ test_expect_success 'cover up after throughput shortens' ' EOF cat >in <<-\EOF && + start throughput 409600 1000 update progress 1 @@ -251,8 +261,9 @@ test_expect_success 'cover up after throughput shortens' ' throughput 1638400 4000 update progress 4 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -267,6 +278,7 @@ test_expect_success 'cover up after throughput shortens a lot' ' EOF cat >in <<-\EOF && + start throughput 1 1000 update progress 1 @@ -276,8 +288,9 @@ test_expect_success 'cover up after throughput shortens a lot' ' throughput 3145728 3000 update progress 3 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -285,6 +298,7 @@ test_expect_success 'cover up after throughput shortens a lot' ' test_expect_success 'progress generates traces' ' cat >in <<-\EOF && + start 40 throughput 102400 1000 update progress 10 @@ -297,10 +311,11 @@ test_expect_success 'progress generates traces' ' throughput 409600 4000 update progress 40 + stop EOF - GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress --total=40 \ - "Working hard" <in 2>stderr && + GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress \ + <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. test_region progress "Working hard" trace.event && From patchwork Thu Jul 22 12:55:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394069 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D959DC6377D for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC5B56137D for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232042AbhGVMOk (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbhGVMOi (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:38 -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 F05AFC061575 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:12 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id l7so5830962wrv.7 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kk/3xkfv7KDZcog8KY7lY+9twPmyj1guz2egAszznhU=; b=Qq+6ic6BrYvGcAC6Fvrh5T0azoL6KcP1sTsDXo758o7z5PXjlsRQrg0mZpkU6hGsE5 3R4tHhBKkhbxNEaa5Y/q8C0L9Cy9P4rXgghqfL9Ln2FcjFTtRdEZPSJmsgAIQNcofDpH TvFPJF2DJaghwXO02XROkqvZSGWsdvsQjlEbcZwY6YqCYaRAclBI3BGZ+4VLKvCfHrNb v5GBFuj6WRvUW9XgC3AQGwqMK3cSP7VXTegJi5K7mHQjWdPi3Mc1SboTPxC3sAq5VzaM I4SguztwqgVViN5Hj9O0mXNP1balXKdFA9d2b6B06Dq7Fz8Ut0cBK90vdxMKhf5wxshX 1Tlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kk/3xkfv7KDZcog8KY7lY+9twPmyj1guz2egAszznhU=; b=QP8/fxzdByKq9nkK0AiBOC+2X0AoQ8CUeCM1e1Z9S1PG0YUvgq6+F9fRqmkJ7/3xTI 8YhhSoaoLihd8dnc/u3J71Y4lOP9QTMv07pCLUjwuz3geLKNj4ItlcpfIpWdEtWCgWw5 vATVtQYH12kfr1Q1aKZulh1HLxqkdrZfLqmHtCk8jk6En3ezQjHYiD8bQYpgl/r1cgyh ZgLboOotQWJe/v+dQifFyYi3/o6yp74iT2Z3/eAltYG/5BB6hSes+WU+fPDNmh7nTund KyBNdt8l9bSHQsN9LLJeeVb3X3jazCyVUAfbBwuo6eQp2tkfiL4Z/XshDlmTvUNZGPP7 SYKA== X-Gm-Message-State: AOAM531LG/2LLLdYAcInQB9ySu+2gwBxWfS/OLQpzicM7jEN947nQcaO hIOyQA0hql9kxnWLg1OXJbXYIIbiS4YLOg== X-Google-Smtp-Source: ABdhPJy+f47SVEmHT1Pd+K2HO/Md2XtaV8NGs0bBHItSenjC8bseqAXPTudr6YxLEY7+iyD0F5sVgA== X-Received: by 2002:a5d:608c:: with SMTP id w12mr24974676wrt.53.1626958511315; Thu, 22 Jul 2021 05:55:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:10 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 2/8] progress.c tests: test some invalid usage Date: Thu, 22 Jul 2021 14:55:00 +0200 Message-Id: <patch-2.8-2dc0d255c8-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Test what happens when we "stop" without a "start", omit the "stop" after a "start", or try to start two concurrent progress bars. This extends the trace2 tests added in 98a13647408 (trace2: log progress time and throughput, 2020-05-12). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0500-progress-display.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index ca96ac1fa5..ffa819ca1d 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -323,4 +323,37 @@ test_expect_success 'progress generates traces' ' grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event ' +test_expect_success 'progress generates traces: stop / start' ' + cat >in <<-\EOF && + start + stop + EOF + + GIT_TRACE2_EVENT="$(pwd)/trace-startstop.event" test-tool progress \ + <in 2>stderr && + test_region progress "Working hard" trace-startstop.event +' + +test_expect_success 'progress generates traces: start without stop' ' + cat >in <<-\EOF && + start + EOF + + GIT_TRACE2_EVENT="$(pwd)/trace-start.event" test-tool progress \ + <in 2>stderr && + grep region_enter.*progress trace-start.event && + ! grep region_leave.*progress trace-start.event +' + +test_expect_success 'progress generates traces: stop without start' ' + cat >in <<-\EOF && + stop + EOF + + GIT_TRACE2_EVENT="$(pwd)/trace-stop.event" test-tool progress \ + <in 2>stderr && + ! grep region_enter.*progress trace-stop.event && + ! grep region_leave.*progress trace-stop.event +' + test_done From patchwork Thu Jul 22 12:55:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394071 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE3A8C63797 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B65576139A for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232054AbhGVMOm (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbhGVMOj (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:39 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D08C061757 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:13 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id f17so5830557wrt.6 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7UncCd9MO7yaV5/Dm2Q57Vd3+VlDfWXcAYWvvQQRVWo=; b=tdQi2/cxIMTymB6eR/j+EF7m11S2dl5p01SP2oCF0QBHz13T7Yor359ePwxfDY/gs0 LohWlCpGLtDgXjfj93Y3hZdqZ4FkaGSQsVtV7GlwE0NTHBzr3WAb9ywl0xzO17pC7+B3 eV/0+yBzAC8UaFD6wdQCfXxpvpqyRFnzR+RidiYsnDlFx/Z+yv3Qw20lijVYb+kqWIyL K/UUao10CGBqHG2nzYhBw2Z/zqS8AkpWsOYZXo1JUD6Zgec5vA5Wfy6jzxG5Q80nSzpw zNgpvJ7Jx/W6OnUaCE6rfQRFq5UZ++Nf+7vzv4fpcf9ReHDKBW0MPMfuHyEm1Z5SG3ox 7qaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7UncCd9MO7yaV5/Dm2Q57Vd3+VlDfWXcAYWvvQQRVWo=; b=hxG/XULkC08A0vz9sb/nJKB1kydF+eSvz0sX0zil+xVqhZ5zZ//KIAyE8KeRX09aPJ eZIT24h9mJi7sO4NjIcQ9/vNyezaecrBEhnLnPAqySFE60POtwnUehvsLgaF6AopfkNB lxe0c4D6q0cuS2ATwn3zLgUST2TP0LEx5ahwt498QzzfQcb3peNVb5p81bQTwtagJMXP D31hxAT+ifMpUZ1r4UUT4ftaxzIyE7H+eVyKJxkqI+ReN9g6TSJdKOiGGWUlCPTegYBo rW+4mvwO5Aq4+QPTbe+Rns8cE0q3Luv/FTMocnwJ2afAe7OFrgFnhkVEmmEPIXirDfoR GmwQ== X-Gm-Message-State: AOAM531jgjCbSqwAd4SrGSGUQejzxVu9FN7tHL4iL36w28ZDcp57sqBW gzr8avjOSZv7CF19kotT4tZuuEJiU1Oz4g== X-Google-Smtp-Source: ABdhPJwLnw20L3i1fR4uymw2BKDOk2+Fdusfcxy2Bn9ZnlsGSgAL/qb2JxRasAxU7PjMdj4aZ4SUsg== X-Received: by 2002:a5d:488a:: with SMTP id g10mr47157146wrq.327.1626958512161; Thu, 22 Jul 2021 05:55:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 3/8] progress.c: move signal handler functions lower Date: Thu, 22 Jul 2021 14:55:01 +0200 Message-Id: <patch-3.8-b91e37fdb5-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Move the signal handler functions to just before the start_progress_delay() where they'll be referenced, instead of having them at the top of the file. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 92 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/progress.c b/progress.c index 680c6a8bf9..893cb0fe56 100644 --- a/progress.c +++ b/progress.c @@ -53,50 +53,6 @@ static volatile sig_atomic_t progress_update; */ int progress_testing; uint64_t progress_test_ns = 0; -void progress_test_force_update(void) -{ - progress_update = 1; -} - - -static void progress_interval(int signum) -{ - progress_update = 1; -} - -static void set_progress_signal(void) -{ - struct sigaction sa; - struct itimerval v; - - if (progress_testing) - return; - - progress_update = 0; - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = progress_interval; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction(SIGALRM, &sa, NULL); - - v.it_interval.tv_sec = 1; - v.it_interval.tv_usec = 0; - v.it_value = v.it_interval; - setitimer(ITIMER_REAL, &v, NULL); -} - -static void clear_progress_signal(void) -{ - struct itimerval v = {{0,},}; - - if (progress_testing) - return; - - setitimer(ITIMER_REAL, &v, NULL); - signal(SIGALRM, SIG_IGN); - progress_update = 0; -} static int is_foreground_fd(int fd) { @@ -249,6 +205,54 @@ void display_progress(struct progress *progress, uint64_t n) display(progress, n, NULL); } +static void progress_interval(int signum) +{ + progress_update = 1; +} + +/* + * The progress_test_force_update() function is intended for testing + * the progress output, i.e. exclusively for 'test-tool progress'. + */ +void progress_test_force_update(void) +{ + progress_update = 1; +} + +static void set_progress_signal(void) +{ + struct sigaction sa; + struct itimerval v; + + if (progress_testing) + return; + + progress_update = 0; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = progress_interval; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + sigaction(SIGALRM, &sa, NULL); + + v.it_interval.tv_sec = 1; + v.it_interval.tv_usec = 0; + v.it_value = v.it_interval; + setitimer(ITIMER_REAL, &v, NULL); +} + +static void clear_progress_signal(void) +{ + struct itimerval v = {{0,},}; + + if (progress_testing) + return; + + setitimer(ITIMER_REAL, &v, NULL); + signal(SIGALRM, SIG_IGN); + progress_update = 0; +} + static struct progress *start_progress_delay(const char *title, uint64_t total, unsigned delay, unsigned sparse) { From patchwork Thu Jul 22 12:55:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394075 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B653C63793 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E675C613AF for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232062AbhGVMOn (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232034AbhGVMOk (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:40 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 888F2C061760 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:14 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id i94so5835725wri.4 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QuEBlfzrkQk5xOURYJd9UI9s7AJMfkuT1nU7IrwGr8U=; b=JwSyIqHsaxLmE3YgVtSyJyIFMKKFv5NwBEpWacunsZWCJebJHt9zOJ5MBMsWHqG2l9 L0zy+LcLCYMAOUUWDT3VSrsgtkCmvAKtEaV29R1mkNK30m88jzHJ5DD/UB9Ds9yrBXw3 UsHQZjWyN7B9RZWCnZ53oHRh3owbSiPRDcCMDQ4TwHtHyBdvIa3LoMMVLgCSShCFaxiB 6M4Xx3iMlW1clPKe7GuduMU1bxzwhAEZHpFzPwmK8PbmGYDbgnTcJwT5mGNYsvsYDNuh YVme45NaMDCrc9TxgjL57T5WPZutBMZeRG/RCGKmRN5XMFJXIyztodQp1q8+P6NDzsdO hbcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QuEBlfzrkQk5xOURYJd9UI9s7AJMfkuT1nU7IrwGr8U=; b=bRqH88dhiPE2DuXFt8fCL3CamWAyvXN6hTCPJeK7w6IczvixdSmGOLUsKh7h4E7GGx XStBl+IG+ZWg7ConKuOPtGM9eCu5kRe2oCMcuYm6i75WwyzUYThvDw30KV8VyKefvq1Z 4jNgBN16z5vqwNGRVX8QtEtOPCn4zWv2U6YQsHVEhbTCc5aLa6NjBbx2Oa6bK3MqEc/v H+gjyu878AASrR83LuVaZXw3ituawzJFJPOFW9tajRRKoplSJmS3CI5kP6Z0MGA/Ho5e mmnn7QIk+kRYNgd1h3k5NKVJo+DVCJ1BtjneiAM0lvLKrapo3+MBXQXPM7n3IFladM3f zv3w== X-Gm-Message-State: AOAM530n4R6MdVi9fB3ota0QKueUuCiEpiRdRkgIKoMH/vw2jorW2LgX sGxyq+p+7929yKTqkOZnXV2HheWOSCSmXg== X-Google-Smtp-Source: ABdhPJxP9GArxbJFeqZ7qLJnQdQBbGXtC5deW2V73vlirrq0yZK5HhPajh7TTBixiT/vhl0tOJwYEA== X-Received: by 2002:a5d:4cce:: with SMTP id c14mr29806415wrt.258.1626958512954; Thu, 22 Jul 2021 05:55:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 4/8] progress.c: call progress_interval() from progress_test_force_update() Date: Thu, 22 Jul 2021 14:55:02 +0200 Message-Id: <patch-4.8-ac07681f24-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Define the progress_test_force_update() function in terms of progress_interval(). For documentation purposes these two functions have the same body, but different names. Let's just define the test function by calling progress_interval() with SIGALRM ourselves. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress.c b/progress.c index 893cb0fe56..7fcc513717 100644 --- a/progress.c +++ b/progress.c @@ -216,7 +216,7 @@ static void progress_interval(int signum) */ void progress_test_force_update(void) { - progress_update = 1; + progress_interval(SIGALRM); } static void set_progress_signal(void) From patchwork Thu Jul 22 12:55:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394073 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 798BFC63798 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DA2A613AF for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232043AbhGVMOn (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232037AbhGVMOk (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:40 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B633C061575 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:15 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id k4so5842877wrc.8 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9xDLHXB2f/ASz+P6hhlWGWR2Hrfb6NKMRbR/o789aS8=; b=GoPXrWTKoSRLC9tBZtA9XBqr9X+oCO8W4y+WivZ9Y3oUlpF5cwRUfrPLzbQQ3EwbjK V4642srXsIym+tviB+E/LKVHJy3xx0uc7L2qwH1YvPVg12pKXreW0FthkvaMhtI8ReCo M4ihb1pQGDqb9AAmPSA1qzz31Y4qh/gg70dcC2HLsFktltLST7AQSBBZHcBh6suYRKcT cP3gXYUuZtWx2OPO7Fc2YZkRxp8cyutFNSSCgsZuyuMDeiCkBdjxGEBMsRTMtOuU2BAb mme7m3NFQ2whL9D56bv2JSSS6z7OUwBFnpW8beoMr0LRtAA/eixdgiSivOJetjNJ4V75 FDrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9xDLHXB2f/ASz+P6hhlWGWR2Hrfb6NKMRbR/o789aS8=; b=iflOTi8r/6zSV7hwAHvNsp4Uz/nw5IkpGjfdF14l1cg74sS1TVJ8e0VSeOzMAULiSF vaRcJy4AoL9XAGwZTPz/Y7Ha14xTRU8X7ttN78e6h1zvDIxWA3jn7vw9PbDX6dFWW7WM ULlzFv92LL/Q4aslQMMTwjUHStaSM94jEa5JKuigAYsP+z0aqybv34fZLThPt43ULD0w Rr8E+tRMPCmNuVAcQK7Tv8BlaiSlYGIP0QHVO+B+O+mWsMiZJmxv2cfck8mt1q5CxlMY gVEWGNA2SLYWLCWh+Idi2uXXWYFV+saCcy/jHULgk+mUiinVNvZwfeYFtaTRJVMSayXJ CasA== X-Gm-Message-State: AOAM532X0DoBRFCQvv6vOX8i1kAaEY2WDmoLmXfBbsPst+O/lVM9J5zG UYyutXPYE4xk9zqOJj50SsC3WK0ku68AoQ== X-Google-Smtp-Source: ABdhPJwMyxx+B/f9fAbnqRfTTlv5MNHEc2iWV9rG4JoRSu0Eb/VCS0VCVR36/LU5Y8jck1GyX18+6w== X-Received: by 2002:a5d:634c:: with SMTP id b12mr47641367wrw.238.1626958513650; Thu, 22 Jul 2021 05:55:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 5/8] progress.c: stop eagerly fflush(stderr) when not a terminal Date: Thu, 22 Jul 2021 14:55:03 +0200 Message-Id: <patch-5.8-dea3df8ba6-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org It's the clear intention of the combination of 137a0d0ef56 (Flush progress message buffer in display()., 2007-11-19) and 85cb8906f0e (progress: no progress in background, 2015-04-13) to call fflush(stderr) when we have a stderr in the foreground, but we ended up always calling fflush(stderr) seemingly by omission. Let's not. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/progress.c b/progress.c index 7fcc513717..1fade5808d 100644 --- a/progress.c +++ b/progress.c @@ -91,7 +91,8 @@ static void display(struct progress *progress, uint64_t n, const char *done) } if (show_update) { - if (is_foreground_fd(fileno(stderr)) || done) { + int stderr_is_foreground_fd = is_foreground_fd(fileno(stderr)); + if (stderr_is_foreground_fd || done) { const char *eol = done ? done : "\r"; size_t clear_len = counters_sb->len < last_count_len ? last_count_len - counters_sb->len + 1 : @@ -115,7 +116,8 @@ static void display(struct progress *progress, uint64_t n, const char *done) fprintf(stderr, "%s: %s%*s", progress->title, counters_sb->buf, (int) clear_len, eol); } - fflush(stderr); + if (stderr_is_foreground_fd) + fflush(stderr); } progress_update = 0; } From patchwork Thu Jul 22 12:55:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394077 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1C61C63793 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F55E61396 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232070AbhGVMOp (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbhGVMOm (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:42 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC93C0613C1 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:16 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id f10-20020a05600c4e8ab029023e8d74d693so2908526wmq.3 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kb4BD9biQ2CFmv0xDa6kME+4jiF1xCEPXWBGnXU3WPQ=; b=QlzY31kLgSBK8UkHXNQ/tXt4nJ7/fYCaPTlnunkbQKGNECA69DTKdouXWL8zFl/DY/ 6kzvIQ5C9tsTXasYa3d22X1iOI4rOLfTvkzS/JlYK0s3HUxX2efZsU8xNwP6WlMgVBW1 Z2HgROoTbBvaZ2MABc3WXd54YP/6xGygo3IC2jat9ZbQIUEBvkHyh/YkkyTfWggVeV9h kmaaFUU6YlWgRUMeG087tZ+UDXkGSWn2Pm+BQ8zROfjtN8b/qBFHSE02vUYoa7SbYaQO tGO7UCAiEP1kOz4tMPXUSAHmN5zoaI2XV4gC7nIERmbvlLvywgUkj39C66yR3mqpxGtW uNCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kb4BD9biQ2CFmv0xDa6kME+4jiF1xCEPXWBGnXU3WPQ=; b=WvwQ3XOmK5QdKfB/kGoh/8Zrdt37MNnoOgSf7IQPreKVRgQ8D3H/2EMKnfq/3aRGXX ELslakG++cOUgQVzd2U6g3Qj2z77LTlUG3cn0G5vcx+LlVAs2djOTFQD3f1ozE7dAEy9 ICUMf4P/fZMc8ixColpa2mimdsGVby4iauVan+iaUJrAezBhuayqYh2ThGYLFvj1S02v 8DoWXRCT8hkTAB1S6MmFj5/FHH0EzP8oFOcsW3hhMhRPSQgj8P4uI8HOs504bT5D53st 1dp9kR1wpOjrS4GH2gALqvbzFiGoqPKfVyeDB140hql50CtuEU7Qk9oXXJHXTeFcWaPY o2zA== X-Gm-Message-State: AOAM530fp8PUCsLMrRC6dF9sGWPGZM08sxXwr19OITR9Hni21jDE1mTd IEiBmGs/seMSwWQRFGTS39FOwoquOAVkig== X-Google-Smtp-Source: ABdhPJwxz9lZd7oTgFm9F45duNv5UgpPSg4lMoVBnExRk/nb6GwiTRUx1kG37P6PAdhzw16haG2F9Q== X-Received: by 2002:a7b:c4d2:: with SMTP id g18mr42333803wmk.146.1626958514432; Thu, 22 Jul 2021 05:55:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 6/8] progress.c: add temporary variable from progress struct Date: Thu, 22 Jul 2021 14:55:04 +0200 Message-Id: <patch-6.8-b99bb60dca-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Add a temporary "progress" variable for the dereferenced p_progress pointer to a "struct progress *". Before 98a13647408 (trace2: log progress time and throughput, 2020-05-12) we didn't dereference "p_progress" in this function, now that we do it's easier to read the code if we work with a "progress" struct pointer like everywhere else, instead of a pointer to a pointer. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/progress.c b/progress.c index 1fade5808d..1ab7d19deb 100644 --- a/progress.c +++ b/progress.c @@ -331,15 +331,16 @@ void stop_progress(struct progress **p_progress) finish_if_sparse(*p_progress); if (*p_progress) { + struct progress *progress = *p_progress; trace2_data_intmax("progress", the_repository, "total_objects", (*p_progress)->total); if ((*p_progress)->throughput) trace2_data_intmax("progress", the_repository, "total_bytes", - (*p_progress)->throughput->curr_total); + progress->throughput->curr_total); - trace2_region_leave("progress", (*p_progress)->title, the_repository); + trace2_region_leave("progress", progress->title, the_repository); } stop_progress_msg(p_progress, _("done")); From patchwork Thu Jul 22 12:55:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394079 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4679C63797 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98EF3613AA for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbhGVMOu (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbhGVMOn (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:43 -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 BF738C0613D3 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:16 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 14-20020a05600c028eb0290228f19cb433so1522280wmk.0 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BaTcA4Pw6YAbdti/IFIkJuLoqPKanlTk+2jSFeMI9DI=; b=fm6qUTylfi5O15ElPoZAbcGLEFnI8B9p1NDJFppimD/7WOm9GobNQedv26s02VSCk0 yJjbCpsOxVVB7YBsJUsFUeQYdr6+M+k1uac0V/k0t9UZsx3zmBdfkBeeefsOQFWgvsLL iXgpVmTVsl5b7mEblvAZJgxRQ5+qA+VR08oeVejF/MR+bpApzLeYadL0dmmcUMxLmQ2W uMKT1o2XhPORcnilpRgSkaEqVPcLSVhQBQv/1EnWSHe54ivVjtqCfhY0amFwNoxIyFgf J++bsZ0Gctvor1Ep76heKh46/R3PNUWj1r4m3cwj1fmn/qSPUnkV+iDWmCdL8Vx34PMe gX/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BaTcA4Pw6YAbdti/IFIkJuLoqPKanlTk+2jSFeMI9DI=; b=j8K3bNymRnyfAdOnqHMexkeh6rREWDQWu4Ao6ulf9SabJ9OI+7oXnrXN+hTgDqi7nr Az98ufIW6SidJmzyNXn++WFDgA3YvTkujiCbDmMZV3U1cxdYUmdSe71n1iVTMH8IZYYn aTJw6vqazFKAZRW/TEHboaiSZemJR2mbRTC8lErkQxXnJcxqDCfOq1C9apJ+2M944hEB /dxcdrXMiZ40816tx+IzCN8YG7KjD7KDc5cTAkchqOCYmEsb0wrzxAyUg3L7xsNH+/S2 h1Fa/d21eWEPVM+5Ndzv2TotJTdtftpjYwlPe6OnI8KsHde/6FTUmgiTrcyQzQAvh0Tq +0wg== X-Gm-Message-State: AOAM532BOj2YdcOpQ4ObqqiZRNmVKFrSTC62mdTQjFax2eA9wB1W9PY/ ZS38GYCe8mBLo7b/lZ0Hg1V5qsXUwD1akA== X-Google-Smtp-Source: ABdhPJyX5PpVCP3BGHxAmk78v0Lsi5qG9VWX6N9dxlWQH1Ts3z3Q462N7UuIZ2y2m93BAWuKfGImxQ== X-Received: by 2002:a7b:c193:: with SMTP id y19mr9207768wmi.86.1626958515164; Thu, 22 Jul 2021 05:55:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 7/8] pack-bitmap-write.c: add a missing stop_progress() Date: Thu, 22 Jul 2021 14:55:05 +0200 Message-Id: <patch-7.8-eb63b4ba6a-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Fix a bug that's been here since 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21), we did not call stop_progress() if we reached the early exit in this function. This will matter in a subsequent commit where we BUG(...) out if this happens, and matters now e.g. because we don't have a corresponding "region_end" for the progress trace2 event. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- pack-bitmap-write.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 88d9e696a5..6e110e41ea 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -550,6 +550,7 @@ void bitmap_writer_select_commits(struct commit **indexed_commits, if (indexed_commits_nr < 100) { for (i = 0; i < indexed_commits_nr; ++i) push_bitmapped_commit(indexed_commits[i]); + stop_progress(&writer.progress); return; } From patchwork Thu Jul 22 12:55:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12394081 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D2E8C63793 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 464D061396 for <git@archiver.kernel.org>; Thu, 22 Jul 2021 12:55:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbhGVMOv (ORCPT <rfc822;git@archiver.kernel.org>); Thu, 22 Jul 2021 08:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232041AbhGVMOn (ORCPT <rfc822;git@vger.kernel.org>); Thu, 22 Jul 2021 08:14:43 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B2B8C0613D5 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:17 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id i94so5835898wri.4 for <git@vger.kernel.org>; Thu, 22 Jul 2021 05:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K4Vy+cSoK5dbndzGHvKRxK6XaBL7g7Xz+qOwbSPWW6k=; b=KIIIUH91UjENUdYr5bhWYnIsYIi0YmU57uWB+kl1QJ4qXiKTn8bHhTfTLUzDCH77b9 XjPK+Yeuxv8IW3g76J3MgAv3fUSERMBF/DQNbFkNj/FQsL3aiWNn5WuwGkRcKdiDC/O4 Ohk2+fFUAWnJp/wD7PBo90yAqmPlO9l5BzFE0xvIiX1tfyF19heRe3gR4yv4JFC8Lf90 DZI8LjfQbUzcPEis2woRyjAZnkAhh5rdlwp5em8G1KnyX07N1u8khlAEbJHaIYx4KnV1 6nekAtcAiOHB+zJunIrZSo5FaM2apWRsFuydqiblxflfiPRznO67LCVEdZx4qGTbOR1Z sL5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K4Vy+cSoK5dbndzGHvKRxK6XaBL7g7Xz+qOwbSPWW6k=; b=cYR8AXM/PmtsY6+kFqQ2AFCOqx7byFMIBFipvbybErnqs1twgIxgj6YpVX+Wst3Hmc yROkJgEq07YK1ruCehrZ1ms73oq99pcZBJwR+pJFNY04mqWNuSto7+VqovMB+fmP3PNI bW3p0mcolVLTsIQXouEd26bwuYhAsuwTkkvgMKrWFCFOkkgpAkegjPPNPdmHsZAocaJv 59NzgHf/F4bhjR92QTxDqU6GEE6iUCJapnqhJ6sH08zlQnVOopvOowneuSGFLI3eLFne DFlKsQp7hoQ0Nj27yg3gYi9qM5XfwaC4SrdmO5zElTD0bl6ek4KOE9Cec9mgarViGicI UPdw== X-Gm-Message-State: AOAM5329fswPDwixHNDQvnRtyYmwglmdgYqXTe5NVEaySbY3LmTBYInw 726NDQ+VUR3GFuSfg4Xzl625DQXoegJq0g== X-Google-Smtp-Source: ABdhPJz+l5kRX2Bl0UW8jpOTjNeANcQXvGKC9mIymnT1MP6zaPFDdieyT5bJL4lT/uPF3Lmh5l+AGQ== X-Received: by 2002:a05:6000:1841:: with SMTP id c1mr46744476wri.423.1626958515879; Thu, 22 Jul 2021 05:55:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g3sm29937483wru.95.2021.07.22.05.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:55:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH 8/8] progress.c: add & assert a "global_progress" variable Date: Thu, 22 Jul 2021 14:55:06 +0200 Message-Id: <patch-8.8-1a14176bee-20210722T125012Z-avarab@gmail.com> X-Mailer: git-send-email 2.32.0.957.gd9e39d72fe6 In-Reply-To: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> References: <20210620200303.2328957-1-szeder.dev@gmail.com> <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org The progress.c code makes a hard assumption that only one progress bar be active at a time (see [1] for a bug where this wasn't the case), but nothing has asserted that that's the case. Let's add a BUG() that'll trigger if two progress bars are active at the same time. There's an alternate test-only approach to doing the same thing[2], but by doing this for all progress bars we'll have a canary to check if we have any unexpected interaction between the "sig_atomic_t progress_update" variable and this global struct. I am then planning on using this scaffolding in the future to fix a limitation in the progress output, namely the current limitation of the progress.c bar code that any update must pro-actively go through the likes of display_progress(). If we e.g. hang forever before the first display_progress(), or in the middle of a loop that would call display_progress() the user will only see either no output, or output frozen at the last display_progress() that would have done an update (e.g. in cases where progress_update was "1" due to an earlier signal). This change does not fix that, but sets up the structure for solving that and other related problems by juggling this "global_progress" struct. Later changes will make more use of the "global_progress" than only using it for these assertions. 1. 6f9d5f2fda1 (commit-graph: fix progress of reachable commits, 2020-07-09) 2. https://lore.kernel.org/git/20210620200303.2328957-3-szeder.dev@gmail.com Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 17 +++++++++++++---- t/t0500-progress-display.sh | 11 +++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/progress.c b/progress.c index 1ab7d19deb..14a023f4b4 100644 --- a/progress.c +++ b/progress.c @@ -46,6 +46,7 @@ struct progress { }; static volatile sig_atomic_t progress_update; +static struct progress *global_progress; /* * These are only intended for testing the progress output, i.e. exclusively @@ -221,11 +222,15 @@ void progress_test_force_update(void) progress_interval(SIGALRM); } -static void set_progress_signal(void) +static void set_progress_signal(struct progress *progress) { struct sigaction sa; struct itimerval v; + if (global_progress) + BUG("should have no global_progress in set_progress_signal()"); + global_progress = progress; + if (progress_testing) return; @@ -243,10 +248,14 @@ static void set_progress_signal(void) setitimer(ITIMER_REAL, &v, NULL); } -static void clear_progress_signal(void) +static void clear_progress_signal(struct progress *progress) { struct itimerval v = {{0,},}; + if (!global_progress) + BUG("should have a global_progress in clear_progress_signal()"); + global_progress = NULL; + if (progress_testing) return; @@ -270,7 +279,7 @@ static struct progress *start_progress_delay(const char *title, uint64_t total, strbuf_init(&progress->counters_sb, 0); progress->title_len = utf8_strwidth(title); progress->split = 0; - set_progress_signal(); + set_progress_signal(progress); trace2_region_enter("progress", title, the_repository); return progress; } @@ -374,7 +383,7 @@ void stop_progress_msg(struct progress **p_progress, const char *msg) display(progress, progress->last_value, buf); free(buf); } - clear_progress_signal(); + clear_progress_signal(progress); strbuf_release(&progress->counters_sb); if (progress->throughput) strbuf_release(&progress->throughput->display); diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index ffa819ca1d..124d33c96b 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -296,6 +296,17 @@ test_expect_success 'cover up after throughput shortens a lot' ' test_cmp expect out ' +test_expect_success 'BUG: start two concurrent progress bars' ' + cat >in <<-\EOF && + start 0 one + start 0 two + EOF + + test_must_fail test-tool progress \ + <in 2>stderr && + grep -E "^BUG: .*: should have no global_progress in set_progress_signal\(\)$" stderr +' + test_expect_success 'progress generates traces' ' cat >in <<-\EOF && start 40