Git fork

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

+142
+15
Documentation/config/pack.txt
··· 122 122 commits contain certain types of direct renames. Default is 123 123 `true`. 124 124 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 + 125 140 pack.writeBitmaps (deprecated):: 126 141 This is a deprecated synonym for `repack.writeBitmaps`. 127 142
+1
Makefile
··· 693 693 PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS)) 694 694 695 695 TEST_BUILTINS_OBJS += test-advise.o 696 + TEST_BUILTINS_OBJS += test-bitmap.o 696 697 TEST_BUILTINS_OBJS += test-bloom.o 697 698 TEST_BUILTINS_OBJS += test-chmtime.o 698 699 TEST_BUILTINS_OBJS += test-config.o
+34
builtin/pack-objects.c
··· 3547 3547 oid_array_append(&recent_objects, &commit->object.oid); 3548 3548 } 3549 3549 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 + 3550 3581 static void get_object_list(int ac, const char **av) 3551 3582 { 3552 3583 struct rev_info revs; ··· 3600 3631 3601 3632 if (use_delta_islands) 3602 3633 load_delta_islands(the_repository, progress); 3634 + 3635 + if (write_bitmap_index) 3636 + mark_bitmap_preferred_tips(); 3603 3637 3604 3638 if (prepare_revision_walk(&revs)) 3605 3639 die(_("revision walk setup failed"));
+24
pack-bitmap.c
··· 13 13 #include "repository.h" 14 14 #include "object-store.h" 15 15 #include "list-objects-filter-options.h" 16 + #include "config.h" 16 17 17 18 /* 18 19 * An entry on the bitmap index, representing the bitmap for a given ··· 1351 1352 free_bitmap_index(bitmap_git); 1352 1353 } 1353 1354 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 + 1354 1373 int rebuild_bitmap(const uint32_t *reposition, 1355 1374 struct ewah_bitmap *source, 1356 1375 struct bitmap *dest) ··· 1512 1531 1513 1532 return total; 1514 1533 } 1534 + 1535 + const struct string_list *bitmap_preferred_tips(struct repository *r) 1536 + { 1537 + return repo_config_get_value_multi(r, "pack.preferbitmaptips"); 1538 + }
+4
pack-bitmap.h
··· 5 5 #include "khash.h" 6 6 #include "pack.h" 7 7 #include "pack-objects.h" 8 + #include "string-list.h" 8 9 9 10 struct commit; 10 11 struct repository; ··· 49 50 struct rev_info *revs, 50 51 show_reachable_fn show_reachable); 51 52 void test_bitmap_walk(struct rev_info *revs); 53 + int test_bitmap_commits(struct repository *r); 52 54 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs, 53 55 struct list_objects_filter_options *filter); 54 56 int reuse_partial_packfile_from_bitmap(struct bitmap_index *, ··· 89 91 uint32_t index_nr, 90 92 const char *filename, 91 93 uint16_t options); 94 + 95 + const struct string_list *bitmap_preferred_tips(struct repository *r); 92 96 93 97 #endif
+24
t/helper/test-bitmap.c
··· 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 + }
+1
t/helper/test-tool.c
··· 15 15 16 16 static struct test_cmd cmds[] = { 17 17 { "advise", cmd__advise_if_enabled }, 18 + { "bitmap", cmd__bitmap }, 18 19 { "bloom", cmd__bloom }, 19 20 { "chmtime", cmd__chmtime }, 20 21 { "config", cmd__config },
+1
t/helper/test-tool.h
··· 5 5 #include "git-compat-util.h" 6 6 7 7 int cmd__advise_if_enabled(int argc, const char **argv); 8 + int cmd__bitmap(int argc, const char **argv); 8 9 int cmd__bloom(int argc, const char **argv); 9 10 int cmd__chmtime(int argc, const char **argv); 10 11 int cmd__config(int argc, const char **argv);
+38
t/t5310-pack-bitmaps.sh
··· 554 554 ) 555 555 ' 556 556 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 + 557 595 test_done