git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Two issues with mark_reachable_objects
@ 2021-04-27 10:45 David Emett
  2021-04-27 14:41 ` Jeff King
  2021-04-27 15:43 ` [PATCH] prune: save reachable-from-recent objects with bitmaps Jeff King
  0 siblings, 2 replies; 10+ messages in thread
From: David Emett @ 2021-04-27 10:45 UTC (permalink / raw)
  To: git

Hi all,

I ran into an issue yesterday with a script that effectively does this:

    set -e
    git fetch origin refs/blah/blah
    git checkout FETCH_HEAD

The checkout failed a few times with a "fatal: unable to read tree" error.

I noticed that this only happened when the fetch triggered an automatic GC at
the end. After a bit of digging I discovered two separate issues:

1) It seems that FETCH_HEAD is not considered a root by mark_reachable_objects.

2) If the bitmap_git branch in mark_reachable_objects is taken, the mark_recent
   argument is ignored. This doesn't _completely_ break "git prune"'s --expire
   option, as it turns out there is another explicit mtime check in
   prune_object (prune.c). If that check passes this is not propagated to
   referenced objects though. So even if a dangling commit is recent, a prune
   can discard old objects it references.

(1) has been discussed before on this mailing list [1], but it doesn't look
like there was a conclusion.

I assume (2) is not intentional, given that "git gc --help" explicitly says
"Any object with modification time newer than the --prune date is kept, along
with everything reachable from it." Is it safe to just run the mark_recent
block after the bitmap_git block? Could add_unseen_recent_objects_to_traversal
just be called at the start of the bitmap_git block if mark_recent?

[1] https://lore.kernel.org/git/20160708025948.GA3226@x/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two issues with mark_reachable_objects
  2021-04-27 10:45 Two issues with mark_reachable_objects David Emett
@ 2021-04-27 14:41 ` Jeff King
  2021-04-27 15:13   ` Jeff King
  2021-04-27 15:43 ` [PATCH] prune: save reachable-from-recent objects with bitmaps Jeff King
  1 sibling, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-04-27 14:41 UTC (permalink / raw)
  To: David Emett; +Cc: git

On Tue, Apr 27, 2021 at 11:45:01AM +0100, David Emett wrote:

> I noticed that this only happened when the fetch triggered an automatic GC at
> the end. After a bit of digging I discovered two separate issues:
> 
> 1) It seems that FETCH_HEAD is not considered a root by mark_reachable_objects.

Right, as you discovered, this is known and intentional. I don't have
anything to add to the thread you linked already.

> 2) If the bitmap_git branch in mark_reachable_objects is taken, the mark_recent
>    argument is ignored. This doesn't _completely_ break "git prune"'s --expire
>    option, as it turns out there is another explicit mtime check in
>    prune_object (prune.c). If that check passes this is not propagated to
>    referenced objects though. So even if a dangling commit is recent, a prune
>    can discard old objects it references.

But this one is a scary bug. As you note, it's not _completely_ breaking
"--expire", but it is totally disabling the "reachable from recent"
safety added in d3038d22f9 (prune: keep objects reachable from recent
objects, 2014-10-15).

The bug here was introduced by me, and comes from a matter of timing.
Despite what you'll see in the project history, the "use bitmaps" patch
actually predates the "reachable from recent" one. I just didn't clean
it up and upstream it until 2019, and failed to notice the bad
interaction between the two.

> I assume (2) is not intentional, given that "git gc --help" explicitly says
> "Any object with modification time newer than the --prune date is kept, along
> with everything reachable from it." Is it safe to just run the mark_recent
> block after the bitmap_git block? Could add_unseen_recent_objects_to_traversal
> just be called at the start of the bitmap_git block if mark_recent?

So no, definitely not intentional.

I think we'd just want to run the whole mark_recent block after doing
the bitmap traversal.

There may be some subtlety with reusing the rev_info struct again. I
think we'd want to reset the pending objects list after calling into the
bitmap code. It _usually_ does an actual traversal that consumes the
list, but not necessarily. I think traverse_bitmap_commit_list()
probably ought to be the one to do it, so it behaves more like
traverse_commit_list(). (OTOH, I don't think it's _too_ bad if we don't;
we'd include those already-seen objects in our traversal, but they
should all by definition have the SEEN bit set, so we'd stop there).

I don't think we want to add_unseen_recent_objects_to_traversal() to
include it as part of the same traversal, for the same reason the
non-bitmap traversal does not combine them: the mark_recent traversal is
best-effort. We set revs->ignore_missing_links to be tolerant of
already-broken segments of history.

It's possible that we could do the second mark_recent traversal also
with bitmaps (but still separately). I can't offhand think of a reason
that ignore_missing_links wouldn't behave well there. But since we
expect it to be small, I'd be more comfortable just using the regular
traversal code.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two issues with mark_reachable_objects
  2021-04-27 14:41 ` Jeff King
