From patchwork Tue Nov 30 21:38:03 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: 12648147 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 A923BC433FE for ; Tue, 30 Nov 2021 21:38:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344234AbhK3Vln (ORCPT ); Tue, 30 Nov 2021 16:41:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344191AbhK3Vlk (ORCPT ); Tue, 30 Nov 2021 16:41:40 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2621BC06174A for ; Tue, 30 Nov 2021 13:38:20 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id d72-20020a1c1d4b000000b00331140f3dc8so15785436wmd.1 for ; Tue, 30 Nov 2021 13:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1FHFqGRrLhQUZc7KZwrka720Uzz4l3XACZCj2Ti0sHk=; b=DhVNlnK1APM7w86rYUDn8tINABvvQ8T6Gjbqrr5vYtkEyxmycYTxKTYG7m3UDewuho q42pMWzRkfNfAdVVt2SlViYIOP8uII1KQmEf+r1s2VhoYfKcyLTh5oT8w/LTiumLb7yT r5e8ST//aDCbZHk+CUHOK/sax3oOGNhLAr/wi6vVywMezh/XdkXjciGjBuK+/92jLZET 018SLalGQqS9+e1jrNnYlNh7rPUUj9MQkEo0K7a/CtZ0HtsbNtk/7uTzIvavko+fkBT6 tFjE+TtRIj8rPS/VGjOZ4waHy3z3CrqbEBMbJ7csD+dKDRX8FfwgnKHTl+zLo/8zv53I bAPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1FHFqGRrLhQUZc7KZwrka720Uzz4l3XACZCj2Ti0sHk=; b=UlDHa5qAu3Czyqbi7n9YOGxWnFdyT6MUeSbzXdWJYERpfJiDf9SMWVupSXwt+i+TUX u/PhOfTZz3VIVgnD6uj60au+dRgOydkQ8KYJ9cEiKRdXq/OSp53TqtY9jikpGNRMUxhp LwVTPwhWBMzcj1qn1AzjIjhmM8wwjO3NCRqiBAGzxDj5MP3NRz6WNgETmqYeqOoax3nC 2oh3K0X0jw4hhV7AOARhZE8ETSzjQv5Ox8sK7UShdbJsG5DQMbfNL/1VYw+z7AmLDqmI TouztnIzZ0+KaQ/8H5hNE0Uq/u4rguJ4EGDCMIjybBHq55fTOb/qAsHj7XeyOQKoxdAm F3/g== X-Gm-Message-State: AOAM533uzpYI7ligQXaI4md8aXreyWyVTV261RRTZg5r18m0Guknu56n picqM/2beHmSiXtY9qNlJ3rhmGqoofY= X-Google-Smtp-Source: ABdhPJwYiy3weeWhEuhs6iFkAi4T98AyvTBvZn8lrggbl6cSnqn0pO6ZpSZW/lKctUisN2DoC1Ojxw== X-Received: by 2002:a05:600c:4f03:: with SMTP id l3mr1628588wmq.47.1638308298460; Tue, 30 Nov 2021 13:38:18 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:17 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 01/12] reflog delete: narrow scope of "cmd" passed to count_reflog_ent() Date: Tue, 30 Nov 2021 22:38:03 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the "cb_data" we pass to the count_reflog_ent() to be the &cb.cmd itself, instead of passing &cb and having the callback lookup cb->cmd. This makes it clear that the "cb" itself is the same memzero'd structure on each iteration of the for-loop that uses &cb, except for the "cmd" member. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 175c83e7cc2..4c15d71f3e9 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -662,20 +662,18 @@ static int count_reflog_ent(struct object_id *ooid, struct object_id *noid, const char *email, timestamp_t timestamp, int tz, const char *message, void *cb_data) { - struct expire_reflog_policy_cb *cb = cb_data; - if (!cb->cmd.expire_total || timestamp < cb->cmd.expire_total) - cb->cmd.recno++; + struct cmd_reflog_expire_cb *cb = cb_data; + if (!cb->expire_total || timestamp < cb->expire_total) + cb->recno++; return 0; } static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) { - struct expire_reflog_policy_cb cb; + struct cmd_reflog_expire_cb cmd = { 0 }; int i, status = 0; unsigned int flags = 0; - memset(&cb, 0, sizeof(cb)); - for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n")) @@ -703,6 +701,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) const char *spec = strstr(argv[i], "@{"); char *ep, *ref; int recno; + struct expire_reflog_policy_cb cb = { 0 }; if (!spec) { status |= error(_("not a reflog: %s"), argv[i]); @@ -716,14 +715,15 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) recno = strtoul(spec + 2, &ep, 10); if (*ep == '}') { - cb.cmd.recno = -recno; - for_each_reflog_ent(ref, count_reflog_ent, &cb); + cmd.recno = -recno; + for_each_reflog_ent(ref, count_reflog_ent, &cmd); } else { - cb.cmd.expire_total = approxidate(spec + 2); - for_each_reflog_ent(ref, count_reflog_ent, &cb); - cb.cmd.expire_total = 0; + cmd.expire_total = approxidate(spec + 2); + for_each_reflog_ent(ref, count_reflog_ent, &cmd); + cmd.expire_total = 0; } + cb.cmd = cmd; status |= reflog_expire(ref, flags, reflog_expiry_prepare, should_expire_reflog_ent, From patchwork Tue Nov 30 21:38:04 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: 12648149 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 70DBBC433F5 for ; Tue, 30 Nov 2021 21:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344237AbhK3Vlo (ORCPT ); Tue, 30 Nov 2021 16:41:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344226AbhK3Vll (ORCPT ); Tue, 30 Nov 2021 16:41:41 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA48AC061574 for ; Tue, 30 Nov 2021 13:38:20 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id p27-20020a05600c1d9b00b0033bf8532855so15775779wms.3 for ; Tue, 30 Nov 2021 13:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5u6oD7ridtLjC0jecCJMQdrsGENYprIXd9uvUi9VDhc=; b=MnqoEX2rCBJnjjEkpf/1cmvllvYmTHJnsemuvctOtVH+bQUpfCEzLZ6CXNAUQwbl9o AFlVzCmt73it7QVJk9Tx/mlGpov87PwsF/3YQzQTbxXKmTRdwi68KZGAQaE9Kr7ZDMZx /GyW+b9JTFWji2iD35YLKEVMzHEPR0S7++iAavtcd3EB0aFhkzTiHXeZxXJxewbEY0V3 rHatm4DF+LohIWDwEx6sXM6mRNzM9P8O0CmHQ+fVCrvfRirHoKeXWg1nW4xbYr/jOq4g 6A3KEgZzkdKfeQHYUI8LpDAToTOwExCziXHdsFdiwvNCGZB4WBUUhjlYVLIVW8NQowaz cUFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5u6oD7ridtLjC0jecCJMQdrsGENYprIXd9uvUi9VDhc=; b=no2bEqBbX8qwHBAePoqLvIPDraTlkhiqaWzwt4eXYKFPbZ3QYqzO2YTtsfGU/l2MRH Sx/sePJPfifS/LQMYg0UMtuK2VOz7DXntQlrsTnmh29lkyvclbdP/ZfXxjAPh8IlpIfL LVTeriwQS8t9dkPaO+AUpgWcvhnI+adK0te9l0532Dc8bX3ks5TccEC2AQKhgrmurPq/ 3tjS/Jc/vz4auEnUblOX+E3S6/MVgq/kYmTbM7nia+c+Mm7HPMfPANxsMjhfjmWibKsz 9228TfdXJa5B9icp+AQkl8CxGRtp5p/1EDfYFgtlHgLP1izWWveCee1bSMM2v3R9PuVw A0Qg== X-Gm-Message-State: AOAM530pT5J9ODoCpzeXCf2dpQD74H8GhoU3qmXfCs6kgIPQzm/QYtbN 96c2FKNUygI5j7n7B+vldE6uRpp5tTK0ww== X-Google-Smtp-Source: ABdhPJwZSZy2uahywWFRDMDg7wCJZAYygVRKrdUIsK9txJbZZe2FNzcDdHeqZF2Ba4OGZIJtCHV03w== X-Received: by 2002:a1c:3b04:: with SMTP id i4mr1637440wma.126.1638308299251; Tue, 30 Nov 2021 13:38:19 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:18 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 02/12] reflog expire: narrow scope of "cb" in cmd_reflog_expire() Date: Tue, 30 Nov 2021 22:38:04 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with the preceding change for "reflog delete", change the "cb_data" we pass to callbacks to be &cb.cmd itself, instead of passing &cb and having the callback lookup cb->cmd. This makes it clear that the "cb" itself is the same memzero'd structure on each iteration of the for-loops that use &cb, except for the "cmd" member. The "struct expire_reflog_policy_cb" we pass to reflog_expire() will have the members that aren't "cmd" modified by the callbacks, but before we invoke them everything except "cmd" is zero'd out. This included the "tip_commit", "mark_list" and "tips". It might have looked as though we were re-using those between iterations, but the first thing we did in reflog_expiry_prepare() was to either NULL them, or clobber them with another value. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 4c15d71f3e9..6989492bf5c 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -357,7 +357,6 @@ static void reflog_expiry_prepare(const char *refname, struct expire_reflog_policy_cb *cb = cb_data; if (!cb->cmd.expire_unreachable || is_head(refname)) { - cb->tip_commit = NULL; cb->unreachable_expire_kind = UE_HEAD; } else { cb->tip_commit = lookup_commit_reference_gently(the_repository, @@ -371,8 +370,6 @@ static void reflog_expiry_prepare(const char *refname, if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) cb->unreachable_expire_kind = UE_ALWAYS; - cb->mark_list = NULL; - cb->tips = NULL; if (cb->unreachable_expire_kind != UE_ALWAYS) { if (cb->unreachable_expire_kind == UE_HEAD) { struct commit_list *elem; @@ -541,7 +538,7 @@ static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, c static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) { - struct expire_reflog_policy_cb cb; + struct cmd_reflog_expire_cb cmd = { 0 }; timestamp_t now = time(NULL); int i, status, do_all, all_worktrees = 1; int explicit_expiry = 0; @@ -553,10 +550,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) save_commit_buffer = 0; do_all = status = 0; - memset(&cb, 0, sizeof(cb)); - cb.cmd.expire_total = default_reflog_expire; - cb.cmd.expire_unreachable = default_reflog_expire_unreachable; + cmd.expire_total = default_reflog_expire; + cmd.expire_unreachable = default_reflog_expire_unreachable; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -564,17 +560,17 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n")) flags |= EXPIRE_REFLOGS_DRY_RUN; else if (skip_prefix(arg, "--expire=", &arg)) { - if (parse_expiry_date(arg, &cb.cmd.expire_total)) + if (parse_expiry_date(arg, &cmd.expire_total)) die(_("'%s' is not a valid timestamp"), arg); explicit_expiry |= EXPIRE_TOTAL; } else if (skip_prefix(arg, "--expire-unreachable=", &arg)) { - if (parse_expiry_date(arg, &cb.cmd.expire_unreachable)) + if (parse_expiry_date(arg, &cmd.expire_unreachable)) die(_("'%s' is not a valid timestamp"), arg); explicit_expiry |= EXPIRE_UNREACH; } else if (!strcmp(arg, "--stale-fix")) - cb.cmd.stalefix = 1; + cmd.stalefix = 1; else if (!strcmp(arg, "--rewrite")) flags |= EXPIRE_REFLOGS_REWRITE; else if (!strcmp(arg, "--updateref")) @@ -600,14 +596,14 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) * even in older repository. We cannot trust what's reachable * from reflog if the repository was pruned with older git. */ - if (cb.cmd.stalefix) { - repo_init_revisions(the_repository, &cb.cmd.revs, prefix); - cb.cmd.revs.do_not_die_on_missing_tree = 1; - cb.cmd.revs.ignore_missing = 1; - cb.cmd.revs.ignore_missing_links = 1; + if (cmd.stalefix) { + repo_init_revisions(the_repository, &cmd.revs, prefix); + cmd.revs.do_not_die_on_missing_tree = 1; + cmd.revs.ignore_missing = 1; + cmd.revs.ignore_missing_links = 1; if (flags & EXPIRE_REFLOGS_VERBOSE) printf(_("Marking reachable objects...")); - mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL); + mark_reachable_objects(&cmd.revs, 0, 0, NULL); if (flags & EXPIRE_REFLOGS_VERBOSE) putchar('\n'); } @@ -629,6 +625,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) free_worktrees(worktrees); for (i = 0; i < collected.nr; i++) { struct collected_reflog *e = collected.e[i]; + struct expire_reflog_policy_cb cb = { .cmd = cmd }; set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog); status |= reflog_expire(e->reflog, flags, @@ -643,6 +640,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) for (; i < argc; i++) { char *ref; + struct expire_reflog_policy_cb cb = { .cmd = cmd }; + if (!dwim_log(argv[i], strlen(argv[i]), NULL, &ref)) { status |= error(_("%s points nowhere!"), argv[i]); continue; From patchwork Tue Nov 30 21:38:05 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: 12648151 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 AB94FC433EF for ; Tue, 30 Nov 2021 21:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344241AbhK3Vlp (ORCPT ); Tue, 30 Nov 2021 16:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240516AbhK3Vlm (ORCPT ); Tue, 30 Nov 2021 16:41:42 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE03C061746 for ; Tue, 30 Nov 2021 13:38:22 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id n33-20020a05600c502100b0032fb900951eso20618942wmr.4 for ; Tue, 30 Nov 2021 13:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=57qQgO3vw9s1fLch47WZcmwZCRS9CJvVouiO2JuvXDg=; b=oFCF8Q5/PbvuF9cE8clZ4yVabx1YeBjiaTID4ofgwQwLSXUE4RJhBUbamLOIhRTdzA cPxnfCc8Lcm1qZAXUe1/BMtnHnlHx9xfpnjMwWL/tFRasHHB7O9CEJnCViWGNz/8Plwi yGKn06R7j3p5ClVhHZBXHQglG+oSF6ijKcjhXYk3Zvbpv0uGZG1UqcpXnnD2DvENH5mt 62KIPiSFua8sPyPIMKw6aMYk7dunSJFK2WjKG3y6/bM6Cg3/Yta2CeNGD+sTeIG3hq8a l9Za/0hxWJdtZHxynL9PI7SORwm8ubl4Ms+YJ0pcy7PoZAf25fGKHLGh1RIZImk1NDfq u67g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=57qQgO3vw9s1fLch47WZcmwZCRS9CJvVouiO2JuvXDg=; b=BGGe4suXZx6ihxJZppNHKcHsPvMiWgRC63Dfl/Ck3czFYx7B9jBDG7olI/wfMOTFWn kuhCjwCsg223T4cpDjAz5CZHexyGC5OTSyudi8caNrTIf79jflJLm5Sn5Y8zN1FoExZf bsge9YWibO9gvyGWdbCAn1RlKaRaX8cqTUQrm0FDG59Za3Yk3cmlp+VVZhderwovYTra HxK6Jg4V0O+4vaHF0AJlpnn5Lnm0T2UV6pRhx9VrInnE39LKPv2iOj+RT7dVEwRJuBNU DlJFhQNb7Ho0CLSI3sHEIXYSbSYLoxnqrlC4QOnv2hNbkJs6VXB7lB5i5rv62dAfpr9+ 6zwQ== X-Gm-Message-State: AOAM533SzIoj1xLfbQpjxPMa9cUTOnCgGO1sbxlPzUNbbc7bZ/+9x2gG E/xVS9jR/psZNSr2MlFzRl2ncp2PNb2DiQ== X-Google-Smtp-Source: ABdhPJySOeGBA+dJNThXf5GRlPLruQ9ZiUXyeOY2bNhMHTGp4/s3QtAa8uDDeugoUEpYXLHlei/y8w== X-Received: by 2002:a1c:1bd8:: with SMTP id b207mr1644584wmb.114.1638308300509; Tue, 30 Nov 2021 13:38:20 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:19 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 03/12] reflog: change one->many worktree->refnames to use a string_list Date: Tue, 30 Nov 2021 22:38:05 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the FLEX_ARRAY pattern added in bda3a31cc79 (reflog-expire: Avoid creating new files in a directory inside readdir(3) loop, 2008-01-25) the string-list API instead. This does not change any behavior, allows us to delete much of this code as it's replaced by things we get from the string-list API for free, as a result we need just one struct to keep track of this data, instead of two. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 6989492bf5c..0fb46ade19f 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -48,16 +48,9 @@ struct expire_reflog_policy_cb { struct commit_list *tips; }; -struct collected_reflog { - struct object_id oid; - char reflog[FLEX_ARRAY]; -}; - -struct collect_reflog_cb { - struct collected_reflog **e; - int alloc; - int nr; - struct worktree *wt; +struct worktree_reflogs { + struct worktree *worktree; + struct string_list reflogs; }; /* Remember to update object flag allocation in object.h */ @@ -403,24 +396,20 @@ static void reflog_expiry_cleanup(void *cb_data) static int collect_reflog(const char *ref, const struct object_id *oid, int unused, void *cb_data) { - struct collected_reflog *e; - struct collect_reflog_cb *cb = cb_data; + struct worktree_reflogs *cb = cb_data; + struct worktree *worktree = cb->worktree; struct strbuf newref = STRBUF_INIT; /* * Avoid collecting the same shared ref multiple times because * they are available via all worktrees. */ - if (!cb->wt->is_current && ref_type(ref) == REF_TYPE_NORMAL) + if (!worktree->is_current && ref_type(ref) == REF_TYPE_NORMAL) return 0; - strbuf_worktree_ref(cb->wt, &newref, ref); - FLEX_ALLOC_STR(e, reflog, newref.buf); - strbuf_release(&newref); + strbuf_worktree_ref(worktree, &newref, ref); + string_list_append(&cb->reflogs, strbuf_detach(&newref, NULL)); - oidcpy(&e->oid, oid); - ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc); - cb->e[cb->nr++] = e; return 0; } @@ -609,33 +598,34 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) } if (do_all) { - struct collect_reflog_cb collected; + struct worktree_reflogs collected = { + .reflogs = STRING_LIST_INIT_NODUP, + }; + struct string_list_item *item; struct worktree **worktrees, **p; - int i; - memset(&collected, 0, sizeof(collected)); worktrees = get_worktrees(); for (p = worktrees; *p; p++) { if (!all_worktrees && !(*p)->is_current) continue; - collected.wt = *p; + collected.worktree = *p; refs_for_each_reflog(get_worktree_ref_store(*p), collect_reflog, &collected); } free_worktrees(worktrees); - for (i = 0; i < collected.nr; i++) { - struct collected_reflog *e = collected.e[i]; + + for_each_string_list_item(item, &collected.reflogs) { struct expire_reflog_policy_cb cb = { .cmd = cmd }; - set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog); - status |= reflog_expire(e->reflog, flags, + set_reflog_expiry_param(&cb.cmd, explicit_expiry, item->string); + status |= reflog_expire(item->string, flags, reflog_expiry_prepare, should_expire_reflog_ent, reflog_expiry_cleanup, &cb); - free(e); } - free(collected.e); + collected.reflogs.strdup_strings = 1; + string_list_clear(&collected.reflogs, 0); } for (; i < argc; i++) { From patchwork Tue Nov 30 21:38:06 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: 12648153 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 E746DC433F5 for ; Tue, 30 Nov 2021 21:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344257AbhK3Vlw (ORCPT ); Tue, 30 Nov 2021 16:41:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344230AbhK3Vln (ORCPT ); Tue, 30 Nov 2021 16:41:43 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 136AEC061574 for ; Tue, 30 Nov 2021 13:38:23 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so20618038wmj.5 for ; Tue, 30 Nov 2021 13:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TjcXc9IsIBoOw9sh7JvfMcBEVLUqTqYPac9RGxrc04w=; b=SeIOlkzP9xpLdX/3Ribe5eyQwbA3+RZ2gfCUHUQB9UQcjyW4gDA22sBqanfa3bCQE7 PxEK/MDaLQBq+1uhkoaWGkL/MfG5qFQuN1+dpAZqvyOl1S7QPaIZ77nbQRaU+j0S7k40 /D6XXWK1PXmjv5tRH2nCU8l07C5/aTonSvA3fqFJPFdhw31fVYUZof2heiqNhrt77nBj qJuGN0Dn76znlICYk6hlxEVq+aMKqrQuhG90/I4pYYnIFVjK7mnTjSBqksvGrUEpZV6g kY20Fb6Kp7NhXlxYRbxofZ0HvGlfQy/0UwtQ592E6k1QoLPipw25C611GTND8gsanAx7 IxTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TjcXc9IsIBoOw9sh7JvfMcBEVLUqTqYPac9RGxrc04w=; b=Ht+2gd7/xko9XaFNAzjQrqLOhjfieyomjT76kQ56od830puLsePZyLVSeL7K+iKc4x rHQtenGwTLnq2SaobefKWXyUT2rP4OXd7LFLWJsdhIqLx5BAY5cAlZZZ3lUM/VdhMUi0 ES4R6KaThlom9y1bOI+lWXDJQmoRmYDwu2KKy3pYsqmmDZqQihjE3ReG5sN97blStE9e YkRnlsokcB4YecY+hUPqHxmq2ivNN/J6s3VPFfJy9qDNtNcyuy5LeJlTjWvU08fkgObh icmrlAE9G+VrOPbe9fR0SxVcuHT9Pd4LIXZpZs7GluTPZK6t969sYNuhc3UcXFq5Gzmd DwMg== X-Gm-Message-State: AOAM5308XwAlt9VOGdbT4B2P31UOUd1UIKplcUZlDlYba31Vze2zo+9Z CK8K49oYw38rK5/iFxTkOYucldxnDmMVIg== X-Google-Smtp-Source: ABdhPJwtgYRSnZyRD29vWufUJwt1BxyV51o109k5hUufnYXWIQD3ZmfUB43QpOSGXwYlFdHMq1Zh9w== X-Received: by 2002:a1c:540c:: with SMTP id i12mr1615172wmb.33.1638308301435; Tue, 30 Nov 2021 13:38:21 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:20 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 04/12] reflog expire: don't do negative comparison on enum values Date: Tue, 30 Nov 2021 22:38:06 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code added in 03cb91b18cc (reflog --expire-unreachable: special case entries in "HEAD" reflog, 2010-04-09) to not do positive instead of negative comparisons on enum values, i.e. not to assume that "x != UE_ALWAYS" means "(x == UE_HEAD || x || UE_NORMAL)". That assumption is true now, but we'd introduce subtle bugs here if that were to change, now the compiler will notice and error out on such errors. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 57 ++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 0fb46ade19f..f8a24f1aa26 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -303,10 +303,15 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no return 1; if (timestamp < cb->cmd.expire_unreachable) { - if (cb->unreachable_expire_kind == UE_ALWAYS) - return 1; - if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid)) + switch (cb->unreachable_expire_kind) { + case UE_ALWAYS: return 1; + case UE_NORMAL: + case UE_HEAD: + if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid)) + return 1; + break; + } } if (cb->cmd.recno && --(cb->cmd.recno) == 0) @@ -348,6 +353,7 @@ static void reflog_expiry_prepare(const char *refname, void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; + struct commit_list *elem; if (!cb->cmd.expire_unreachable || is_head(refname)) { cb->unreachable_expire_kind = UE_HEAD; @@ -363,34 +369,37 @@ static void reflog_expiry_prepare(const char *refname, if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) cb->unreachable_expire_kind = UE_ALWAYS; - if (cb->unreachable_expire_kind != UE_ALWAYS) { - if (cb->unreachable_expire_kind == UE_HEAD) { - struct commit_list *elem; - - for_each_ref(push_tip_to_list, &cb->tips); - for (elem = cb->tips; elem; elem = elem->next) - commit_list_insert(elem->item, &cb->mark_list); - } else { - commit_list_insert(cb->tip_commit, &cb->mark_list); - } - cb->mark_limit = cb->cmd.expire_total; - mark_reachable(cb); + switch (cb->unreachable_expire_kind) { + case UE_ALWAYS: + return; + case UE_HEAD: + for_each_ref(push_tip_to_list, &cb->tips); + for (elem = cb->tips; elem; elem = elem->next) + commit_list_insert(elem->item, &cb->mark_list); + break; + case UE_NORMAL: + commit_list_insert(cb->tip_commit, &cb->mark_list); } + cb->mark_limit = cb->cmd.expire_total; + mark_reachable(cb); } static void reflog_expiry_cleanup(void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; + struct commit_list *elem; - if (cb->unreachable_expire_kind != UE_ALWAYS) { - if (cb->unreachable_expire_kind == UE_HEAD) { - struct commit_list *elem; - for (elem = cb->tips; elem; elem = elem->next) - clear_commit_marks(elem->item, REACHABLE); - free_commit_list(cb->tips); - } else { - clear_commit_marks(cb->tip_commit, REACHABLE); - } + switch (cb->unreachable_expire_kind) { + case UE_ALWAYS: + return; + case UE_HEAD: + for (elem = cb->tips; elem; elem = elem->next) + clear_commit_marks(elem->item, REACHABLE); + free_commit_list(cb->tips); + break; + case UE_NORMAL: + clear_commit_marks(cb->tip_commit, REACHABLE); + break; } } From patchwork Tue Nov 30 21:38:07 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: 12648155 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 41B36C433EF for ; Tue, 30 Nov 2021 21:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236124AbhK3Vly (ORCPT ); Tue, 30 Nov 2021 16:41:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344191AbhK3Vln (ORCPT ); Tue, 30 Nov 2021 16:41:43 -0500 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 F3EF6C061746 for ; Tue, 30 Nov 2021 13:38:23 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so20618067wmj.5 for ; Tue, 30 Nov 2021 13:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XtJJ+mNRQ+CWcj74FI+teeMSeJhiyOGNqS08VhRLjnw=; b=oJT9CUH6iW2X04l3vWgE28PSRXipO6TjAK743Iz/mObTuBaAoFvb+xMUt6B/g5sxZJ JabN49LJ6MkP7MJDY5se8zKD1L9GXnK/OvRr6I0Nmr0GU2KPMJqfTWTJ+q9sIZto3ob7 +zzG1AA6HQa1FGaYS+1oSJXavgyC2qmDapjQYyXkK5kHMLkvgkY6z2vUXrqt4QZfiQNl J+xLfiCCHKjPetBboAq6yQCe1XYFTsbjw1sYNcCbo2NtqvQPzT7FeMqxlgsdF9h5ULeN 6ofcxZBTiVw7JBiybwgVQhaLnW9VWcv0bQlnEnyhMQIc7k0N11940R3ClOWC7Ino5Vbh M5wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XtJJ+mNRQ+CWcj74FI+teeMSeJhiyOGNqS08VhRLjnw=; b=aiZJRrdD257Jyq+wHZFtml8cafe6A8jkf1tEqXTXmL5YDWJ8mYfQ+oiDqc1vFzkdVW NLz4pwxQGYNtFaECp0rX09Mbd/SKuLMLrNKzf4EEBKOILfj0dN4IJJkBKIcKyrayx2ws oy3uKV7IqlWdxcVPoSxaRiANWXyRZ+jwpBamqBcGajz5km8ngLGT9x61psufmcKY97ES 15w7g629wOUp6Eonf67ty078DUwZJbKawnCALIFSJJft11fU0/Ib9o5wvXH7fTsu+4Gf DgP6LChH1yqeqCJKTiY1RkdjHodO0/0wJ8z8YsyaZr/Pq3cPDBz+PQ97MGkwz449dzuI s45w== X-Gm-Message-State: AOAM53359fLQVD+upNy07AwZMRakQD/v/TjBPrH8PKJnqaHXhGgfZ9DL I4YzUjRM1Kot5YR5QYSPZ/YXBRmo144rVw== X-Google-Smtp-Source: ABdhPJy7O/QL283YBJLZBOpbbhmjAxbzMyy3r262jrsgDnGf2+eowlhtlRc/Tg15tczk22+5Vnpgdg== X-Received: by 2002:a05:600c:294c:: with SMTP id n12mr1578481wmd.71.1638308302363; Tue, 30 Nov 2021 13:38:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:21 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 05/12] reflog expire: refactor & use "tip_commit" only for UE_NORMAL Date: Tue, 30 Nov 2021 22:38:07 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add an intermediate variable for "tip_commit" in reflog_expiry_prepare(), and only add it to the struct if we're handling the UE_NORMAL case. The code behaves the same way as before, but this makes the control flow clearer, and the shorter name allows us to fold a 4-line i/else int a one-line terany instead. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index f8a24f1aa26..ec0c6051135 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -354,16 +354,14 @@ static void reflog_expiry_prepare(const char *refname, { struct expire_reflog_policy_cb *cb = cb_data; struct commit_list *elem; + struct commit *commit = NULL; if (!cb->cmd.expire_unreachable || is_head(refname)) { cb->unreachable_expire_kind = UE_HEAD; } else { - cb->tip_commit = lookup_commit_reference_gently(the_repository, - oid, 1); - if (!cb->tip_commit) - cb->unreachable_expire_kind = UE_ALWAYS; - else - cb->unreachable_expire_kind = UE_NORMAL; + commit = lookup_commit_reference_gently(the_repository, + oid, 1); + cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS; } if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) @@ -378,7 +376,9 @@ static void reflog_expiry_prepare(const char *refname, commit_list_insert(elem->item, &cb->mark_list); break; case UE_NORMAL: - commit_list_insert(cb->tip_commit, &cb->mark_list); + commit_list_insert(commit, &cb->mark_list); + /* For reflog_expiry_cleanup() below */ + cb->tip_commit = commit; } cb->mark_limit = cb->cmd.expire_total; mark_reachable(cb); From patchwork Tue Nov 30 21:38:08 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: 12648157 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 004DFC433EF for ; Tue, 30 Nov 2021 21:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344263AbhK3Vl6 (ORCPT ); Tue, 30 Nov 2021 16:41:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344240AbhK3Vlo (ORCPT ); Tue, 30 Nov 2021 16:41:44 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D90B0C061748 for ; Tue, 30 Nov 2021 13:38:24 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id q3so24607469wru.5 for ; Tue, 30 Nov 2021 13:38:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=csE09GodBkuoeSRAxjaJaIiEth9kRVv4P1MZIeR98io=; b=CAqdylGnFhE6W43gFD/j4IG1O/pkrk4H/3EBhllFJW56stYgj/gqv7oHvBhSY4y6Gc CSIxkr4Ddk0lK2p/iA0u/uq3+PoZBi8VH9BVnvGJusiMS1tAjrT4VqZboMBurZjtfBwF dptT60aOn08GAS3CDWi9jazFtTaTf1r/l6o+kWfIyugTnY0QLKd9t9YIWMRR9p5swPr4 oS7yKUZp55faBMaraPaxzQFM1gsSpYqMbOQNQvlfIxSNHtntmPUE9TTh5E8l3eyB/ZEf Ys4O6E4/Vc/BxMueygzfTgAw0OlBUt6sYIcCMNee2aCGUGMV/DD4J7BYORgRF7QFgXKa WtcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=csE09GodBkuoeSRAxjaJaIiEth9kRVv4P1MZIeR98io=; b=tE5ilBhxTaqF6B16FG83iir6LP6H6Sj0AVVXONRlYZncTbp86vyrIkZ+Reh0UrBoqN +9EyvQLfXUaqjut51tXwgO0G4FpqcaJVekQSlqrHbhwxUm6kOrKdXGHju3ln0wA5hMJT X/Tx00slc6flST9RoxFE8OTZcqWlXzoukXLrp3ZHCEaOfXdXLs8ATF31ABEXjaX7M6g2 vTtp8nyJ9QNEutC39uMUmlugoLmFRFLxY5OaQ8loRa7pDug+MtAUz+4cQz1NdZWW6YrU xm+mD+C3NWlufBM6Htxd/vadIdREnHJ2JjP+BT5zIpmvIpnfOgL4yNE6DQxGutUmzQt9 kj4w== X-Gm-Message-State: AOAM533fTrow/IAXcTBXWd3dlJWwMY7iH8LCH5/J4mjjZCdVhwOLV1KW Q30XGeJFdUFDjm/TbAAUC7p4W0FXc4BHZg== X-Google-Smtp-Source: ABdhPJyBOAwpib+wNm+9AQpc4/3c4Hbn/X9iyEnq8ZPb5I7w5aYeP1n49/OWsWyskpwIGAxHJbB7kA== X-Received: by 2002:a5d:6b09:: with SMTP id v9mr1678291wrw.591.1638308303216; Tue, 30 Nov 2021 13:38:23 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:22 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 06/12] reflog expire: don't use lookup_commit_reference_gently() Date: Tue, 30 Nov 2021 22:38:08 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the initial implementation of "git reflog" in 4264dc15e19 (git reflog expire, 2006-12-19) we had this lookup_commit_reference_gently(). I don't think we've ever found tags that we need to recursively dereference in reflogs, so this should at least be changed to a "lookup commit" as I'm doing here, although I can't think of a way where it mattered in practice. I also think we'd probably like to just die here if we have a NULL object, but as this code needs to handle potentially broken repositories let's just show an "error" but continue, the non-quiet lookup_commit() will do for us. None of our tests cover the case where "commit" is NULL after this lookup. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index ec0c6051135..29dcd91abca 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -359,8 +359,7 @@ static void reflog_expiry_prepare(const char *refname, if (!cb->cmd.expire_unreachable || is_head(refname)) { cb->unreachable_expire_kind = UE_HEAD; } else { - commit = lookup_commit_reference_gently(the_repository, - oid, 1); + commit = lookup_commit(the_repository, oid); cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS; } From patchwork Tue Nov 30 21:38:09 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: 12648159 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 24E76C433F5 for ; Tue, 30 Nov 2021 21:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344201AbhK3VmE (ORCPT ); Tue, 30 Nov 2021 16:42:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344243AbhK3Vlq (ORCPT ); Tue, 30 Nov 2021 16:41:46 -0500 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 9AA9EC061574 for ; Tue, 30 Nov 2021 13:38:25 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id a18so47527256wrn.6 for ; Tue, 30 Nov 2021 13:38:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pkf+nc9XahHl9Y5dnd/ZB1xwGfmKuGHguq7KqyfZxWM=; b=kYgg1sTas0YZesEo+U5CB2xWI237Hu7JhL1EoMVeuePdO9j3DFCWmyoXGCygyk1dx+ C2bzYKfdpPiqaTrghxU08KqxpABn/eUdfIHXwDUkCWvVeyOgwIhHuWcBabPjOw3/u5LL FDMwG/XBqBrXxOdWhpYbtFRT3KUfVUbskREFrjNGvFT7ppkXmptP6XUSSq3fhYMEwSqx 4UsDH1WyWB2VbqNjU01cX04rnpUsPEQNHnkH02LVO+REsRrtVpxA05knjbCJrblsjleY BWkd71UczA+PEVdsOzkwLcjFYpp0bBZ1jDDfalSFYB1zsUp3tirt2BdYpX/93BzeUXJI OZkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pkf+nc9XahHl9Y5dnd/ZB1xwGfmKuGHguq7KqyfZxWM=; b=1VybovDX2AIomPf7zpcyc5ymfzX2VuMG911/PN6IqmY0oZt6E1E+CuvzduvqBCnQtc rFQ5GSG4zg9WBybsJ3MaiuRk5M4dpXnfAAsSRNEHINORJRELnPzMqzcrZpZVAEP4Qy7H /9Xv5rfTqoqVSekmIB9nx60Q0GNAuDrIpcG/cqjk6BhvLjNUqmS6+3k5CXAdcyPSWS0c 69TC85ODuyyF1EeI9WrYOtNesxDnb5PLL4G/9EkTuLlxgvkv+z7+eA97SDOgmxkWURYK TIljwyzzxZXkbNdab84/L2LvheDuTj0BOpZIg9I2kaQ2FqWMGU/7O+Ab9YX6HgBLliWH Z4zQ== X-Gm-Message-State: AOAM530YpQ05bpIhgn5L6iCrdqYNA5g9K1os0izTPmslJWYUl5Q+D2x+ fnz4jEwvxJXuEqH13B7bwjK+C19UqrzDEA== X-Google-Smtp-Source: ABdhPJz+JbMMRM5mWWvjatj5HAQUimGlEbqfiHMefmOgHrrjkzXAP2ZgifgPltvCVMfxMFc+ZD31nQ== X-Received: by 2002:adf:f44e:: with SMTP id f14mr1787204wrp.37.1638308304007; Tue, 30 Nov 2021 13:38:24 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:23 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 07/12] reflog: reduce scope of "struct rev_info" Date: Tue, 30 Nov 2021 22:38:09 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the "cmd.stalefix" handling added in 1389d9ddaa6 (reflog expire --fix-stale, 2007-01-06) to use a locally scoped "struct rev_info". This code relies on mark_reachable_objects() twiddling flags in the walked objects. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 29dcd91abca..48e4f5887b0 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -28,7 +28,6 @@ static timestamp_t default_reflog_expire; static timestamp_t default_reflog_expire_unreachable; struct cmd_reflog_expire_cb { - struct rev_info revs; int stalefix; timestamp_t expire_total; timestamp_t expire_unreachable; @@ -594,13 +593,15 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) * from reflog if the repository was pruned with older git. */ if (cmd.stalefix) { - repo_init_revisions(the_repository, &cmd.revs, prefix); - cmd.revs.do_not_die_on_missing_tree = 1; - cmd.revs.ignore_missing = 1; - cmd.revs.ignore_missing_links = 1; + struct rev_info revs; + + repo_init_revisions(the_repository, &revs, prefix); + revs.do_not_die_on_missing_tree = 1; + revs.ignore_missing = 1; + revs.ignore_missing_links = 1; if (flags & EXPIRE_REFLOGS_VERBOSE) printf(_("Marking reachable objects...")); - mark_reachable_objects(&cmd.revs, 0, 0, NULL); + mark_reachable_objects(&revs, 0, 0, NULL); if (flags & EXPIRE_REFLOGS_VERBOSE) putchar('\n'); } From patchwork Tue Nov 30 21:38:10 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: 12648167 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 95FFBC433EF for ; Tue, 30 Nov 2021 21:38:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344266AbhK3VmQ (ORCPT ); Tue, 30 Nov 2021 16:42:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344276AbhK3VmD (ORCPT ); Tue, 30 Nov 2021 16:42:03 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FCD4C061758 for ; Tue, 30 Nov 2021 13:38:27 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id d24so47537312wra.0 for ; Tue, 30 Nov 2021 13:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+DP63MMqOmC7x5EJLWOeRwhcZIybmuP1+Q7/INmQuWI=; b=qquNEjT7JqwuQyoqGmdjednJUuSPAMg601VAS982UJpBQDEgyIm2w3kgupKzZdHiGT ZRvMECIvO/bkUuz6Uf8ZLazPhDauMGZdeLyoblavsJsgjjktENQ3MaDc7meY7pd5Szn6 tWGZCFD+w7fm7GkKO/YJF7UWrehEgdh889D9MlpOqK/vxEbSvpnHgqnOEPPyRTHIcZQE 7kx2JSp7kZDLQpl6NVh7NlLaRXcP/XynbNniZGDBjf7xh4Kqdt5E7QDMLH07p3tcj85h OJHv0LZVYyYt/TDVN3rWBIerGHYZGyY5mgNZZ5bT6moUrvgckH3hFHn22kFnm0eyBIaa fuRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+DP63MMqOmC7x5EJLWOeRwhcZIybmuP1+Q7/INmQuWI=; b=bIGcLiPDCVDQKLJQv/RsjyKvsowp4PU5F/wS080elGh2ujJ5jXeZQBrRrRpOS+pzzN n41mMzAwkz9D6+e9ijm7cM0t99ndnSPHv9K40TyKu1Xne5TtvvThnE5OrY2pX3NW1/Nn 16iRC/6zqJatccKgdxC89GL0ISlVhZHhe5u00FOh/mUPmJb+onx7Zjc1qwVfSBTz86g4 3ufwY2HrP/oAnMcFdfkSyYDUSDaFUx3jdUqwAxOSG9Ok/Gq/sWzNlNvePRBZthVaQHos SkhYg4Z8Ko+cyNMxXRa7OAonYR76dmufV/SNvhO+E6t+/s5oTK872O7f2sRebyDh5Zvo pphA== X-Gm-Message-State: AOAM5319FFib/ekIgI8P4C1DPoZRrXlrVD48U85GdPLrwwU9QfnbimPp FyNgBwX2tGUwXrCySm0aS7FX0TPo1OEv0Q== X-Google-Smtp-Source: ABdhPJwMSKK7CQ2qG3okDGDMBG9VWWvVAoJiIksIocaT+JCB5VF1mUOKG4DyzUhG02K6InyJkNDOgQ== X-Received: by 2002:adf:fa04:: with SMTP id m4mr1714837wrr.389.1638308305725; Tue, 30 Nov 2021 13:38:25 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:24 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 08/12] refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN Date: Tue, 30 Nov 2021 22:38:10 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's not possible for "cb->newlog" to be NULL if !EXPIRE_REFLOGS_DRY_RUN, since files_reflog_expire() would have error()'d and taken the "goto failure" branch if it couldn't open the file. By not using the "newlog" field private to "file-backend.c"'s "struct expire_reflog_cb", we can move this verbosity logging to "builtin/reflog.c" in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 4b14f30d48f..451c4e2a052 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3099,12 +3099,12 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid, if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz, message, policy_cb)) { - if (!cb->newlog) + if (cb->flags & EXPIRE_REFLOGS_DRY_RUN) printf("would prune %s", message); else if (cb->flags & EXPIRE_REFLOGS_VERBOSE) printf("prune %s", message); } else { - if (cb->newlog) { + if (!(cb->flags & EXPIRE_REFLOGS_DRY_RUN)) { fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s", oid_to_hex(ooid), oid_to_hex(noid), email, timestamp, tz, message); From patchwork Tue Nov 30 21:38:11 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: 12648161 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 3A7BCC433EF for ; Tue, 30 Nov 2021 21:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240528AbhK3VmL (ORCPT ); Tue, 30 Nov 2021 16:42:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344272AbhK3VmD (ORCPT ); Tue, 30 Nov 2021 16:42:03 -0500 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 EC8F4C06175A for ; Tue, 30 Nov 2021 13:38:28 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id v11so47466518wrw.10 for ; Tue, 30 Nov 2021 13:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oswnOYVaHQo//llJo5Xops/IuG8r8YVTby08wRo7sh0=; b=P62G+CPiFX6Quyzulo3j8Oepkp36WqN8M897OndF+42YAMIJeMccxQlf91VTyBYIRC q5u1v01vq4PK2kl+YVz9qnucz69oQRNECwxFLRLXLlmwbBR3rAtbWVchY/AjQm/N6yWO QnDGGhmtk3n9r2Fl6TO8qJuKDrm1ZR7KdrZ9vHTFDrvOGUNm8qbfEyLKnTaPomr25NnB rXjyQ2nAii2ZajCmQy2gg4221SIxE5EH/sTfNhomlLGk2lPyi5yH3izdHsvBC7CxBzPV U1zT9bjzgvswdKzvBK8BhdpMrRpgm7xx4KNWw90dHNJNMHEScTP4wwaE/IZfhQ5PMZ2A oi0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oswnOYVaHQo//llJo5Xops/IuG8r8YVTby08wRo7sh0=; b=UOcXn4QL/pButf1BCgDg22xi+666i/Awx3ursBp+sKlWB25HNvcsYSDGbzfR7R3mya odaOtNG7brMTFsaHIomIx7jUL56IAFMwBjrUuUVHKGdNnTsPH4ugFw9p19P8Bsfd/dWQ GF5HmqFBHsXJ0nDyBHmlfqg3L7QD1oYBUwtV7HFmfJF6ilRIb37f2B/UhZ+qbCamjvTc dMxWmrYDNjpNoM8XcuJbI6ImUvuuRoOGbu/IGg5E2sCzkB564HS7Tq/YAucCrzO2tNQs iBGsOjfpZdg4ssY8aicZwf+sH2zeCQy8EAXRvscLFzwqKjjDeQg8ZDlM2bN2eWS1CjUx +cSA== X-Gm-Message-State: AOAM532AvTKoRTRqBBtJYXxeZ3PIoxm2AwVUE1NhMJOO2R2RSQeFHvZe 8JiiDRG03mymghAZSPLe9W7sYueEkL8NQQ== X-Google-Smtp-Source: ABdhPJwOST41oXaH1OpZKad05FWoSmMETx3GJC5NP6rFL02eH9vdX/EqIOvWwXphj9itiad2vK28Kg== X-Received: by 2002:adf:e387:: with SMTP id e7mr1715794wrm.412.1638308306671; Tue, 30 Nov 2021 13:38:26 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:26 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 09/12] reflog + refs-backend: move "verbose" out of the backend Date: Tue, 30 Nov 2021 22:38:11 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the handling of the "verbose" flag entirely out of "refs/files-backend.c" and into "builtin/reflog.c". This allows the backend to stop knowing about the EXPIRE_REFLOGS_VERBOSE flag. The expire_reflog_ent() function shouldn't need to deal with the implementation detail of whether or not we're emitting verbose output, by doing this the --verbose output becomes backend-agnostic, so reftable will get the same output. I think the output is rather bad currently, and should e.g. be implemented with some better future mode of progress.[ch], but that's a topic for another improvement. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 42 +++++++++++++++++++++++++++++++----------- refs.h | 3 +-- refs/files-backend.c | 44 ++++++++++++++++++++------------------------ 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 48e4f5887b0..a77c0d96dce 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -45,6 +45,8 @@ struct expire_reflog_policy_cb { struct cmd_reflog_expire_cb cmd; struct commit *tip_commit; struct commit_list *tips; + unsigned int dry_run:1, + verbose:1; }; struct worktree_reflogs { @@ -294,29 +296,38 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no struct commit *old_commit, *new_commit; if (timestamp < cb->cmd.expire_total) - return 1; + goto expire; old_commit = new_commit = NULL; if (cb->cmd.stalefix && (!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid))) - return 1; + goto expire; if (timestamp < cb->cmd.expire_unreachable) { switch (cb->unreachable_expire_kind) { case UE_ALWAYS: - return 1; + goto expire; case UE_NORMAL: case UE_HEAD: if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid)) - return 1; + goto expire; break; } } if (cb->cmd.recno && --(cb->cmd.recno) == 0) - return 1; + goto expire; + + if (cb->verbose) + printf("keep %s", message); return 0; +expire: + if (cb->dry_run) + printf("would prune %s", message); + else if (cb->verbose) + printf("prune %s", message); + return 1; } static int push_tip_to_list(const char *refname, const struct object_id *oid, @@ -539,6 +550,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) int i, status, do_all, all_worktrees = 1; int explicit_expiry = 0; unsigned int flags = 0; + int verbose = 0; default_reflog_expire_unreachable = now - 30 * 24 * 3600; default_reflog_expire = now - 90 * 24 * 3600; @@ -576,7 +588,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) else if (!strcmp(arg, "--single-worktree")) all_worktrees = 0; else if (!strcmp(arg, "--verbose")) - flags |= EXPIRE_REFLOGS_VERBOSE; + verbose = 1; else if (!strcmp(arg, "--")) { i++; break; @@ -599,10 +611,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) revs.do_not_die_on_missing_tree = 1; revs.ignore_missing = 1; revs.ignore_missing_links = 1; - if (flags & EXPIRE_REFLOGS_VERBOSE) + if (verbose) printf(_("Marking reachable objects...")); mark_reachable_objects(&revs, 0, 0, NULL); - if (flags & EXPIRE_REFLOGS_VERBOSE) + if (verbose) putchar('\n'); } @@ -624,7 +636,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) free_worktrees(worktrees); for_each_string_list_item(item, &collected.reflogs) { - struct expire_reflog_policy_cb cb = { .cmd = cmd }; + struct expire_reflog_policy_cb cb = { + .cmd = cmd, + .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN), + .verbose = verbose, + }; set_reflog_expiry_param(&cb.cmd, explicit_expiry, item->string); status |= reflog_expire(item->string, flags, @@ -671,6 +687,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) struct cmd_reflog_expire_cb cmd = { 0 }; int i, status = 0; unsigned int flags = 0; + int verbose = 0; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -681,7 +698,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) else if (!strcmp(arg, "--updateref")) flags |= EXPIRE_REFLOGS_UPDATE_REF; else if (!strcmp(arg, "--verbose")) - flags |= EXPIRE_REFLOGS_VERBOSE; + verbose = 1; else if (!strcmp(arg, "--")) { i++; break; @@ -699,7 +716,10 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) const char *spec = strstr(argv[i], "@{"); char *ep, *ref; int recno; - struct expire_reflog_policy_cb cb = { 0 }; + struct expire_reflog_policy_cb cb = { + .verbose = verbose, + .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN), + }; if (!spec) { status |= error(_("not a reflog: %s"), argv[i]); diff --git a/refs.h b/refs.h index 45c34e99e3a..0c3374b405c 100644 --- a/refs.h +++ b/refs.h @@ -786,8 +786,7 @@ enum ref_type ref_type(const char *refname); enum expire_reflog_flags { EXPIRE_REFLOGS_DRY_RUN = 1 << 0, EXPIRE_REFLOGS_UPDATE_REF = 1 << 1, - EXPIRE_REFLOGS_VERBOSE = 1 << 2, - EXPIRE_REFLOGS_REWRITE = 1 << 3 + EXPIRE_REFLOGS_REWRITE = 1 << 2, }; /* diff --git a/refs/files-backend.c b/refs/files-backend.c index 451c4e2a052..c154c3c4a23 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3080,11 +3080,12 @@ static int files_initial_transaction_commit(struct ref_store *ref_store, } struct expire_reflog_cb { - unsigned int flags; reflog_expiry_should_prune_fn *should_prune_fn; void *policy_cb; FILE *newlog; struct object_id last_kept_oid; + unsigned int rewrite:1, + dry_run:1; }; static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid, @@ -3092,33 +3093,27 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid, const char *message, void *cb_data) { struct expire_reflog_cb *cb = cb_data; - struct expire_reflog_policy_cb *policy_cb = cb->policy_cb; + reflog_expiry_should_prune_fn *fn = cb->should_prune_fn; - if (cb->flags & EXPIRE_REFLOGS_REWRITE) + if (cb->rewrite) ooid = &cb->last_kept_oid; - if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz, - message, policy_cb)) { - if (cb->flags & EXPIRE_REFLOGS_DRY_RUN) - printf("would prune %s", message); - else if (cb->flags & EXPIRE_REFLOGS_VERBOSE) - printf("prune %s", message); - } else { - if (!(cb->flags & EXPIRE_REFLOGS_DRY_RUN)) { - fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s", - oid_to_hex(ooid), oid_to_hex(noid), - email, timestamp, tz, message); - oidcpy(&cb->last_kept_oid, noid); - } - if (cb->flags & EXPIRE_REFLOGS_VERBOSE) - printf("keep %s", message); - } + if (fn(ooid, noid, email, timestamp, tz, message, cb->policy_cb)) + return 0; + + if (cb->dry_run) + return 0; /* --dry-run */ + + fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s", oid_to_hex(ooid), + oid_to_hex(noid), email, timestamp, tz, message); + oidcpy(&cb->last_kept_oid, noid); + return 0; } static int files_reflog_expire(struct ref_store *ref_store, const char *refname, - unsigned int flags, + unsigned int expire_flags, reflog_expiry_prepare_fn prepare_fn, reflog_expiry_should_prune_fn should_prune_fn, reflog_expiry_cleanup_fn cleanup_fn, @@ -3136,7 +3131,8 @@ static int files_reflog_expire(struct ref_store *ref_store, const struct object_id *oid; memset(&cb, 0, sizeof(cb)); - cb.flags = flags; + cb.rewrite = !!(expire_flags & EXPIRE_REFLOGS_REWRITE); + cb.dry_run = !!(expire_flags & EXPIRE_REFLOGS_DRY_RUN); cb.policy_cb = policy_cb_data; cb.should_prune_fn = should_prune_fn; @@ -3172,7 +3168,7 @@ static int files_reflog_expire(struct ref_store *ref_store, files_reflog_path(refs, &log_file_sb, refname); log_file = strbuf_detach(&log_file_sb, NULL); - if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) { + if (!cb.dry_run) { /* * Even though holding $GIT_DIR/logs/$reflog.lock has * no locking implications, we use the lock_file @@ -3199,7 +3195,7 @@ static int files_reflog_expire(struct ref_store *ref_store, refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb); (*cleanup_fn)(cb.policy_cb); - if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) { + if (!cb.dry_run) { /* * It doesn't make sense to adjust a reference pointed * to by a symbolic ref based on expiring entries in @@ -3209,7 +3205,7 @@ static int files_reflog_expire(struct ref_store *ref_store, */ int update = 0; - if ((flags & EXPIRE_REFLOGS_UPDATE_REF) && + if ((expire_flags & EXPIRE_REFLOGS_UPDATE_REF) && !is_null_oid(&cb.last_kept_oid)) { int ignore_errno; int type; From patchwork Tue Nov 30 21:38:12 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: 12648165 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 72624C433EF for ; Tue, 30 Nov 2021 21:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344261AbhK3VmO (ORCPT ); Tue, 30 Nov 2021 16:42:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344249AbhK3VmH (ORCPT ); Tue, 30 Nov 2021 16:42:07 -0500 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 1D401C06175E for ; Tue, 30 Nov 2021 13:38:29 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id o13so47334722wrs.12 for ; Tue, 30 Nov 2021 13:38:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1toHONEK16LBgCnu8vhMrQcFwTgpK8KEj4GJ37b9cJc=; b=XCMU27adlsqteS1ZBsOUZHxl15QcNZH5TsrvSAcdb/cbMDIex//k3bei5M86o4guZ7 9R+jCrJp6+q5gnkVEU+WjEgHUPFlkf7sqhLAYTUSKFKFHr5ABTcFWZtJtBnm9Mp/GpWb 8LzDGUJomh0ofZxvtpUB/BcNHW1CR+ZU0PX+Kbe9bvxn/4IVwJgGM0w8wdGhYSQUKYz0 UaHQbhqWgF3cIvTR6PR6EP1WXOAR96u90HxDUSU7xHBMCS+KJg5RIdxIxsDxb2+UYx3b FbqOMA/xqMXA2D4aRWzha8HVq4WKsuZagO2DGw+EFj+FgSul37qFoUFsqC0l37xZvW1h I/Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1toHONEK16LBgCnu8vhMrQcFwTgpK8KEj4GJ37b9cJc=; b=SqY6UCfyW2gT0iHRkGWvJcoCHZpwGigR/7qbUtBQFqIx5MgpydKbcea9CWWMqFmO4b eWl3hxYWpX1l4pVbcHRv9YZmCi84gtoSdE5RBgeoX/QBsyaH3gNGJpBiw52E2vNQlZsc z/9vbWMNAetoIB38DtvxO5hSx6mxlW6PW9Jg2H04ynBecT++SynPFNALwTFlIHA981uT ZrVU1MNiOo62bL1QhY5V0NdKjQ1yJNZvB3oapXtRT9ZQ1DMgBy68HZ1YoIyWXxK+FYTB yEzY0MpByBdM7nthRFeYNtlnr+lZDNG8wNVtM4yMFbp9l23/zJimHOJ8pA0ovaaMQ8N0 lRMQ== X-Gm-Message-State: AOAM533eQnaF58F3OzVjks1+LLnb/3bhUbb++8qgU0DMjV+o2+hv0fZx NJf+xrF/7fkXIm0iD7c3jGSwYMGFUjSP3Q== X-Google-Smtp-Source: ABdhPJyT4KxJDEqdw1ke0fRTGyjeZy5Uthi95eK6YFgxZfz8UOYhkS4wALnZyauw5Nr1k1cXHJtNxw== X-Received: by 2002:a5d:47c7:: with SMTP id o7mr1711787wrc.204.1638308307809; Tue, 30 Nov 2021 13:38:27 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:26 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 10/12] reflog expire: add progress output on --stale-fix Date: Tue, 30 Nov 2021 22:38:12 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add progress output when the "git reflog expire --stale-fix" option is used. This output was previously only emitted under --verbose, but we shouldn't treat it the same way as the actually verbose "--verbose" output emitted in should_expire_reflog_ent(). Note that this code isn't going to be affected by the sort of bug we had to fix in 6b89a34c89f (gc: fix regression in 7b0f229222 impacting --quiet, 2018-09-19). I.e. "git gc" won't call it with the "--stale-fix" flag, that option is purely used as a one-off. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-reflog.txt | 8 ++++++++ builtin/reflog.c | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt index ff487ff77d3..1735bbea9fb 100644 --- a/Documentation/git-reflog.txt +++ b/Documentation/git-reflog.txt @@ -69,6 +69,14 @@ Options for `show` Options for `expire` ~~~~~~~~~~~~~~~~~~~~ +--progress:: +--no-progress:: + Progress status is reported on the standard error stream by + default when it is attached to a terminal. The `--progress + flag enables progress reporting even if not attached to a + terminal. Supplying `--no-progress` will suppress all progress + output. + --all:: Process the reflogs of all references. diff --git a/builtin/reflog.c b/builtin/reflog.c index a77c0d96dce..cf0ef68d82d 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -11,6 +11,7 @@ #include "revision.h" #include "reachable.h" #include "worktree.h" +#include "progress.h" /* NEEDSWORK: switch to using parse_options */ static const char reflog_expire_usage[] = @@ -551,6 +552,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) int explicit_expiry = 0; unsigned int flags = 0; int verbose = 0; + int show_progress = -1; default_reflog_expire_unreachable = now - 30 * 24 * 3600; default_reflog_expire = now - 90 * 24 * 3600; @@ -579,6 +581,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) } else if (!strcmp(arg, "--stale-fix")) cmd.stalefix = 1; + else if (!strcmp(arg, "--progress")) + show_progress = 1; + else if (!strcmp(arg, "--no-progress")) + show_progress = 0; else if (!strcmp(arg, "--rewrite")) flags |= EXPIRE_REFLOGS_REWRITE; else if (!strcmp(arg, "--updateref")) @@ -598,6 +604,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) else break; } + if (show_progress == -1) + show_progress = isatty(2); /* * We can trust the commits and objects reachable from refs @@ -606,16 +614,16 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) */ if (cmd.stalefix) { struct rev_info revs; + struct progress *progress = NULL; + if (show_progress) + progress = start_delayed_progress(_("Marking reachable objects"), 0); repo_init_revisions(the_repository, &revs, prefix); revs.do_not_die_on_missing_tree = 1; revs.ignore_missing = 1; revs.ignore_missing_links = 1; - if (verbose) - printf(_("Marking reachable objects...")); - mark_reachable_objects(&revs, 0, 0, NULL); - if (verbose) - putchar('\n'); + mark_reachable_objects(&revs, 0, 0, progress); + stop_progress(&progress); } if (do_all) { From patchwork Tue Nov 30 21:38:13 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: 12648163 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 C8E23C433FE for ; Tue, 30 Nov 2021 21:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344237AbhK3VmM (ORCPT ); Tue, 30 Nov 2021 16:42:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344246AbhK3VmE (ORCPT ); Tue, 30 Nov 2021 16:42:04 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B39C0613DD for ; Tue, 30 Nov 2021 13:38:30 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id u1so47419611wru.13 for ; Tue, 30 Nov 2021 13:38:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gx5l/5AyhDJIXoMKtTIMSn+SDEEKAqgY84OQzXkG71U=; b=mzv5H34W93VqfJZ7Dmuulu4hkm3g7gDwn38v1lig6s6EF075Sh0LMWfDnZ1QDk7lP/ dwqPhqNGQPBRiE/YxY4r19Sq4omExGzXFfvyxmNGpy7Ksi3FQhgdrDES89z7AVvlhXju onKvSsRmIOIM22yBGHwsjPqaSvBPInLCs92xY6QnNl6ydzxsT7SLRPJ19k3iOjIjdbLR jukYGb35rcWaPUERBocUbZiQv6kRCfhzCcGLCn0pnSUnK+YDd8CJAZA1+pAp8S/eNKpz wec301ozPa2nC+zAHFu8Eqn8tzDj83AmSGeyZxHZ+tJFfqfMTTBkkHL/Lgf5APzQZyb2 sUKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gx5l/5AyhDJIXoMKtTIMSn+SDEEKAqgY84OQzXkG71U=; b=zyUxRq8b5n6H2IrT3qsypt7ybUw85Ob1/KSGoRDy7cTvlLan/XlKzQJcn7IoTIiP3Y t4/MebAnE9r6XSFXZtFQtAWrwGwuoCH3w1nG4FW++n8/gLiBWIylFkmGIe1DZWsgzLtB 5bOELMIBxQo6gmfJmd+UmrsrawWU46Y6c7sip3HHkw74Yhn2P0JO5vvyny0sccjnxX6y yt94OHAYIYquGpeQV8/n8MCtJqZYXlJ5S7O89Jtk7DTPPZ5Aw6xEj3kAxshFYBZ4VPWK XcUptLaWd89CKU66qXwZdlXTzKTRo3EHSadj8oKybq5ln19Tf3STiZ6YxsdglsEMu7X9 8wKg== X-Gm-Message-State: AOAM532kM5vZwj7JTMvuZKS9E7f80m4t60MHPJGOFmb03cAyQK0ZU4O1 Hceu9dTLsDRxNyQ31Q+jAwDaoj6MvRAUPw== X-Google-Smtp-Source: ABdhPJwbxYokp/04gE0ocilUDCMPM7dxC1O9UWaSC+DaN4Jh447j1G9IiNoP2jOw6SQFWvdzDE548A== X-Received: by 2002:a5d:668f:: with SMTP id l15mr1783319wru.182.1638308308648; Tue, 30 Nov 2021 13:38:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:28 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 11/12] gc + reflog: emit progress output from "reflog expire --all" Date: Tue, 30 Nov 2021 22:38:13 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Emit progress output on "git reflog expire --all", which is what "git gc" runs. On my git.git checkout I'll now get: $ time GIT_PROGRESS_DELAY=0 ~/g/git/git reflog expire --all --dry-run Enumerating reflogs: 23782, done. Expiring reflogs: 100% (23782/23782), done. real 0m3.264s user 0m2.308s sys 0m0.941s The "Enumerating reflogs" is too fast to appear for me except with GIT_PROGRESS_DELAY=0. We'll also emit this at the top of "git gc" output: $ ~/g/git/git --exec-path=$PWD gc Expiring reflogs: 100% (23782/23782), done. Enumerating objects: [...] This goes a long way (but not quite, a subsequent commit will) to addressing the seeming halting of "git gc" on startup. That usually happens because of the "HEAD" case in "reflog expire --all" and unreachable(). Note that this code isn't going to be affected by the sort of bug we had to fix in 6b89a34c89f (gc: fix regression in 7b0f229222 impacting --quiet, 2018-09-19). This is because "git gc" even with "--auto" won't detach until after it runs "git reflog -expire", so whatever output we emit will never end up in the gc.log. We should still obey its --quiet to mean our --no-progress, but we don't need a special-case for "daemonized" as write_commit_graph_reachable() does. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/gc.c | 4 +++- builtin/reflog.c | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index bcef6a4c8da..872209e083e 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -593,8 +593,10 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (aggressive_window > 0) strvec_pushf(&repack, "--window=%d", aggressive_window); } - if (quiet) + if (quiet) { + strvec_push(&reflog, "--no-progress"); strvec_push(&repack, "-q"); + } if (auto_gc) { /* diff --git a/builtin/reflog.c b/builtin/reflog.c index cf0ef68d82d..1a2a210ecf1 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -53,6 +53,7 @@ struct expire_reflog_policy_cb { struct worktree_reflogs { struct worktree *worktree; struct string_list reflogs; + struct progress *progress; }; /* Remember to update object flag allocation in object.h */ @@ -324,7 +325,7 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no return 0; expire: - if (cb->dry_run) + if (cb->verbose && cb->dry_run) printf("would prune %s", message); else if (cb->verbose) printf("prune %s", message); @@ -426,6 +427,7 @@ static int collect_reflog(const char *ref, const struct object_id *oid, int unus if (!worktree->is_current && ref_type(ref) == REF_TYPE_NORMAL) return 0; + display_progress(cb->progress, cb->reflogs.nr + 1); strbuf_worktree_ref(worktree, &newref, ref); string_list_append(&cb->reflogs, strbuf_detach(&newref, NULL)); @@ -627,11 +629,17 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) } if (do_all) { + struct progress *progress = NULL; struct worktree_reflogs collected = { .reflogs = STRING_LIST_INIT_NODUP, }; struct string_list_item *item; struct worktree **worktrees, **p; + uint64_t progress_cnt; + + if (show_progress) + collected.progress = start_delayed_progress(_("Enumerating reflogs"), + 0); worktrees = get_worktrees(); for (p = worktrees; *p; p++) { @@ -642,6 +650,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) collect_reflog, &collected); } free_worktrees(worktrees); + stop_progress(&collected.progress); + + if (show_progress) { + progress_cnt = 0; + progress = start_delayed_progress(_("Expiring reflogs"), + collected.reflogs.nr); + } for_each_string_list_item(item, &collected.reflogs) { struct expire_reflog_policy_cb cb = { @@ -650,6 +665,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) .verbose = verbose, }; + display_progress(progress, ++progress_cnt); set_reflog_expiry_param(&cb.cmd, explicit_expiry, item->string); status |= reflog_expire(item->string, flags, reflog_expiry_prepare, @@ -657,6 +673,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) reflog_expiry_cleanup, &cb); } + stop_progress(&progress); collected.reflogs.strdup_strings = 1; string_list_clear(&collected.reflogs, 0); } From patchwork Tue Nov 30 21:38:14 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: 12648169 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 EC1AFC433FE for ; Tue, 30 Nov 2021 21:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344281AbhK3VmU (ORCPT ); Tue, 30 Nov 2021 16:42:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344287AbhK3VmK (ORCPT ); Tue, 30 Nov 2021 16:42:10 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1974FC0613FD for ; Tue, 30 Nov 2021 13:38:31 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id o13so47334874wrs.12 for ; Tue, 30 Nov 2021 13:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qyj3qx543nkSIsnA9fp5SPnHtkvC5sZOGjLpkPrDfog=; b=ULgjCstqjBKFa6mEbYqduWV7Jw7NUwAehFQpeHmM2/OvnSLwr3nMne8hrZibkfVr1Y 2SE4vKgLO8bGhcTbim+1UysiCnbN0Tg5vePxQR/Q2N0CtPAfjHrHRbqHDB3VEgOfEgjP TAjMTrJ589FvYmQirsMgdyDRufhQSa5dpt63nHgLxvbx9fBLxFrTqf25fAkEXQc4T/wd JA1nCV6I2ShTIf6dPFd6fTiI8osEYgKf+FLwUIwTymmeqxhbayU6XNEXYrqS8VcDD7/Q MffLo0W4FskosU5ccxNfWLh9lmHVrw52wXPJWhzFqfAeXg2Px7486obgxUc2XJ+NOO79 GVJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qyj3qx543nkSIsnA9fp5SPnHtkvC5sZOGjLpkPrDfog=; b=5hf1POCNlCZ4oOIybbwdSVGo/CN9Rtrzkf4ahM5lvWTvuK52nJSTxzwvYOEeTd43ah XwuXzvwfgQH13ennKc4LngHtf9kVRVc4Q9gz21aIYMquzjoY/mfXNw+WI+dWQ2W4v4It A59nA7fHZxLXk9+M6Xz9v/gFYwhLALPO3rn56sN6wMFvbsm0GyAtUl2CUAziGroe2QYz uFKfedx2N2kCnmulWbLgjEL1DNgDKysz42RUd9sn6QWg/ER1S3tzP6borHij7UZVLGvR kI9vnm2nDUHL2Bz/WEjyJiMITfFDZAI/qfvQCwMQVwwgnvdemYfMa0qukeTAy9AwKeOO WGzQ== X-Gm-Message-State: AOAM531rBajfRhQ1W6pCEvonsaJFlNa8kXGN+jeT0nChLZvOCMddItVm sp553X2eM6wAWF8mWPFZeJlBLdBTfC3xbw== X-Google-Smtp-Source: ABdhPJxpCw+3cslnlqo7aAwzDGQx9vob05NBuH4+IgBig0PkDuYeYcMFawwe678iOe5TxyFvbnduoQ== X-Received: by 2002:a05:6000:18ac:: with SMTP id b12mr1766843wri.355.1638308309709; Tue, 30 Nov 2021 13:38:29 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v8sm17006914wrd.84.2021.11.30.13.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 13:38:28 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Han-Wen Nienhuys , Bagas Sanjaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 12/12] gc + reflog: don't stall before initial "git gc" progress output Date: Tue, 30 Nov 2021 22:38:14 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.877.g7d5b0a3b8a6 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the "git reflog expire --all" progress output to show progress on mark_reachable() in addition to the "Expiring reflogs" output added in the preceding commit. This is a major UI improvement to the "git gc" progress output, which in large repositories would seem to hang before the "initial" "Enumerating objects" phase. E.g. on a linux.git checkout I've got it previously took me around 10 seconds before I saw any output. With the change to add the "Expiring reflogs" output in the preceding commit that ~10 second delay was perhaps ~8-9, now it's pretty much guaranteed to show output within the first couple of seconds (our default progress delay). Why? Because as we iterate through our reflogs to expire in reflog_exire() we'd always check the reflog for "HEAD" first, and as we hadn't previously marked anything REACHABLE in mark_reachable() would almost certainly end up needing to walk a substantial amount of history to mark commits. In linux.git north of 1 million commits. Now we'll instead show: $ git gc Iterating (un)reachable HEAD: 1137354, done. Expiring reflogs: 100% (45/45), done. ^Enmerating objects: 662499^C [...] The implementation is a bit of a hack. Ideally we'd support nested progress bars, and the ability to "attach" a sub-progress bar to a running one. I.e. to optimistically show either: Expiring reflogs: X (Y/Z) Or: Expiring reflogs: X (Y/Z) iterating unreachable HEAD: 123456 In this case the problem is that if we have done our initial big "REACHABLE" iteration we're usually going to process the reflog quite quickly, but if we haven't we'd stall. So as a hack pass down a "show_progress" to reflog_expiry_prepare(), which will only be shown if we haven't processed the UE_HEAD case. We'll then start a progress bar, which when passed through to mark_reachable() will almost certainly result in a substantial initial iteration. Then when we've done that initial walk we'll stop that progress bar in our main loop, and start the "Expiring reflogs" progress bar. We'll usually start it at 2/X, since our "HEAD" was the 1/X usurped by the "Iterating (un)reachable HEAD" progress bar. The "usually" would assume that we wouldn't hit the "cb->no_reachable_progress = 1" case being added here. I.e. if our configuration is such that we're not going to do the UE_HEAD walk we'll just fall back on only using "Expiring reflogs". We'll still start the count at the 2nd reflog, but it shouldn't matter, on e.g. my linux.git checkout it doesn't, the progress bar goes by too fast to notice. It would have been nicer to be able to compute the "cb->unreachable_expire_kind" before we call reflog_expire(), but to do that we'd need the "oid", which we'll only know once we lock it. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 53 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 1a2a210ecf1..ef4f039a20c 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -47,7 +47,11 @@ struct expire_reflog_policy_cb { struct commit *tip_commit; struct commit_list *tips; unsigned int dry_run:1, - verbose:1; + verbose:1, + show_progress:1, + no_reachable_progress:1; + struct progress *reachable_progress; + uint64_t reachable_progress_cnt; }; struct worktree_reflogs { @@ -235,6 +239,8 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb) while (pending) { struct commit_list *parent; struct commit *commit = pop_commit(&pending); + + display_progress(cb->reachable_progress, ++cb->reachable_progress_cnt); if (commit->object.flags & REACHABLE) continue; if (parse_commit(commit)) @@ -375,16 +381,27 @@ static void reflog_expiry_prepare(const char *refname, cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS; } - if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) + if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) { + if (cb->show_progress && + cb->unreachable_expire_kind == UE_HEAD) + cb->no_reachable_progress = 1; cb->unreachable_expire_kind = UE_ALWAYS; + } switch (cb->unreachable_expire_kind) { case UE_ALWAYS: return; case UE_HEAD: + if (cb->show_progress) { + const char *s = _("Iterating (un)reachable HEAD"); + cb->reachable_progress = start_delayed_progress(s, 0); + } for_each_ref(push_tip_to_list, &cb->tips); - for (elem = cb->tips; elem; elem = elem->next) + for (elem = cb->tips; elem; elem = elem->next) { + display_progress(cb->reachable_progress, + ++cb->reachable_progress_cnt); commit_list_insert(elem->item, &cb->mark_list); + } break; case UE_NORMAL: commit_list_insert(commit, &cb->mark_list); @@ -633,9 +650,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) struct worktree_reflogs collected = { .reflogs = STRING_LIST_INIT_NODUP, }; - struct string_list_item *item; struct worktree **worktrees, **p; - uint64_t progress_cnt; + int show_head_progress = show_progress; + size_t j; if (show_progress) collected.progress = start_delayed_progress(_("Enumerating reflogs"), @@ -652,27 +669,31 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) free_worktrees(worktrees); stop_progress(&collected.progress); - if (show_progress) { - progress_cnt = 0; - progress = start_delayed_progress(_("Expiring reflogs"), - collected.reflogs.nr); - } - - for_each_string_list_item(item, &collected.reflogs) { + for (j = 0; j < collected.reflogs.nr; j++) { + const char *string = collected.reflogs.items[j].string; struct expire_reflog_policy_cb cb = { .cmd = cmd, .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN), .verbose = verbose, + .show_progress = show_head_progress, }; - - display_progress(progress, ++progress_cnt); - set_reflog_expiry_param(&cb.cmd, explicit_expiry, item->string); - status |= reflog_expire(item->string, flags, + display_progress(progress, j + 1); + set_reflog_expiry_param(&cb.cmd, explicit_expiry, string); + status |= reflog_expire(string, flags, reflog_expiry_prepare, should_expire_reflog_ent, reflog_expiry_cleanup, &cb); + + if (show_head_progress && + (cb.reachable_progress || cb.no_reachable_progress)) { + stop_progress(&cb.reachable_progress); + show_head_progress = 0; + progress = start_delayed_progress(_("Expiring reflogs"), + collected.reflogs.nr); + } } + display_progress(progress, collected.reflogs.nr); /* only HEAD? */ stop_progress(&progress); collected.reflogs.strdup_strings = 1; string_list_clear(&collected.reflogs, 0);