Skip to content

Commit 0623669

Browse files
committed
Merge branch 'tb/pack-preferred-tips-to-give-bitmap'
A configuration variable has been added to force tips of certain refs to be given a reachability bitmap. * tb/pack-preferred-tips-to-give-bitmap: builtin/pack-objects.c: respect 'pack.preferBitmapTips' t/helper/test-bitmap.c: initial commit pack-bitmap: add 'test_bitmap_commits()' helper
2 parents f63add4 + 3f267a1 commit 0623669

File tree

9 files changed

+142
-0
lines changed

9 files changed

+142
-0
lines changed

Documentation/config/pack.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ pack.useSparse::
122122
commits contain certain types of direct renames. Default is
123123
`true`.
124124

125+
pack.preferBitmapTips::
126+
When selecting which commits will receive bitmaps, prefer a
127+
commit at the tip of any reference that is a suffix of any value
128+
of this configuration over any other commits in the "selection
129+
window".
130+
+
131+
Note that setting this configuration to `refs/foo` does not mean that
132+
the commits at the tips of `refs/foo/bar` and `refs/foo/baz` will
133+
necessarily be selected. This is because commits are selected for
134+
bitmaps from within a series of windows of variable length.
135+
+
136+
If a commit at the tip of any reference which is a suffix of any value
137+
of this configuration is seen in a window, it is immediately given
138+
preference over any other commit in that window.
139+
125140
pack.writeBitmaps (deprecated)::
126141
This is a deprecated synonym for `repack.writeBitmaps`.
127142

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ X =
693693
PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
694694

695695
TEST_BUILTINS_OBJS += test-advise.o
696+
TEST_BUILTINS_OBJS += test-bitmap.o
696697
TEST_BUILTINS_OBJS += test-bloom.o
697698
TEST_BUILTINS_OBJS += test-chmtime.o
698699
TEST_BUILTINS_OBJS += test-config.o

builtin/pack-objects.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,37 @@ static void record_recent_commit(struct commit *commit, void *data)
35473547
oid_array_append(&recent_objects, &commit->object.oid);
35483548
}
35493549