@ 2021-04-27 15:13   ` Jeff King
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2021-04-27 15:13 UTC (permalink / raw)
  To: David Emett; +Cc: git

On Tue, Apr 27, 2021 at 10:41:18AM -0400, Jeff King wrote:

> I think we'd just want to run the whole mark_recent block after doing
> the bitmap traversal.
> 
> There may be some subtlety with reusing the rev_info struct again. I
> think we'd want to reset the pending objects list after calling into the
> bitmap code. It _usually_ does an actual traversal that consumes the
> list, but not necessarily. I think traverse_bitmap_commit_list()
> probably ought to be the one to do it, so it behaves more like
> traverse_commit_list(). (OTOH, I don't think it's _too_ bad if we don't;
> we'd include those already-seen objects in our traversal, but they
> should all by definition have the SEEN bit set, so we'd stop there).

Nope, I was wrong here. It's actually prepare_bitmap_walk() which would
want to clear the pending list, and it does so (it may later re-add
objects in find_objects(), but if it does so, it will definitely
traverse and consume them).

> It's possible that we could do the second mark_recent traversal also
> with bitmaps (but still separately). I can't offhand think of a reason
> that ignore_missing_links wouldn't behave well there. But since we
> expect it to be small, I'd be more comfortable just using the regular
> traversal code.

I poked at this a bit, and indeed, the bitmap code is not ready to
handle the caller passing ignore_missing_links (it performs two separate
traversals for the wanted and uninteresting objects, and manipulates
ignore_missing_links itself between the two). It would probably be easy
to change, but I think we should focus on the minimal fix for the bug
you found first.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] prune: save reachable-from-recent objects with bitmaps
  2021-04-27 10:45 Two issues with mark_reachable_objects David Emett
  2021-04-27 14:41 ` Jeff King
@ 2021-04-27 15:43 ` Jeff King
  2021-04-28 12:20   ` David Emett
  1 sibling, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-04-27 15:43 UTC (permalink / raw)
  To: David Emett; +Cc: git

On Tue, Apr 27, 2021 at 11:45:01AM +0100, David Emett wrote:

> I assume (2) is not intentional, given that "git gc --help" explicitly says
> "Any object with modification time newer than the --prune date is kept, along
> with everything reachable from it." Is it safe to just run the mark_recent
> block after the bitmap_git block? Could add_unseen_recent_objects_to_traversal
> just be called at the start of the bitmap_git block if mark_recent?

Here's a fix. Thanks very much for reporting.

I was a little surprised you saw this with "git gc", as when I tried
testing with that, I found that the "git repack" run before "git prune"
works around the bug (see the discussion of t6501 below). But I think
perhaps it is just that "gc --auto" is more willing to do a "repack -d"
sometimes, rather than a full "repack -A". At any rate, I was able to
easily reproduce it for the tests with just git-prune.

-- >8 --
Subject: prune: save reachable-from-recent objects with bitmaps

We pass our prune expiration to mark_reachable_objects(), which will
traverse not only the reachable objects, but consider any recent ones as
tips for reachability; see d3038d22f9 (prune: keep objects reachable
from recent objects, 2014-10-15) for details.

