Received: from mout.web.de (mout.web.de [212.227.15.4]) (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 0390B2C11E7 for ; Tue, 2 Dec 2025 21:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764710204; cv=none; b=DyIYIoFcz5IV8IbGR+d7DyFPAOcTL90hgVUE6hb85SLamQXrsprGJoAJp0kcTVk20iaX0at8eSVlOAHoHjYeA+TjqWTPuSTdUs2Sqyv+FJpMASgAhzeZ4Pat2oQMQw6bjm5kqyynIAu2nsdgKEFkr86Pg9VmriFuBzjSDgdoCCQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764710204; c=relaxed/simple; bh=K5Cx0EeSjGCCZlsaIIC9Ghm4V/oUr40NeYXSmTkir8s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JHuVq83Z1uPUa5jF0hj6QWpBBhDpoaJWTevqQqSsv5Pv0RkrKTQsEkZI6hGg3jZMayWtIjSchrn2Wt6hzdzP2zoBF9ZlWF2qM5Nq+gutCvx59+sXi3JmIcSScht8DL2YCgXSVilmHS1oPcx0eK2BXUywPNT5sZeffu0rMC2VB1U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=Swho4j66; arc=none smtp.client-ip=212.227.15.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="Swho4j66" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1764710188; x=1765314988; i=l.s.r@web.de; bh=GrhMaTpu240j1wVSzOfR6hmw1gyEdA4p9b9RtQkCwcU=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To:Cc: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=Swho4j667Wz2QdmVDsil8EqnNiEEugEL6+dnBXlC0HChym4u6TzuF/Ilgj5YUTq1 qUJH/zjcM3omUUAYFI44+ClZsVuDa2ABCxDF9hzdeqrXSAxaJVHpXEDTiVf4esX9y FwUuYr1Zpq/IPodDGsyTt1AYbJ5hFNl5SgrbpR4I+FrjvOQ6GW3ecApbXKB1mEHV7 ZjoQy9cbTw9CVXO3/7MpA+o6lM1wcHMVDZYnoSPnJ0IvObyaLZcjpxpyEc1LCXgJh iXnaD9q5+7lbYiC9wvvAkeS2+mk6GKRXwEMGg1cOj6mzFLSuAZykD6gL2kISxSXKa cHsTC12/2le40nm0iA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.2.31] ([79.203.23.3]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MAcpg-1vFaQm1EfA-0084K9; Tue, 02 Dec 2025 22:16:28 +0100 Message-ID: Date: Tue, 2 Dec 2025 22:16:27 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] diff-index: don't queue unchanged filepairs with diff_change() To: Junio C Hamano Cc: Git List , "D. Ben Knoble" , Jeff King , Phillip Wood References: Content-Language: en-US From: =?UTF-8?Q?Ren=C3=A9_Scharfe?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags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m/hh1f6OH8Hq1yLLU6hzxyLfjwirVPPt9oN72nWRq2rDci1p atb24/4WLgPUzmfqVGSSIpJashG/kzIBcCpv3UIl+nxJRqfU6uefOgRV64CgYuSo67GgeU0AF i9dfywWocRj7bnQKp+Q2nNH/K79Gprqw3ddwBGoBBqAwu7rGcTs9rFwgJxuFHtg30FeJlFy7D 83c/vri05jbV2L1NCX725ZvdeOTnlKhPOMCqqusch2nmwpgPw3w== On 11/30/25 7:02 PM, Junio C Hamano wrote: > Ren=C3=A9 Scharfe writes: >=20 >> Add a new streamlined function for queuing unchanged filepairs and >> use it in show_modified(), which is called by diff_cache() via >> oneway_diff() and do_oneway_diff(). It allocates only a single filespe= c >> for each filepair and uses it twice with reference counting. This has = a >> measurable effect if there are a lot of them, like in the Linux repo: >> >> Benchmark 1: ./git_v2.52.0 -C ../linux diff --cached --find-copies-hard= er >> Time (mean =C2=B1 =CF=83): 31.8 ms =C2=B1 0.2 ms [User: 24.= 2 ms, System: 6.3 ms] >> Range (min =E2=80=A6 max): 31.5 ms =E2=80=A6 32.3 ms 85 runs >> >> Benchmark 2: ./git -C ../linux diff --cached --find-copies-harder >> Time (mean =C2=B1 =CF=83): 23.9 ms =C2=B1 0.2 ms [User: 18.= 1 ms, System: 4.6 ms] >> Range (min =E2=80=A6 max): 23.5 ms =E2=80=A6 24.4 ms 111 runs >> >> Summary >> ./git -C ../linux diff --cached --find-copies-harder ran >> 1.33 =C2=B1 0.01 times faster than ./git_v2.52.0 -C ../linux diff -= -cached --find-copies-harder >=20 > Nice. Is this technique only applicable to diff-index among the > three diff plumbing siblings? I suspect diff-files is an oddball > in that on the working tree side we do not necessarily have the > blob object names Indeed: - git diff-files compares index and working tree, - a copy is a new file with contents from an old file, - git ignores new files in the working tree. So in theory git diff-files can only detect copies in the other direction. Or is there a way I'm missing? In practice, however, it doesn't do that reliably because it simply skips up-to-date index entries. Oops. =2D-- >8 --- Subject: [PATCH v2 2/1] diff-files: fix copy detection Copy detection cannot work when comparing the index to the working tree because Git ignores files that it is not explicitly told to track. It should work in the other direction, though, i.e. for a reverse diff of the deletion of a copy from the index. d1f2d7e8ca (Make run_diff_index() use unpack_trees(), not read_tree(), 2008-01-19) broke it with a seemingly stray change to run_diff_files(). We didn't notice because there's no test for that. But even if we had one, it might have gone unnoticed because the breakage only happens with index preloading, which requires at least 1000 entries (more than most test repos have) and is racy because it runs in parallel with the actual command. Fix copy detection by queuing up-to-date and skip-worktree entries using diff_same(). While at it, use diff_same() also for queuing unchanged files not flagged as up-to-date, i.e. clean submodules and entries where preloading was not done at all or not quickly enough. It uses less memory than diff_change() and doesn't unnecessarily set the diff flag has_changes. Add two tests to cover running both without and with preloading. The first one passes reliably with the original code. The second one enables preloading and thus is racy. It has a good chance to pass even without the fix, but fails within seconds when running the test script with --stress. With the fix it runs fine for several minutes, until my patience runs out. Signed-off-by: Ren=C3=A9 Scharfe =2D-- Patch formatted with -U9 for easier review of the second hunk. diff-lib.c | 12 +++++++++--- t/t4007-rename-3.sh | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 8e624f38c6..5307390ff3 100644 =2D-- a/diff-lib.c +++ b/diff-lib.c @@ -220,20 +220,24 @@ void run_diff_files(struct rev_info *revs, unsigned = int option) * from the desired stage. */ pair =3D diff_unmerge(&revs->diffopt, ce->name); if (wt_mode) pair->two->mode =3D wt_mode; if (ce_stage(ce) !=3D diff_unmerged_stage) continue; } =20 - if (ce_uptodate(ce) || ce_skip_worktree(ce)) + if (ce_uptodate(ce) || ce_skip_worktree(ce)) { + if (revs->diffopt.flags.find_copies_harder) + diff_same(&revs->diffopt, ce->ce_mode, + &ce->oid, ce->name); continue; + } =20 /* * When CE_VALID is set (via "update-index --assume-unchanged" * or via adding paths while core.ignorestat is set to true), * the user has promised that the working tree file for that * path will not be modified. When CE_FSMONITOR_VALID is true, * the fsmonitor knows that the path hasn't been modified since * we refreshed the cached stat information. In either case, * we do not have to stat to see if the path has been removed @@ -266,20 +270,22 @@ void run_diff_files(struct rev_info *revs, unsigned = int option) =20 changed =3D match_stat_with_submodule(&revs->diffopt, ce, &st, ce_option, &dirty_submodule); newmode =3D ce_mode_from_stat(ce, st.st_mode); } =20 if (!changed && !dirty_submodule) { ce_mark_uptodate(ce); mark_fsmonitor_valid(istate, ce); - if (!revs->diffopt.flags.find_copies_harder) - continue; + if (revs->diffopt.flags.find_copies_harder) + diff_same(&revs->diffopt, newmode, + &ce->oid, ce->name); + continue; } oldmode =3D ce->ce_mode; old_oid =3D &ce->oid; new_oid =3D changed ? null_oid(the_hash_algo) : &ce->oid; diff_change(&revs->diffopt, oldmode, newmode, old_oid, new_oid, !is_null_oid(old_oid), !is_null_oid(new_oid), ce->name, 0, dirty_submodule); diff --git a/t/t4007-rename-3.sh b/t/t4007-rename-3.sh index 3fc81bcd76..1012a370dd 100755 =2D-- a/t/t4007-rename-3.sh +++ b/t/t4007-rename-3.sh @@ -61,19 +61,40 @@ cat >expected <current && compare_diff_raw current expected ' =20 test_expect_success 'tweak work tree' ' - rm -f path0/COPYING && + rm -f path0/COPYING +' + +cat >expected <current && + compare_diff_raw current expected +' + +test_expect_success 'copy detection, files to preloaded index' ' + GIT_TEST_PRELOAD_INDEX=3D1 \ + git diff-files -C --find-copies-harder -R >current && + compare_diff_raw current expected +' + +test_expect_success 'tweak index' ' git update-index --remove path0/COPYING ' # In the tree, there is only path0/COPYING. In the cache, path0 does # not have COPYING anymore and path1 has COPYING which is a copy of # path0/COPYING. Showing the full tree with cache should tell us about # the rename. =20 cat >expected <