Git fork

pack-bitmap-write: stop depending on `the_repository`

There are multiple sites in "pack-bitmap-write.c" where we use the
global `the_repository` variable, either explicitly or implicitly by
using `the_hash_algo`.

Refactor the code so that the `struct bitmap_writer` stores the
repository it is getting initialized with. Like this, we can adapt
callsites that use `the_repository` to instead use the repository
provided by the writer.

Remove the `USE_THE_REPOSITORY_VARIABLE` define.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
1a6768d1 e5957ca3

+19 -18
+18 -18
pack-bitmap-write.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 1 #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" ··· 48 47 memset(writer, 0, sizeof(struct bitmap_writer)); 49 48 if (writer->bitmaps) 50 49 BUG("bitmap writer already initialized"); 50 + writer->repo = r; 51 51 writer->bitmaps = kh_init_oid_map(); 52 52 writer->pseudo_merge_commits = kh_init_oid_map(); 53 53 writer->to_pack = pdata; ··· 415 415 bb->commits[bb->commits_nr++] = r->item; 416 416 } 417 417 418 - trace2_data_intmax("pack-bitmap-write", the_repository, 418 + trace2_data_intmax("pack-bitmap-write", writer->repo, 419 419 "num_selected_commits", writer->selected_nr); 420 - trace2_data_intmax("pack-bitmap-write", the_repository, 420 + trace2_data_intmax("pack-bitmap-write", writer->repo, 421 421 "num_maximal_commits", num_maximal); 422 422 423 423 release_revisions(&revs); ··· 460 460 switch (object_type(entry.mode)) { 461 461 case OBJ_TREE: 462 462 if (fill_bitmap_tree(writer, bitmap, 463 - lookup_tree(the_repository, &entry.oid)) < 0) 463 + lookup_tree(writer->repo, &entry.oid)) < 0) 464 464 return -1; 465 465 break; 466 466 case OBJ_BLOB: ··· 536 536 return -1; 537 537 bitmap_set(ent->bitmap, pos); 538 538 prio_queue_put(tree_queue, 539 - repo_get_commit_tree(the_repository, c)); 539 + repo_get_commit_tree(writer->repo, c)); 540 540 } 541 541 542 542 for (p = c->parents; p; p = p->next) { ··· 590 590 int closed = 1; /* until proven otherwise */ 591 591 592 592 if (writer->show_progress) 593 - writer->progress = start_progress(the_repository, 593 + writer->progress = start_progress(writer->repo, 594 594 "Building bitmaps", 595 595 writer->selected_nr); 596 596 trace2_region_enter("pack-bitmap-write", "building_bitmaps_total", 597 - the_repository); 597 + writer->repo); 598 598 599 599 old_bitmap = prepare_bitmap_git(writer->to_pack->repo); 600 600 if (old_bitmap) ··· 645 645 free(mapping); 646 646 647 647 trace2_region_leave("pack-bitmap-write", "building_bitmaps_total", 648 - the_repository); 649 - trace2_data_intmax("pack-bitmap-write", the_repository, 648 + writer->repo); 649 + trace2_data_intmax("pack-bitmap-write", writer->repo, 650 650 "building_bitmaps_reused", reused_bitmaps_nr); 651 - trace2_data_intmax("pack-bitmap-write", the_repository, 651 + trace2_data_intmax("pack-bitmap-write", writer->repo, 652 652 "building_bitmaps_pseudo_merge_reused", 653 653 reused_pseudo_merge_bitmaps_nr); 654 654 ··· 711 711 } 712 712 713 713 if (writer->show_progress) 714 - writer->progress = start_progress(the_repository, 714 + writer->progress = start_progress(writer->repo, 715 715 "Selecting bitmap commits", 0); 716 716 717 717 for (;;) { ··· 960 960 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) 961 961 table_inv[table[i]] = i; 962 962 963 - trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository); 963 + trace2_region_enter("pack-bitmap-write", "writing_lookup_table", writer->repo); 964 964 for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) { 965 965 struct bitmapped_commit *selected = &writer->selected[table[i]]; 966 966 uint32_t xor_offset = selected->xor_offset; ··· 987 987 hashwrite_be64(f, (uint64_t)offsets[table[i]]); 988 988 hashwrite_be32(f, xor_row); 989 989 } 990 - trace2_region_leave("pack-bitmap-write", "writing_lookup_table", the_repository); 990 + trace2_region_leave("pack-bitmap-write", "writing_lookup_table", writer->repo); 991 991 992 992 free(table); 993 993 free(table_inv); ··· 1008 1008 void bitmap_writer_set_checksum(struct bitmap_writer *writer, 1009 1009 const unsigned char *sha1) 1010 1010 { 1011 - hashcpy(writer->pack_checksum, sha1, the_repository->hash_algo); 1011 + hashcpy(writer->pack_checksum, sha1, writer->repo->hash_algo); 1012 1012 } 1013 1013 1014 1014 void bitmap_writer_finish(struct bitmap_writer *writer, ··· 1030 1030 if (writer->pseudo_merges_nr) 1031 1031 options |= BITMAP_OPT_PSEUDO_MERGES; 1032 1032 1033 - f = hashfd(the_repository->hash_algo, fd, tmp_file.buf); 1033 + f = hashfd(writer->repo->hash_algo, fd, tmp_file.buf); 1034 1034 1035 1035 memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)); 1036 1036 header.version = htons(default_version); 1037 1037 header.options = htons(flags | options); 1038 1038 header.entry_count = htonl(bitmap_writer_nr_selected_commits(writer)); 1039 - hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo); 1039 + hashcpy(header.checksum, writer->pack_checksum, writer->repo->hash_algo); 1040 1040 1041 - hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz); 1041 + hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + writer->repo->hash_algo->rawsz); 1042 1042 dump_bitmap(f, writer->commits); 1043 1043 dump_bitmap(f, writer->trees); 1044 1044 dump_bitmap(f, writer->blobs); ··· 1072 1072 finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, 1073 1073 CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); 1074 1074 1075 - if (adjust_shared_perm(the_repository, tmp_file.buf)) 1075 + if (adjust_shared_perm(writer->repo, tmp_file.buf)) 1076 1076 die_errno("unable to make temporary bitmap file readable"); 1077 1077 1078 1078 if (rename(tmp_file.buf, filename))
+1
pack-bitmap.h
··· 104 104 off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *); 105 105 106 106 struct bitmap_writer { 107 + struct repository *repo; 107 108 struct ewah_bitmap *commits; 108 109 struct ewah_bitmap *trees; 109 110 struct ewah_bitmap *blobs;