However, this interacts badly with the bitmap code path added in
fde67d6896 (prune: use bitmaps for reachability traversal, 2019-02-13).
If we hit the bitmap-optimized path, we return immediately to avoid the
regular traversal, accidentally skipping the "also traverse recent"
code.

Instead, we should do an if-else for the bitmap versus regular
traversal, and then follow up with the "recent" traversal in either
case. This reuses the "rev_info" for a bitmap and then a regular
traversal, but that should work OK (the bitmap code clears the pending
array in the usual way, just like a regular traversal would).

Note that I dropped the comment above the regular traversal here.  It
has little explanatory value, and makes the if-else logic much harder to
read.

Here are a few variants that I rejected:

  - it seems like both the reachability and recent traversals could be
    done in a single traversal. This was rejected by d3038d22f9 (prune:
    keep objects reachable from recent objects, 2014-10-15), though the
    balance may be different when using bitmaps. However, there's a
    subtle correctness issue, too: we use revs->ignore_missing_links for
    the recent traversal, but not the reachability one.

  - we could try using bitmaps for the recent traversal, too, which
    could possibly improve performance. But it would require some fixes
    in the bitmap code, which uses ignore_missing_links for its own
    purposes. Plus it would probably not help all that much in practice.
    We use the reachable tips to generate bitmaps, so those objects are
    likely not covered by bitmaps (unless they just became unreachable).
    And in general, we expect the set of unreachable objects to be much
    smaller anyway, so there's less to gain.

The test in t5304 detects the bug and confirms the fix.

I also beefed up the tests in t6501, which covers the mtime-checking
code more thoroughly, to handle the bitmap case (in addition to just
"loose" and "packed" cases). Interestingly, this test doesn't actually
detect the bug, because it is running "git gc", and not "prune"
directly. And "gc" will call "repack" first, which does not suffer the
same bug. So the old-but-reachable-from-recent objects get scooped up
into the new pack along with the actually-recent objects, which gives
both a recent mtime. But it seemed prudent to get more coverage of the
bitmap case for related code.

Reported-by: David Emett <dave@sp4m.net>
Signed-off-by: Jeff King <peff@peff.net>
---
 reachable.c                | 13 ++++---------
 t/t5304-prune.sh           | 13 +++++++++++++
 t/t6501-freshen-objects.sh | 21 +++++++++++++++------
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/reachable.c b/reachable.c
index 77a60c70a5..a088717eb5 100644
--- a/reachable.c
+++ b/reachable.c
@@ -227,17 +227,12 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
 	if (bitmap_git) {
 		traverse_bitmap_commit_list(bitmap_git, revs, mark_object_seen);
 		free_bitmap_index(bitmap_git);
-		return;
+	} else {
+		if (prepare_revision_walk(revs))
+			die("revision walk setup failed");
+		traverse_commit_list(revs, mark_commit, mark_object, &cp);
 	}
 
-	/*
-	 * Set up the revision walk - this will move all commits
-	 * from the pending list to the commit walking list.
-	 */
-	if (prepare_revision_walk(revs))
-		die("revision walk setup failed");
-	traverse_commit_list(revs, mark_commit, mark_object, &cp);
-
 	if (mark_recent) {
 		revs->ignore_missing_links = 1;
 		if (add_unseen_recent_objects_to_traversal(revs, mark_recent))
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index b447ce56a9..20fcc2da1f 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -352,4 +352,17 @@ test_expect_success 'trivial prune with bitmaps enabled' '
 	test_must_fail git cat-file -e $blob
 '
 
+test_expect_success 'old reachable-from-recent retained with bitmaps' '
+	git repack -adb &&
+	to_drop=$(echo bitmap-from-recent-1 | git hash-object -w --stdin) &&
+	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_drop) &&
+	to_save=$(echo bitmap-from-recent-2 | git hash-object -w --stdin) &&
+	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_save) &&
+	tree=$(printf "100644 blob $to_save\tfile\n" | git mktree) &&
+	git prune --expire=12.hours.ago &&
+	git cat-file -e $tree &&
+	git cat-file -e $to_save &&
+	test_must_fail git cat-file -e $to_drop
+'
+
 test_done
diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh
index 75210f012b..de7742cc51 100755
--- a/t/t6501-freshen-objects.sh
+++ b/t/t6501-freshen-objects.sh
@@ -43,15 +43,24 @@ commit () {
 }
 
 maybe_repack () {
-	if test -n "$repack"; then
+	case "$title" in
+	loose)
+		: skip repack
+		;;
+	repack)
 		git repack -ad
-	fi
+		;;
+	bitmap)
+		git repack -adb
+		;;
+	*)
+		echo >&2 "unknown test type in maybe_repack"
+		return 1
+		;;
+	esac
 }
 
-for repack in '' true; do
-	title=${repack:+repack}
-	title=${title:-loose}
-
+for title in loose repack bitmap; do
 	test_expect_success "make repo completely empty ($title)" '
 		rm -rf .git &&
 		git init
-- 
2.31.1.789.g4530770a26


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] prune: save reachable-from-recent objects with bitmaps
  2021-04-27 15:43 ` [PATCH] prune: save reachable-from-recent objects with bitmaps Jeff King
@ 2021-04-28 12:20   ` David Emett
  2021-04-28 15:13     ` Jeff King
  0 siblings, 1 reply; 10+ messages in thread
From: David Emett @ 2021-04-28 12:20 UTC (permalink / raw)
  To: Jeff King; +Cc: git

> Here's a fix. Thanks very much for reporting.

Thanks for the quick response! I tried the fix out on the repo I was having
trouble with. It's hitting a segfault in traverse_commit_list in the
mark_recent block. It looks like the issue is that the bitmap code leaves
revs->include_check set, with revs->include_check_data pointing at the stack.
Setting revs->include_check to NULL after the traverse_commit_list call in
find_objects in pack-bitmap.c fixes the segfault for me. And the original issue
appears to be resolved as well, so thanks!

> I was a little surprised you saw this with "git gc", as when I tried
> testing with that, I found that the "git repack" run before "git prune"
> works around the bug (see the discussion of t6501 below). But I think
> perhaps it is just that "gc --auto" is more willing to do a "repack -d"
> sometimes, rather than a full "repack -A". At any rate, I was able to
> easily reproduce it for the tests with just git-prune.

I can't say for sure that this bug is what I was seeing originally, however it
does seem quite likely -- the commits that hit issues were minor updates of
commits that had been fetched a month or so earlier, and so would certainly fit
the bill. Like you though I've just been reproducing with git prune.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] prune: save reachable-from-recent objects with bitmaps
  2021-04-28 12:20   ` David Emett
@ 2021-04-28 15:13     ` Jeff King
  2021-04-28 15:41       ` [PATCH v2 0/2] " Jeff King
  0 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-04-28 15:13 UTC (permalink / raw)
  To: David Emett; +Cc: git

On Wed, Apr 28, 2021 at 01:20:03PM +0100, David Emett wrote:

> > Here's a fix. Thanks very much for reporting.
> 
> Thanks for the quick response! I tried the fix out on the repo I was having
> trouble with. It's hitting a segfault in traverse_commit_list in the
> mark_recent block. It looks like the issue is that the bitmap code leaves
> revs->include_check set, with revs->include_check_data pointing at the stack.
> Setting revs->include_check to NULL after the traverse_commit_list call in
> find_objects in pack-bitmap.c fixes the segfault for me. And the original issue
> appears to be resolved as well, so thanks!

Oof, good catch. I wondered why my test didn't see this. The answer is
that the include_check only applies to commits, not trees. And my test
only has a recent-but-unreachable tree. Beefing it up to include an
actual commit shows the problem (and ASan nicely pinpoints the issue).

The solution, as you noted, is to have the bitmap code clean up after
itself.

I'll prepare a re-roll of the series.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 0/2] prune: save reachable-from-recent objects with bitmaps
  2021-04-28 15:13     ` Jeff King
@ 2021-04-28 15:41       ` Jeff King
  2021-04-28 15:42         ` [PATCH v2 1/2] pack-bitmap: clean up include_check after use Jeff King
  2021-04-28 15:42         ` [PATCH v2 2/2] prune: save reachable-from-recent objects with bitmaps Jeff King
  0 siblings, 2 replies; 10+ messages in thread
