pack-bitmap: refuse to do a bitmap traversal with pathspecs

rev-list has refused to use bitmaps with pathspec limiting since
c8a70d3509 (rev-list: disable --use-bitmap-index when pruning commits,
2015-07-01). But this is true not just for rev-list, but for anyone who
calls prepare_bitmap_walk(); the code isn't equipped to handle this
case.  We never noticed because the only other callers would never pass
a pathspec limiter.

But let's push the check down into prepare_bitmap_walk() anyway. That's
a more logical place for it to live, as callers shouldn't need to know
the details (and must be prepared to fall back to a regular traversal
anyway, since there might not be bitmaps in the repository).

It would also prepare us for a day where this case _is_ handled, but
that's pretty unlikely. E.g., we could use bitmaps to generate the set
of commits, and then diff each commit to see if it matches the pathspec.
That would be slightly faster than a naive traversal that actually walks
the commits. But you'd probably do better still to make use of the newer
commit-graph feature to make walking the commits very cheap.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2020-02-14 13:22:16 -05:00 коммит произвёл Junio C Hamano
Родитель e03f928e2a
Коммит d90fe06ea7
2 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -533,7 +533,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
if (show_progress)
progress = start_delayed_progress(show_progress, 0);
if (use_bitmap_index && !revs.prune) {
if (use_bitmap_index) {
if (revs.count && !revs.left_right && !revs.cherry_mark) {
uint32_t commit_count;
int max_count = revs.max_count;

Просмотреть файл

@ -715,9 +715,19 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
struct bitmap *wants_bitmap = NULL;
struct bitmap *haves_bitmap = NULL;
struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
struct bitmap_index *bitmap_git;
/*
* We can't do pathspec limiting with bitmaps, because we don't know
* which commits are associated with which object changes (let alone
* even which objects are associated with which paths).
*/
if (revs->prune)
return NULL;
/* try to open a bitmapped pack, but don't parse it yet
* because we may not need to use it */
bitmap_git = xcalloc(1, sizeof(*bitmap_git));
if (open_pack_bitmap(revs->repo, bitmap_git) < 0)
goto cleanup;