Skip to content

Commit 8e118e8

Browse files
peffgitster
authored andcommitted
pack-objects: update "nr_seen" progress based on pack-reused count
When serving a clone or fetch with bitmaps, after deciding which objects need to be sent our "pack reuse" mechanism kicks in: we try to send more-or-less verbatim a bunch of objects from the beginning of the bitmapped packfile without even adding them to the to_pack.objects array. After deciding which objects will be in the "reused" portion, we update nr_result to account for those, and then trigger display_progress() to show the user (who is undoubtedly dazzled that we managed to enumerate so many objects so quickly). But then something confusing happens: the "Enumerating objects" progress meter jumps _backwards_, counting up from zero the number of objects we actually add into to_pack.objects. This worked correctly once upon a time, but was broken in 5af0504 (pack-objects: show some progress when counting kept objects, 2018-04-15), when the latter half of that progress meter switched to using a separate nr_seen counter, rather than nr_result. Nobody noticed for two reasons: - prior to the pack-reuse fixes from a14aebe (Merge branch 'jk/packfile-reuse-cleanup', 2020-02-14), the reuse code almost never kicked in anyway - the output looks _kind of_ correct. The "backwards" moment is hard to catch, because we overwrite the old progress number with the new one, and the larger number is displayed only for a second. So unless you look at that exact second, you just see the much smaller value, counting up to the number of non-reused objects (though of course if you catch it in stderr, or look at GIT_TRACE_PACKET from a server with bitmaps, you can see both values). This smaller output isn't wrong per se, but isn't counting what we ever intended to. We should give the user the whole number of objects we considered (which, as per 5af0504's original purpose, is already _not_ a count of what goes into to_pack.objects). The follow-on "Counting objects" meter shows the actual number of objects we feed into that array. We can easily fix this by bumping (and showing) nr_seen for the pack-reused objects. When the included test is run without this patch, the second pack-objects invocation produces "Enumerating objects: 1" to show the one loose object, even though the resulting pack has hundreds of objects in it. With it, we jump to "Enumerating objects: 674" after deciding on reuse, and then "675" when we add in the loose object. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bf2fa commit 8e118e8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3317,7 +3317,8 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
33173317
&reuse_packfile_bitmap)) {
33183318
assert(reuse_packfile_objects);
33193319
nr_result += reuse_packfile_objects;
3320-
display_progress(progress_state, nr_result);
3320+
nr_seen += reuse_packfile_objects;
3321+
display_progress(progress_state, nr_seen);
33213322
}
33223323

33233324
traverse_bitmap_commit_list(bitmap_git, revs,

t/t5310-pack-bitmaps.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,29 @@ test_expect_success 'truncated bitmap fails gracefully (cache)' '
461461
test_i18ngrep corrupted.bitmap.index stderr
462462
'
463463

464+
test_expect_success 'enumerating progress counts pack-reused objects' '
465+
count=$(git rev-list --objects --all --count) &&
466+
git repack -adb &&
467+
468+
# check first with only reused objects; confirm that our progress
469+
# showed the right number, and also that we did pack-reuse as expected.
470+
# Check only the final "done" line of the meter (there may be an
471+
# arbitrary number of intermediate lines ending with CR).
472+
GIT_PROGRESS_DELAY=0 \
473+
git pack-objects --all --stdout --progress \
474+
</dev/null >/dev/null 2>stderr &&
475+
grep "Enumerating objects: $count, done" stderr &&
476+
grep "pack-reused $count" stderr &&
477+
478+
# now the same but with one non-reused object
479+
git commit --allow-empty -m "an extra commit object" &&
480+
GIT_PROGRESS_DELAY=0 \
481+
git pack-objects --all --stdout --progress \
482+
</dev/null >/dev/null 2>stderr &&
483+
grep "Enumerating objects: $((count+1)), done" stderr &&
484+
grep "pack-reused $count" stderr
485+
'
486+
464487
# have_delta <obj> <expected_base>
465488
#
466489
# Note that because this relies on cat-file, it might find _any_ copy of an

0 commit comments

Comments
 (0)