From: Jeff King @ 2021-04-28 15:41 UTC (permalink / raw)
  To: David Emett; +Cc: git

On Wed, Apr 28, 2021 at 11:13:57AM -0400, Jeff King wrote:

> On Wed, Apr 28, 2021 at 01:20:03PM +0100, David Emett wrote:
> 
> > > Here's a fix. Thanks very much for reporting.
> > 
> > Thanks for the quick response! I tried the fix out on the repo I was having
> > trouble with. It's hitting a segfault in traverse_commit_list in the
> > mark_recent block. It looks like the issue is that the bitmap code leaves
> > revs->include_check set, with revs->include_check_data pointing at the stack.
> > Setting revs->include_check to NULL after the traverse_commit_list call in
> > find_objects in pack-bitmap.c fixes the segfault for me. And the original issue
> > appears to be resolved as well, so thanks!
> 
> Oof, good catch. I wondered why my test didn't see this. The answer is
> that the include_check only applies to commits, not trees. And my test
> only has a recent-but-unreachable tree. Beefing it up to include an
> actual commit shows the problem (and ASan nicely pinpoints the issue).
> 
> The solution, as you noted, is to have the bitmap code clean up after
> itself.
> 
> I'll prepare a re-roll of the series.

Here it is.

I did notice one other oddity. The bitmap code doesn't do any sort of
progress reporting. So progress is enabled, we'll _just_ count the
recent-but-unreachable entries in the progress meter.

That's not entirely wrong (it represents the actual traversal work we're
doing), but is a little funny. However, I think the best thing to do for
now is to leave it there. The right path forward is for the bitmap code
to learn about progress reporting, too (for this case, but also for
others). But that's a more involved topic, and I don't want to hold up
this fix for it.

  [1/2]: pack-bitmap: clean up include_check after use
  [2/2]: prune: save reachable-from-recent objects with bitmaps

 pack-bitmap.c              |  3 +++
 reachable.c                | 13 ++++---------
 t/t5304-prune.sh           | 16 ++++++++++++++++
 t/t6501-freshen-objects.sh | 21 +++++++++++++++------
 4 files changed, 38 insertions(+), 15 deletions(-)

-:  ---------- > 1:  43f25e88c5 pack-bitmap: clean up include_check after use
1:  a7fb2a7f5b ! 2:  0a60ea597d prune: save reachable-from-recent objects with bitmaps
    @@ t/t5304-prune.sh: test_expect_success 'trivial prune with bitmaps enabled' '
     +	to_save=$(echo bitmap-from-recent-2 | git hash-object -w --stdin) &&
     +	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_save) &&
     +	tree=$(printf "100644 blob $to_save\tfile\n" | git mktree) &&
    ++	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $tree) &&
    ++	commit=$(echo foo | git commit-tree $tree) &&
     +	git prune --expire=12.hours.ago &&
    ++	git cat-file -e $commit &&
     +	git cat-file -e $tree &&
     +	git cat-file -e $to_save &&
     +	test_must_fail git cat-file -e $to_drop

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] pack-bitmap: clean up include_check after use
  2021-04-28 15:41       ` [PATCH v2 0/2] " Jeff King
@ 2021-04-28 15:42         ` Jeff King
  2021-04-28 15:42         ` [PATCH v2 2/2] prune: save reachable-from-recent objects with bitmaps Jeff King
  1 sibling, 0 replies; 10+ messages in thread
From: Jeff King @ 2021-04-28 15:42 UTC (permalink / raw)
  To: David Emett; +Cc: git

When a bitmap walk has to traverse (to fill in non-bitmapped objects),
we use rev_info's include_check mechanism to let us stop the traversal
early. But after setting the function and its data parameter, we never
clean it up. This means that if the rev_info is used for a subsequent
traversal without bitmaps, it will unexpectedly call into our
include_check function (worse, it will do so pointing to a now-defunct
stack variable in include_check_data, likely resulting in a segfault).

There's no code which does this now, but it's an accident waiting to
happen. Let's clean up after ourselves in the bitmap code.

Reported-by: David Emett <dave@sp4m.net>
Signed-off-by: Jeff King <peff@peff.net>
---
 pack-bitmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pack-bitmap.c b/pack-bitmap.c
index 3ed15431cd..f2b59fbf48 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -631,6 +631,9 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
 		traverse_commit_list_filtered(filter, revs,
 					      show_commit, show_object,
 					      &show_data, NULL);
+
+		revs->include_check = NULL;
+		revs->include_check_data = NULL;
 	}
 
 	return base;
-- 
2.31.1.791.g8400859cdc


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] prune: save reachable-from-recent objects with bitmaps
  2021-04-28 15:41       ` [PATCH v2 0/2] " Jeff King
  2021-04-28 15:42         ` [PATCH v2 1/2] pack-bitmap: clean up include_check after use Jeff King
@ 2021-04-28 15:42         ` Jeff King
  2021-04-29  1:37           ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Jeff King @ 2021-04-28 15:42 UTC (permalink / raw)
  To: David Emett; +Cc: git

