]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-bitmap: parse commits in `find_pseudo_merge_group_for_ref()`
authorTaylor Blau <me@ttaylorr.com>
Tue, 12 May 2026 00:47:03 +0000 (20:47 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 May 2026 01:36:18 +0000 (10:36 +0900)
`find_pseudo_merge_group_for_ref()` uses the commit's date to classify
it as either "stable" (older than the stable threshold) or "unstable"
(otherwise).

However, to find the relevant commit from a given OID, the function
`find_pseudo_merge_group_for_ref()` uses `lookup_commit()` which does
not parse commits.

Because an unparsed commit has its "date" set to zero, every candidate
is placed in the "stable" bucket regardless of its actual committer
timestamp. This means the `bitmapPseudoMerge.*.threshold` and
`stableThreshold` configuration options have no effect: the
stable/unstable split is always determined by comparing against zero
rather than the real commit date.

The net result is that pseudo-merge groups are partitioned by
`stableSize` instead of the intended decay-based sizing, and the
`sampleRate` knob (which only applies to the unstable path) is never
exercised.

Fix this by calling `repo_parse_commit()` after `lookup_commit()`,
bailing out of the callback if parsing fails.

The corresponding test configures two pseudo-merge groups that both
match all tags. The "stable" group uses `threshold=1.month.ago`, and the
"all" group uses `threshold=now`. The test use our custom
"GIT_TEST_DATE_NOW" environment variable by setting it to the value of
"$test_tick" to align Git's notion of "now" (and therefore
"1.month.ago") with the `test_tick` timestamps, so the commits appear to
be younger than one month: only the "all" group matches them, producing
exactly one pseudo-merge.

Without the fix every commit has `date == 0`, which satisfies `date <=
threshold` for both groups (since 0 is older than one month ago), and
the "stable" group erroneously matches as well.

Now that commits are correctly classified as "unstable", the bug
described in the test exercising the "sampleRate=0" test is reachable,
and the test is marked as failing. It will be fixed in a following
commit.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pseudo-merge.c
t/t5333-pseudo-merge-bitmaps.sh

index 34e1da00b4e2002740c14c1e798d70328e34a180..d79e5fb649a8b59df980bba8ac38c20c37b989e4 100644 (file)
@@ -236,6 +236,8 @@ static int find_pseudo_merge_group_for_ref(const struct reference *ref, void *_d
        c = lookup_commit(the_repository, maybe_peeled);
        if (!c)
                return 0;
+       if (repo_parse_commit(the_repository, c))
+               return 0;
        if (!packlist_find(writer->to_pack, maybe_peeled))
                return 0;
 
index 90459da5e63c315213e7b820e593252b8b437fb3..0032a16606bd701366736d50593bf148c033ae2c 100755 (executable)
@@ -592,32 +592,34 @@ test_expect_success 'apply pseudo-merges with overlapping groups during fill-in'
        )
 '
 
-test_expect_failure 'pseudo-merge commits are correctly classified by date' '
+test_expect_success 'pseudo-merge commits are correctly classified by date' '
        test_when_finished "rm -fr pseudo-merge-date-classification" &&
        git init pseudo-merge-date-classification &&
        (
                cd pseudo-merge-date-classification &&
 
                test_commit_bulk 64 &&
+
                tag_everything &&
                git repack -ad &&
 
                pack="$(ls .git/objects/pack/pack-*.pack)" &&
 
                # Configure two pseudo-merge groups: one that only
-               # matches "stable" refs (older than one month), and one
-               # that matches all refs. With 64 freshly-created tags
-               # (all younger than one month) the stable group should
-               # have zero pseudo-merges and the catch-all group should
-               # have one.
+               # matches "stable" refs (older than one month), and
+               # one that matches all refs. With 64 tags whose
+               # commits are all younger than one month, the
+               # "stable" group should have zero pseudo-merges and
+               # the "all" group should have one.
                #
                # Use GIT_TEST_DATE_NOW to align "now" (and therefore
                # "1.month.ago") with the test_tick timestamps so that
                # the commits are within the last month.
                #
-               # This exercises the date-based classification in
-               # find_pseudo_merge_group_for_ref(), which requires
-               # that commits are parsed before inspecting their date.
+               # Without parsing the commit, its date field would
+               # be zero, causing it to satisfy date <= threshold
+               # for the "stable" group as well, and both groups
+               # would produce pseudo-merges.
                git config bitmapPseudoMerge.stable.pattern "refs/tags/" &&
                git config bitmapPseudoMerge.stable.maxMerges 64 &&
                git config bitmapPseudoMerge.stable.stableThreshold never &&
@@ -637,7 +639,7 @@ test_expect_failure 'pseudo-merge commits are correctly classified by date' '
        )
 '
 
-test_expect_success 'sampleRate=0 does not cause division by zero' '
+test_expect_failure 'sampleRate=0 does not cause division by zero' '
        test_when_finished "rm -fr pseudo-merge-sample-rate-zero" &&
        git init pseudo-merge-sample-rate-zero &&
        (