From patchwork Mon Mar 25 10:03:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13601869 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3C71188A74 for ; Mon, 25 Mar 2024 10:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711361018; cv=none; b=HAXZtqNIJzauxSnY3ugYg3IRE5EICuy2odAbcDBn3YiiJFaWAlDkEu0B/1rsFVJhKDb6oDmWRTqSNDQbzzoMeNL82lY3n+cUOd5KF7TR/r4CtiMNMgheZC0KJii+wXDyg+/vhTAv1LyvWWmh4jXiIWmoAB9+3bmh2mAkmuWon0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711361018; c=relaxed/simple; bh=87gPnVVFnXN1kD1yeiWaJAJ03Yo1/vMjiRXN8phy1w4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N33WQMBDuGSL3f/uDsBV6gdCXIk7INvfc8YDeTrwsA0TkUbGsJz45lnT8mLJ7NsI/+yCpGa+OboAUQJGnsppPfeuEiX5PuCrj/fm6IAHzz7a4eZR608cQlO7tBKreQULRCvviFtQfkDMhWZUnoFKOBBAWgpD+gjvUpN4oIfSPVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=mDn7XkP9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kNndxH3Q; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="mDn7XkP9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kNndxH3Q" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id CA60711400DF; Mon, 25 Mar 2024 06:03:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 25 Mar 2024 06:03:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1711361015; x=1711447415; bh=RfZSjyCfYm h61+5ftsHOhbT46ZZJtn+8Pp4RVBK441o=; b=mDn7XkP9N+yCKBXNRf7UYqyoU1 xfN73yzKvd2FVKDEZQ6hhYpact+hTOga22dab+d+uyo//lG71yXfi9yqrZ1pMN3L vgA/lgDFQ7OOwGj5GAX9+AhSe8LDlWZsSwrmTpnrcYcFiNH8hoR3DvInOczcXIwg F9WHwflmbKImqydmVSqu9NTv8dZkH2iHMo6q+4zbUkg6FFRJNceYcDR6dd2YC00X +WMLVDeDWpM7toaTAe89zwVQIzXn6qKLohX6cxrqalpm6HImwV7IFM5qacYlt8Pb y0j2aLxcyl1QtkyQNMQxpgIEzMbjjKeETNERCUzO1jjRPW7SZJHc1z1oisig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1711361015; x=1711447415; bh=RfZSjyCfYmh61+5ftsHOhbT46ZZJ tn+8Pp4RVBK441o=; b=kNndxH3QYCrd5ZA5ooxMWw4SjVgSNMfleMd6BqseHz3C c7O4IfRJb17MUF93VAKUQM4b0zhM0KnpfNAafNNK7W4OyEDYN9VpsU6QImEQE8Uy Fnd2tQML/wdKROQJ5NY3dL3+HdWn4sm42+kxNfsGuWo6heYJIyiczJF0KgwBa+gR +FFGr0+lStGZbddvbcgOuYym2138E/ZlSEflz1POkRI/a1WKwSPr++e4Zdd7sesP qNkuRqK5vpRZO3fMTPgEKEEHy2qsmjjfUpDh33ytJ+jfLuSpR+2FWpfSyLtk2het pSwqBs6Uk+xkNTgzwtEA1c0AUy0HTmyFtC+c1r1U8A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtledguddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Mar 2024 06:03:34 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a9d4e16a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 25 Mar 2024 10:03:24 +0000 (UTC) Date: Mon, 25 Mar 2024 11:03:32 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Derrick Stolee , Karthik Nayak Subject: [PATCH v2 14/15] builtin/gc: forward git-gc(1)'s `--auto` flag when packing refs Message-ID: <3eaff8289be5032cfd425272f63a6a02ae432eb1.1711360631.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Forward the `--auto` flag to git-pack-refs(1) when it has been invoked with this flag itself. This does not change anything for the "files" backend, which will continue to eagerly pack refs. But it does ensure that the "reftable" backend only compacts refs as required. This change does not impact git-maintenance(1) because this command will in fact never run the pack-refs task when run with `--auto`. This issue will be addressed in a subsequent commit. Signed-off-by: Patrick Steinhardt --- builtin/gc.c | 21 ++++++++++++--------- t/t0610-reftable-basics.sh | 19 ++++++++++++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index e0029c88f9..bf1f2a621a 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -212,6 +212,9 @@ static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts * cmd.git_cmd = 1; strvec_pushl(&cmd.args, "pack-refs", "--all", "--prune", NULL); + if (opts->auto_flag) + strvec_push(&cmd.args, "--auto"); + return run_command(&cmd); } @@ -572,7 +575,7 @@ static int report_last_gc_error(void) return ret; } -static void gc_before_repack(void) +static void gc_before_repack(struct maintenance_run_opts *opts) { /* * We may be called twice, as both the pre- and @@ -583,7 +586,7 @@ static void gc_before_repack(void) if (done++) return; - if (pack_refs && maintenance_task_pack_refs(NULL)) + if (pack_refs && maintenance_task_pack_refs(opts)) die(FAILED_RUN, "pack-refs"); if (prune_reflogs) { @@ -599,7 +602,6 @@ static void gc_before_repack(void) int cmd_gc(int argc, const char **argv, const char *prefix) { int aggressive = 0; - int auto_gc = 0; int quiet = 0; int force = 0; const char *name; @@ -608,6 +610,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) int keep_largest_pack = -1; timestamp_t dummy; struct child_process rerere_cmd = CHILD_PROCESS_INIT; + struct maintenance_run_opts opts = {0}; struct option builtin_gc_options[] = { OPT__QUIET(&quiet, N_("suppress progress reporting")), @@ -618,7 +621,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) OPT_MAGNITUDE(0, "max-cruft-size", &max_cruft_size, N_("with --cruft, limit the size of new cruft packs")), OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")), - OPT_BOOL_F(0, "auto", &auto_gc, N_("enable auto-gc mode"), + OPT_BOOL_F(0, "auto", &opts.auto_flag, N_("enable auto-gc mode"), PARSE_OPT_NOCOMPLETE), OPT_BOOL_F(0, "force", &force, N_("force running gc even if there may be another gc running"), @@ -663,7 +666,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (quiet) strvec_push(&repack, "-q"); - if (auto_gc) { + if (opts.auto_flag) { /* * Auto-gc should be least intrusive as possible. */ @@ -688,7 +691,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (lock_repo_for_gc(force, &pid)) return 0; - gc_before_repack(); /* dies on failure */ + gc_before_repack(&opts); /* dies on failure */ delete_tempfile(&pidfile); /* @@ -713,7 +716,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) name = lock_repo_for_gc(force, &pid); if (name) { - if (auto_gc) + if (opts.auto_flag) return 0; /* be quiet on --auto */ die(_("gc is already running on machine '%s' pid %"PRIuMAX" (use --force if not)"), name, (uintmax_t)pid); @@ -728,7 +731,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) atexit(process_log_file_at_exit); } - gc_before_repack(); + gc_before_repack(&opts); if (!repository_format_precious_objects) { struct child_process repack_cmd = CHILD_PROCESS_INIT; @@ -783,7 +786,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, NULL); - if (auto_gc && too_many_loose_objects()) + if (opts.auto_flag && too_many_loose_objects()) warning(_("There are too many unreachable loose objects; " "run 'git prune' to remove them.")); diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh index 6de7529575..b37d8bf3b1 100755 --- a/t/t0610-reftable-basics.sh +++ b/t/t0610-reftable-basics.sh @@ -387,7 +387,9 @@ test_expect_success 'pack-refs: compaction raises locking errors' ' test_cmp expect err ' -test_expect_success 'pack-refs: auto compaction' ' +for command in pack-refs gc +do +test_expect_success "$command: auto compaction" ' test_when_finished "rm -rf repo" && git init repo && ( @@ -395,14 +397,24 @@ test_expect_success 'pack-refs: auto compaction' ' test_commit A && + # We need a bit of setup to ensure that git-gc(1) actually + # triggers, and that it does not write anything to the refdb. + git config gc.auto 1 && + git config gc.autoDetach 0 && + git config gc.reflogExpire never && + git config gc.reflogExpireUnreachable never && + test_oid blob17_1 | git hash-object -w --stdin && + # The tables should have been auto-compacted, and thus auto # compaction should not have to do anything. ls -1 .git/reftable >tables-expect && test_line_count = 4 tables-expect && - git pack-refs --auto && + git $command --auto && ls -1 .git/reftable >tables-actual && test_cmp tables-expect tables-actual && + test_oid blob17_2 | git hash-object -w --stdin && + # Lock all tables write some refs. Auto-compaction will be # unable to compact tables and thus fails gracefully, leaving # the stack in a sub-optimal state. @@ -416,10 +428,11 @@ test_expect_success 'pack-refs: auto compaction' ' rm .git/reftable/*.lock && test_line_count = 5 .git/reftable/tables.list && - git pack-refs --auto && + git $command --auto && test_line_count = 1 .git/reftable/tables.list ) ' +done test_expect_success 'pack-refs: prunes stale tables' ' test_when_finished "rm -rf repo" &&