We pass our prune expiration to mark_reachable_objects(), which will
traverse not only the reachable objects, but consider any recent ones as
tips for reachability; see d3038d22f9 (prune: keep objects reachable
from recent objects, 2014-10-15) for details.

However, this interacts badly with the bitmap code path added in
fde67d6896 (prune: use bitmaps for reachability traversal, 2019-02-13).
If we hit the bitmap-optimized path, we return immediately to avoid the
regular traversal, accidentally skipping the "also traverse recent"
code.

Instead, we should do an if-else for the bitmap versus regular
traversal, and then follow up with the "recent" traversal in either
case. This reuses the "rev_info" for a bitmap and then a regular
traversal, but that should work OK (the bitmap code clears the pending
array in the usual way, just like a regular traversal would).

Note that I dropped the comment above the regular traversal here.  It
has little explanatory value, and makes the if-else logic much harder to
read.

Here are a few variants that I rejected:

  - it seems like both the reachability and recent traversals could be
    done in a single traversal. This was rejected by d3038d22f9 (prune:
    keep objects reachable from recent objects, 2014-10-15), though the
    balance may be different when using bitmaps. However, there's a
    subtle correctness issue, too: we use revs->ignore_missing_links for
    the recent traversal, but not the reachability one.

  - we could try using bitmaps for the recent traversal, too, which
    could possibly improve performance. But it would require some fixes
    in the bitmap code, which uses ignore_missing_links for its own
    purposes. Plus it would probably not help all that much in practice.
    We use the reachable tips to generate bitmaps, so those objects are
    likely not covered by bitmaps (unless they just became unreachable).
    And in general, we expect the set of unreachable objects to be much
    smaller anyway, so there's less to gain.

The test in t5304 detects the bug and confirms the fix.

I also beefed up the tests in t6501, which covers the mtime-checking
code more thoroughly, to handle the bitmap case (in addition to just
"loose" and "packed" cases). Interestingly, this test doesn't actually
detect the bug, because it is running "git gc", and not "prune"
directly. And "gc" will call "repack" first, which does not suffer the
same bug. So the old-but-reachable-from-recent objects get scooped up
into the new pack along with the actually-recent objects, which gives
both a recent mtime. But it seemed prudent to get more coverage of the
bitmap case for related code.

Reported-by: David Emett <dave@sp4m.net>
Signed-off-by: Jeff King <peff@peff.net>
---
 reachable.c                | 13 ++++---------
 t/t5304-prune.sh           | 16 ++++++++++++++++
 t/t6501-freshen-objects.sh | 21 +++++++++++++++------
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/reachable.c b/reachable.c
index 77a60c70a5..a088717eb5 100644
--- a/reachable.c
+++ b/reachable.c
@@ -227,17 +227,12 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
 	if (bitmap_git) {
 		traverse_bitmap_commit_list(bitmap_git, revs, mark_object_seen);
 		free_bitmap_index(bitmap_git);
-		return;
+	} else {
+		if (prepare_revision_walk(revs))
+			die("revision walk setup failed");
+		traverse_commit_list(revs, mark_commit, mark_object, &cp);
 	}
 