3550+
static int mark_bitmap_preferred_tip(const char *refname,
3551+
const struct object_id *oid, int flags,
3552+
void *_data)
3553+
{
3554+
struct object_id peeled;
3555+
struct object *object;
3556+
3557+
if (!peel_iterated_oid(oid, &peeled))
3558+
oid = &peeled;
3559+
3560+
object = parse_object_or_die(oid, refname);
3561+
if (object->type == OBJ_COMMIT)
3562+
object->flags |= NEEDS_BITMAP;
3563+
3564+
return 0;
3565+
}
3566+
3567+
static void mark_bitmap_preferred_tips(void)
3568+
{
3569+
struct string_list_item *item;
3570+
const struct string_list *preferred_tips;
3571+
3572+
preferred_tips = bitmap_preferred_tips(the_repository);
3573+
if (!preferred_tips)
3574+
return;
3575+
3576+
for_each_string_list_item(item, preferred_tips) {
3577+
for_each_ref_in(item->string, mark_bitmap_preferred_tip, NULL);
3578+
}
3579+
}
3580+
35503581
static void get_object_list(int ac, const char **av)
35513582
{
35523583
struct rev_info revs;
@@ -3601,6 +3632,9 @@ static void get_object_list(int ac, const char **av)
36013632
if (use_delta_islands)
36023633
load_delta_islands(the_repository, progress);
36033634

3635+
if (write_bitmap_index)
3636+
mark_bitmap_preferred_tips();
3637+
36043638
if (prepare_revision_walk(&revs))
36053639
die(_("revision walk setup failed"));
36063640
mark_edges_uninteresting(&revs, show_edge, sparse);

pack-bitmap.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "repository.h"
1414
#include "object-store.h"
1515
#include "list-objects-filter-options.h"
16+
#include "config.h"
1617

1718
/*
1819
* An entry on the bitmap index, representing the bitmap for a given
@@ -1351,6 +1352,24 @@ void test_bitmap_walk(struct rev_info *revs)
13511352
free_bitmap_index(bitmap_git);
13521353
}
13531354

1355+
int test_bitmap_commits(struct repository *r)
1356+
{
1357+
struct bitmap_index *bitmap_git = prepare_bitmap_git(r);
1358+
struct object_id oid;
1359+
MAYBE_UNUSED void *value;
1360+
1361+
if (!bitmap_git)
1362+
die("failed to load bitmap indexes");
1363+
1364+
kh_foreach(bitmap_git->bitmaps, oid, value, {
1365+
printf("%s\n", oid_to_hex(&oid));
1366+
});
1367+
1368+
free_bitmap_index(bitmap_git);
1369+
1370+
return 0;
1371+
}
1372+
13541373
int rebuild_bitmap(const uint32_t *reposition,
13551374
struct ewah_bitmap *source,
13561375
struct bitmap *dest)
@@ -1512,3 +1531,8 @@ off_t get_disk_usage_from_bitmap(struct bitmap_index *bitmap_git,
15121531

15131532
return total;
15141533
}
1534+
1535+
const struct string_list *bitmap_preferred_tips(struct repository *r)
1536+
{
1537+
return repo_config_get_value_multi(r, "pack.preferbitmaptips");
1538+
}

pack-bitmap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "khash.h"
66
#include "pack.h"
77
#include "pack-objects.h"
8+
#include "string-list.h"
89

910
struct commit;
1011
struct repository;
@@ -49,6 +50,7 @@ void traverse_bitmap_commit_list(struct bitmap_index *,
4950
struct rev_info *revs,
5051
show_reachable_fn show_reachable);
5152
void test_bitmap_walk(struct rev_info *revs);
53+
int test_bitmap_commits(struct repository *r);
5254
struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
5355
struct list_objects_filter_options *filter);
5456
int reuse_partial_packfile_from_bitmap(struct bitmap_index *,
@@ -90,4 +92,6 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
9092
const char *filename,
9193
uint16_t options);
9294

95+
const struct string_list *bitmap_preferred_tips(struct repository *r);
96+
9397
#endif

t/helper/test-bitmap.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "test-tool.h"
2+
#include "cache.h"
3+
#include "pack-bitmap.h"
4+
5+
static int bitmap_list_commits(void)
6+
{
7+
return test_bitmap_commits(the_repository);
8+
}
9+
10+
int cmd__bitmap(int argc, const char **argv)
11+
{
12+
setup_git_directory();
13+
14+
if (argc != 2)
15+
goto usage;
16+
17+
if (!strcmp(argv[1], "list-commits"))
18+
return bitmap_list_commits();
19+
20+
usage:
21+
usage("\ttest-tool bitmap list-commits");
22+
23+
return -1;
24+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct test_cmd {
1515

1616
static struct test_cmd cmds[] = {
1717
{ "advise", cmd__advise_if_enabled },
18+
{ "bitmap", cmd__bitmap },
1819
{ "bloom", cmd__bloom },
1920
{ "chmtime", cmd__chmtime },
2021
{ "config", cmd__config },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "git-compat-util.h"
66

77
int cmd__advise_if_enabled(int argc, const char **argv);
8+
int cmd__bitmap(int argc, const char **argv);
89
int cmd__bloom(int argc, const char **argv);
910
int cmd__chmtime(int argc, const char **argv);
1011
int cmd__config(int argc, const char **argv);

t/t5310-pack-bitmaps.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,4 +554,42 @@ test_expect_success 'fetch with bitmaps can reuse old base' '
554554
)
555555
'
556556

557+
test_expect_success 'pack.preferBitmapTips' '
558+
git init repo &&
559+
test_when_finished "rm -fr repo" &&
560+
(
561+
cd repo &&
562+
563+
# create enough commits that not all are receive bitmap
564+
# coverage even if they are all at the tip of some reference.
565+
test_commit_bulk --message="%s" 103 &&
566+
567+
git rev-list HEAD >commits.raw &&
568+
sort <commits.raw >commits &&
569+
570+
git log --format="create refs/tags/%s %H" HEAD >refs &&
571+
git update-ref --stdin <refs &&
572+
573+
git repack -adb &&
574+
test-tool bitmap list-commits | sort >bitmaps &&
575+
576+
# remember which commits did not receive bitmaps
577+
comm -13 bitmaps commits >before &&
578+
test_file_not_empty before &&
579+
580+
# mark the commits which did not receive bitmaps as preferred,
581+
# and generate the bitmap again
582+
perl -pe "s{^}{create refs/tags/include/$. }" <before |
583+
git update-ref --stdin &&
584+
git -c pack.preferBitmapTips=refs/tags/include repack -adb &&
585+
586+
# finally, check that the commit(s) without bitmap coverage
587+
# are not the same ones as before
588+
test-tool bitmap list-commits | sort >bitmaps &&
589+
comm -13 bitmaps commits >after &&
590+
591+
! test_cmp before after
592+
)
593+
'
594+
557595
test_done

0 commit comments

Comments
 (0)