From patchwork Thu Mar 6 05:58:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Woodruff X-Patchwork-Id: 14003851 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BA5719AD48 for ; Thu, 6 Mar 2025 05:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741240691; cv=none; b=qwWK5iTzUvO0sYETkS4SRxC0Lz46c0D1gHTMbehH2tOM0UbNlNgeHudM4inHK1D2PwPpRHAynEHYjyTvcfzHPnBHtk2PMB3U1CktxokmqxpUuD1s3HtCOY5DoZCnKifBUpDxOUUBesD7KDwUUnclMIKaBuI4Y2YbSCBCkQdTdJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741240691; c=relaxed/simple; bh=2bFavhysJwhG4U2Pq/U/T/fb3WvzTZvbuDgkkhwX0F0=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=CQFfZshQSRco+1HE2yicwNBtrg+OvbLke3bbZPX1f4ANR2s5Hg4Z7XO+H1b3+GqZplb6PoJhlRejE2s7Tc50lcaQ7cGvcm0xp/e1hmfHfYRbDxP1U2LnwgQp6sgrxUCQVdO5dmkofelUBwZA7BzdfPDvKUulllfzCGuTyN/UaaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hzERE4j8; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hzERE4j8" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43bcb1a9890so10086915e9.0 for ; Wed, 05 Mar 2025 21:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741240687; x=1741845487; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=iM7BMEbR09X40sCGGRebJ5LTwomeJ4m2o/3+cFq/QB0=; b=hzERE4j8mVr1gyB/zCNaPtnr5ALfzOyXyCEPiAP5fGaTpEU30DigUu/kLqJqj7Li5n krISVrpxcNvPA9viL8+tUfoltBuRdmCOtQCR29U0WlT6nAEK17B9OOvi+2MLqcxI/4YL Cd5FktHsraDdzpexkkiQX7m7HXofwtxHLrsMlO+dUpjCMGj7wBs20JLYgZNL51AQTxYs qHQwsISsBeN12ifDkIVOVsvPT5k3NoINJjyKr4HUOR6NUK9kjnwfKa7Lr/9CR9jSjYQk YIqcLSZhBdIEy3TXyS0B2XyZrrn/FyTI8dXHOus+Xu4W6ST4R661dgn9sGn1aNd2OPtT ysgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741240687; x=1741845487; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iM7BMEbR09X40sCGGRebJ5LTwomeJ4m2o/3+cFq/QB0=; b=eBotRRtxU/TMQa/q6GkXc2xBpawowD5W1PFE4NeykY93NiCCtjmXJ0AQJaTsZomn3h XCz0ikLHONP4r1fgZ2lgh0sxetGZSN5/EcnNcnWnfAgHzg3c0Fk2trgFkjr96yTh4j9Y tl5lLaYccQVo44LEomDoSVX5zjFj3qoo9iP2VMZ5SapqYvjF2vP7zTew4sDRczKDnwDR LS91XhKxhJRQu+6XYQ8caB//fYkd/yyR953UGBZjRd5nDtRMyysJ+xfyKnOwYWKLRiYv OdzZfpT/8GfQK4wGTeRzzjSKQoKR4uETgL5cqwerQEdB3h6WOku7pthYZtYidDPcIlLD sh4w== X-Gm-Message-State: AOJu0YxlqazeZWVVQxfSWOHRjlTsH4W7q28utifMrQQ8LLn2Cfc/b73l QR/s/1QbrrPstort3jNBFmbFapOzIbg7JWD9G3hiyvY01HhrZwYCfBedSA== X-Gm-Gg: ASbGncs4i2V4FFOe5WFV9WPPQIzKRqPFR70BbWt2B+WDsZJKptQC2Cczv0omU8BQUGa w+gQaUPPm/Hp9ItZtPrz7ojgWrVKOc+GQ5/ds3JpZivcSNLI7cxuNbAsyzlqeOyxA9CRWh6Flm6 vasqo8iSRh33tbQw0GED2ulItTVOZNO0k8iJfGhEIDcrAjHoJe1ebAM0Fe6vA0gA3gOqpd+Acvg JDFsbEhZfNXYZE8cW+7odF/tojjjHZpKYGvTkev9FnSsFs0A7DdQQABK7k8yMgRi8IGwZh0eDrx oWtgVnnfuJY3n/kxElsAJnN8Kr++pbQjePSKnbBULaOIpw== X-Google-Smtp-Source: AGHT+IEvQXOtR3x9Vf+RX9kHMq8maIW+mLqaLWAHJyqTfn6Yxo0PvJndJ0ao8EGXIWxt2pbg1tEr5g== X-Received: by 2002:a05:6000:2185:b0:391:21e2:ec3b with SMTP id ffacd0b85a97d-391296d3f23mr1060278f8f.3.1741240687128; Wed, 05 Mar 2025 21:58:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912c0e34fasm840043f8f.75.2025.03.05.21.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 21:58:06 -0800 (PST) Message-Id: <46c90ba12a5afd0e697a224c7951771b649b336b.1741240685.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 06 Mar 2025 05:58:04 +0000 Subject: [PATCH 1/2] describe: implement --no-optional-locks Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Benjamin Woodruff , Benjamin Woodruff From: Benjamin Woodruff From: Benjamin Woodruff When used with `--dirty`, describe may update the index in the background for similar performance reasons to `git-status`. This commit implements the `--no-optional-locks` option for `git describe`, which allows scripts to bypass this behavior. Signed-off-by: Benjamin Woodruff --- Documentation/git-describe.adoc | 12 ++++++++++++ Documentation/git.adoc | 3 ++- builtin/describe.c | 12 +++++++----- t/t6120-describe.sh | 8 ++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Documentation/git-describe.adoc b/Documentation/git-describe.adoc index 08ff715709c..97b4c656078 100644 --- a/Documentation/git-describe.adoc +++ b/Documentation/git-describe.adoc @@ -198,6 +198,18 @@ selected and output. Here fewest commits different is defined as the number of commits which would be shown by `git log tag..input` will be the smallest number of commits possible. +BACKGROUND REFRESH +------------------ + +By default, `git describe --dirty` will automatically refresh the index, +similar to the background refresh functionality of +linkgit:git-status[1]. Writing out the updated index is an optimization +that isn't strictly necessary. When `describe` is run in the background, +the lock held during the write may conflict with other simultaneous +processes, causing them to fail. Scripts running `describe` in the +background should consider using `git --no-optional-locks status` (see +linkgit:git[1] for details). + BUGS ---- diff --git a/Documentation/git.adoc b/Documentation/git.adoc index 743b7b00e4d..f084b2f0f1e 100644 --- a/Documentation/git.adoc +++ b/Documentation/git.adoc @@ -189,7 +189,8 @@ If you just want to run git as if it was started in `` then use --no-optional-locks:: Do not perform optional operations that require locks. This is - equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`. + equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`. This + functionality is implemented for `git status` and `git describe`. --no-advice:: Disable all advice hints from being printed. diff --git a/builtin/describe.c b/builtin/describe.c index e2e73f3d757..d4fea55352d 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -704,7 +704,6 @@ int cmd_describe(int argc, } else if (dirty) { struct lock_file index_lock = LOCK_INIT; struct rev_info revs; - int fd; setup_work_tree(); prepare_repo_settings(the_repository); @@ -712,10 +711,13 @@ int cmd_describe(int argc, repo_read_index(the_repository); refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); - fd = repo_hold_locked_index(the_repository, - &index_lock, 0); - if (0 <= fd) - repo_update_index_if_able(the_repository, &index_lock); + if (use_optional_locks()) { + int fd = repo_hold_locked_index(the_repository, + &index_lock, 0); + if (0 <= fd) + repo_update_index_if_able(the_repository, + &index_lock); + } repo_init_revisions(the_repository, &revs, prefix); diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 76843a61691..ae7b6901ed6 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -749,4 +749,12 @@ test_expect_success 'do not be fooled by invalid describe format ' ' test_must_fail git cat-file -t "refs/tags/super-invalid/./../...../ ~^:/?*[////\\\\\\&}/busted.lock-42-g"$(cat out) ' +test_expect_success '--no-optional-locks prevents index update' ' + test_set_magic_mtime .git/index && + git --no-optional-locks describe --dirty && + test_is_magic_mtime .git/index && + git describe --dirty && + ! test_is_magic_mtime .git/index +' + test_done From patchwork Thu Mar 6 05:58:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Woodruff X-Patchwork-Id: 14003852 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA28A19DF48 for ; Thu, 6 Mar 2025 05:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741240692; cv=none; b=b9CzIB1ZVP0exQK4SEXBHwZkIDbeQiCFKZfaCVw4flxgPeCdoGMENIDtIfdw+PC2hCFjFNNPcFTNq9n81oebui0ZPlksSjGcErj/ewUtud31gS2JxYxtUzqotC+z8mJY+cozEUuooRUNdyIh6F/mPyiYHHFf6INLYQBSmA97Uu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741240692; c=relaxed/simple; bh=YM7WsbVIPu7ngWJ2B+wyDQdNVNLClawysFOaWjJ9qmk=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ORN82Xqlx5C4wA3wVnryblkpWUB8EC2/JVlhman3FqjwQUipemyywX5CgloVd6bfMGgiewFh5a28TW1X6NEtKMmVHojL3weBWi6GA4OHXnewU2cbga6OGk98igBqXePH83VQaeaBeFT5xUEETL66hJYUacnbb0jOnIzFqA8ornM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bNEw+aDd; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bNEw+aDd" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4394a0c65fcso1845545e9.1 for ; Wed, 05 Mar 2025 21:58:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741240688; x=1741845488; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=xGLFbHdt7nz837PD8zXk9AOIm9zdWa+zEKPQ0/YuFIo=; b=bNEw+aDdbgv4CGBttSrISinq0Wk67AvxrTvJ/mcZuIjlkdekTvWV2AILoUXAbGpDi5 frJmMJvTx33emxYt6PSrWoiExAHF7OAyH3VfAAFfNO4E0W1GQy30YXCnwQNCpvzOvUlj 4VtSxI4frA6/dF9gsBaWmd6JZ6rfJaBcvzF+wjRFMqoKSjpR1GH2geiwyszScbwd90jR hSMLjUeoEWmCE6qMgwrGfqyMtEpnTucPM7xN8uTQynTuxmYxmGb2h4e/MVIV58/TkW2J T2m1ptMuBp960gZR6Ilrj9qZ2cXq/i15jR4y+Gi1hBKvpY+CVc17dZ1eAw4tprUAvGCt Kczg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741240688; x=1741845488; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xGLFbHdt7nz837PD8zXk9AOIm9zdWa+zEKPQ0/YuFIo=; b=PmDPZj1csL6cUUSPjZzfGxdMCXH0ez0L1ml3I5gcDMBopFEJyYG/HhZjhnAs3hEaBh j9m9V8uEXwGAzfyM7Rpj/0TqjoM5osOkauOkioILCoClXM8j3Ud9AJqO5QiGZxZ1agOn 8JzdTwYxaw+Ahmr6DfM0b7p4x5t+BBVyzx2AyDneaCZXOhWJ5cqYh4a/kvrUDw/FugD8 4ghfYlVlmIcOLPtqKFNJW0KvX/fMkVPkjMoecTbU8xVM5EXnrPkK9HQYhwc0OF6EwOcZ VMKeFs3NjYVfJcmW14TD7U9pyIQXwdAd9b+yV+KcCG6DB4stTwDxUBzRzHViVUDUovl+ KynA== X-Gm-Message-State: AOJu0YymaqaQdbEcvrS8JlpjmjccFTQdA6hzbDZoG9ESGq3DdckxS5rc sJkz70TYgnyuzsMUwbKAyua7gAcX/Lht4QwdP99++FIb0hzh5Ehjz54uzA== X-Gm-Gg: ASbGncuZ23eFQCafa1NGDJaKcz6cjFto5sowj9Sv9250H5TLO7biv9DlLC29uoAYm7W NOyFUE7EYHuhF8P5FoNHQ+ll8jjZ3T3r7QLZN4gz8k6KqXIw68R15ui6adcrpQnf0yihAZ/oax4 x18owbLL52/D3F4/otz1zURgLMhxwDdoszX51+qo5DIFb56pTWEciTr5Gso6NlCTSa4OzasELyf md2q1B8fiBSJ/BWDxL8QKTO2vFrFDbmEznZiwm0Bgl78Muzu/sC4S6q42/A6IuB6Ign83iSbZKI GOB10wSGSlF8wnnv2283ADAS/edAs6NwOIkNVDdXRCMLPw== X-Google-Smtp-Source: AGHT+IEepMZN6GxUk+FwOfStnR8zGXNlVamd7wJRm0bdnxvNIw7/8x9K+I4a6tZ+T/1DxMPUFwBfRg== X-Received: by 2002:a05:6000:440a:b0:390:e2a3:cb7b with SMTP id ffacd0b85a97d-3911f7adcdfmr4091153f8f.34.1741240688102; Wed, 05 Mar 2025 21:58:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912bfdfb16sm850067f8f.29.2025.03.05.21.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 21:58:07 -0800 (PST) Message-Id: <3ba3113738e913d51156703b7cf86daf43c7d1b4.1741240685.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 06 Mar 2025 05:58:05 +0000 Subject: [PATCH 2/2] diff: implement --no-optional-locks Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Benjamin Woodruff , Benjamin Woodruff From: Benjamin Woodruff From: Benjamin Woodruff When used with `autoRefreshIndex`, `git diff` may update the index in the background for similar performance reasons to `git-status`. This commit implements the `--no-optional-locks` option for `git diff`, which allows scripts to bypass this behavior. Signed-off-by: Benjamin Woodruff --- Documentation/config/diff.adoc | 4 ++- Documentation/git.adoc | 3 +- builtin/diff.c | 4 +++ t/meson.build | 1 + t/t4070-diff-auto-refresh-index.sh | 46 ++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 t/t4070-diff-auto-refresh-index.sh diff --git a/Documentation/config/diff.adoc b/Documentation/config/diff.adoc index 1135a62a0ad..2dadcf7a1da 100644 --- a/Documentation/config/diff.adoc +++ b/Documentation/config/diff.adoc @@ -6,7 +6,9 @@ contents in the work tree match the contents in the index. This option defaults to `true`. Note that this affects only `git diff` Porcelain, and not lower level - `diff` commands such as `git diff-files`. + `diff` commands such as `git diff-files`. If + `--no-optional-locks` is set (see linkgit:git[1] for + details), the index file is not updated. `diff.dirstat`:: ifdef::git-diff[] diff --git a/Documentation/git.adoc b/Documentation/git.adoc index f084b2f0f1e..754880b8672 100644 --- a/Documentation/git.adoc +++ b/Documentation/git.adoc @@ -190,7 +190,8 @@ If you just want to run git as if it was started in `` then use --no-optional-locks:: Do not perform optional operations that require locks. This is equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`. This - functionality is implemented for `git status` and `git describe`. + functionality is implemented for `git status`, `git describe`, + and `git diff`. --no-advice:: Disable all advice hints from being printed. diff --git a/builtin/diff.c b/builtin/diff.c index a4fffee42c6..5469e58bf5d 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -9,6 +9,7 @@ #include "builtin.h" #include "config.h" +#include "environment.h" #include "ewah/ewok.h" #include "lockfile.h" #include "color.h" @@ -239,6 +240,9 @@ static void refresh_index_quietly(void) struct lock_file lock_file = LOCK_INIT; int fd; + if (!use_optional_locks()) + return; + fd = repo_hold_locked_index(the_repository, &lock_file, 0); if (fd < 0) return; diff --git a/t/meson.build b/t/meson.build index a59da26be3f..10d7cace3c6 100644 --- a/t/meson.build +++ b/t/meson.build @@ -500,6 +500,7 @@ integration_tests = [ 't4067-diff-partial-clone.sh', 't4068-diff-symmetric-merge-base.sh', 't4069-remerge-diff.sh', + 't4070-diff-auto-refresh-index.sh', 't4100-apply-stat.sh', 't4101-apply-nonl.sh', 't4102-apply-rename.sh', diff --git a/t/t4070-diff-auto-refresh-index.sh b/t/t4070-diff-auto-refresh-index.sh new file mode 100755 index 00000000000..9e38f1d3206 --- /dev/null +++ b/t/t4070-diff-auto-refresh-index.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Copyright (c) 2025 Benjamin Woodruff +# + +test_description='diff.autoRefreshIndex config option' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-diff.sh + +test_expect_success 'index is updated when autoRefreshIndex is true' ' + >tracked && + git add tracked && + + # stat() must change (but not file contents) to trigger an index update + test_set_magic_mtime tracked && + + # check the mtime of .git/index does not change without autoRefreshIndex + test_set_magic_mtime .git/index && + git config diff.autoRefreshIndex false && + git diff && + test_is_magic_mtime .git/index && + + # but it does change when autoRefreshIndex is true (the default) + git config diff.autoRefreshIndex true && + git diff && + ! test_is_magic_mtime .git/index +' + +test_expect_success '--no-optional-locks overrides autoRefreshIndex' ' + >tracked && + git add tracked && + test_set_magic_mtime tracked && + + # `--no-optional-locks` overrides `autoRefreshIndex` + test_set_magic_mtime .git/index && + git config diff.autoRefreshIndex true && + git --no-optional-locks diff && + + # sanity check that without `--no-optional-locks` it still updates + test_is_magic_mtime .git/index && + git diff && + ! test_is_magic_mtime .git/index +' + +test_done