-	/*
-	 * Set up the revision walk - this will move all commits
-	 * from the pending list to the commit walking list.
-	 */
-	if (prepare_revision_walk(revs))
-		die("revision walk setup failed");
-	traverse_commit_list(revs, mark_commit, mark_object, &cp);
-
 	if (mark_recent) {
 		revs->ignore_missing_links = 1;
 		if (add_unseen_recent_objects_to_traversal(revs, mark_recent))
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index b447ce56a9..3475b06aeb 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -352,4 +352,20 @@ test_expect_success 'trivial prune with bitmaps enabled' '
 	test_must_fail git cat-file -e $blob
 '
 
+test_expect_success 'old reachable-from-recent retained with bitmaps' '
+	git repack -adb &&
+	to_drop=$(echo bitmap-from-recent-1 | git hash-object -w --stdin) &&
+	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_drop) &&
+	to_save=$(echo bitmap-from-recent-2 | git hash-object -w --stdin) &&
+	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_save) &&
+	tree=$(printf "100644 blob $to_save\tfile\n" | git mktree) &&
+	test-tool chmtime -86400 .git/objects/$(test_oid_to_path $tree) &&
+	commit=$(echo foo | git commit-tree $tree) &&
+	git prune --expire=12.hours.ago &&
+	git cat-file -e $commit &&
+	git cat-file -e $tree &&
+	git cat-file -e $to_save &&
+	test_must_fail git cat-file -e $to_drop
+'
+
 test_done
diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh
index 75210f012b..de7742cc51 100755
--- a/t/t6501-freshen-objects.sh
+++ b/t/t6501-freshen-objects.sh
@@ -43,15 +43,24 @@ commit () {
 }
 
 maybe_repack () {
-	if test -n "$repack"; then
+	case "$title" in
+	loose)
+		: skip repack
+		;;
+	repack)
 		git repack -ad
-	fi
+		;;
+	bitmap)
+		git repack -adb
+		;;
+	*)
+		echo >&2 "unknown test type in maybe_repack"
+		return 1
+		;;
+	esac
 }
 
-for repack in '' true; do
-	title=${repack:+repack}
-	title=${title:-loose}
-
+for title in loose repack bitmap; do
 	test_expect_success "make repo completely empty ($title)" '
 		rm -rf .git &&
 		git init
-- 
2.31.1.791.g8400859cdc

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] prune: save reachable-from-recent objects with bitmaps
  2021-04-28 15:42         ` [PATCH v2 2/2] prune: save reachable-from-recent objects with bitmaps Jeff King
@ 2021-04-29  1:37           ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2021-04-29  1:37 UTC (permalink / raw)
  To: Jeff King; +Cc: David Emett, git

Jeff King <peff@peff.net> writes:

> -for repack in '' true; do
> -	title=${repack:+repack}
> -	title=${title:-loose}
> -
> +for title in loose repack bitmap; do
>  	test_expect_success "make repo completely empty ($title)" '
>  		rm -rf .git &&
>  		git init

Just this part alone is worth the update ;-) It was not even clear
what "repack" meant in the old loop, or what the significance of
setting it to "true" (as opposed to say "false").

Of course, the early return in the code removed by this patch
explains how the bug happened.  Will queue; thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-04-29  1:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 10:45 Two issues with mark_reachable_objects David Emett
2021-04-27 14:41 ` Jeff King
2021-04-27 15:13   ` Jeff King
2021-04-27 15:43 ` [PATCH] prune: save reachable-from-recent objects with bitmaps Jeff King
2021-04-28 12:20   ` David Emett
2021-04-28 15:13     ` Jeff King
2021-04-28 15:41       ` [PATCH v2 0/2] " Jeff King
2021-04-28 15:42         ` [PATCH v2 1/2] pack-bitmap: clean up include_check after use Jeff King
2021-04-28 15:42         ` [PATCH v2 2/2] prune: save reachable-from-recent objects with bitmaps Jeff King
2021-04-29  1:37           ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).