Skip to content

Commit b04d266

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap: remember pseudo-merge parents
write_pseudo_merges() currently builds an array of temporary bitmaps for the parent set of each pseudo-merge, then serializes those bitmaps later while writing the extension. Move those parent bitmaps onto the corresponding bitmapped_commit entries instead. This keeps the on-disk output unchanged, but gives the parent bitmap the same lifetime and access pattern that later changes will use when pseudo-merge object bitmaps are built before the write step. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent dcccd99 commit b04d266

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

pack-bitmap-write.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct bitmapped_commit {
3232
struct commit *commit;
3333
struct ewah_bitmap *bitmap;
3434
struct ewah_bitmap *write_as;
35+
struct ewah_bitmap *pseudo_merge_parents;
3536
int flags;
3637
int xor_offset;
3738
uint32_t commit_pos;
@@ -102,6 +103,7 @@ void bitmap_writer_free(struct bitmap_writer *writer)
102103
if (bc->write_as != bc->bitmap)
103104
ewah_free(bc->write_as);
104105
ewah_free(bc->bitmap);
106+
ewah_free(bc->pseudo_merge_parents);
105107
}
106108
free(writer->selected);
107109
}
@@ -210,6 +212,7 @@ void bitmap_writer_push_commit(struct bitmap_writer *writer,
210212
writer->selected[writer->selected_nr].write_as = NULL;
211213
writer->selected[writer->selected_nr].flags = 0;
212214
writer->selected[writer->selected_nr].pseudo_merge = pseudo_merge;
215+
writer->selected[writer->selected_nr].pseudo_merge_parents = NULL;
213216

214217
writer->selected_nr++;
215218
}
@@ -1004,42 +1007,47 @@ static void write_pseudo_merges(struct bitmap_writer *writer,
10041007
struct hashfile *f)
10051008
{
10061009
struct oid_array commits = OID_ARRAY_INIT;
1007-
struct bitmap **commits_bitmap = NULL;
10081010
off_t *pseudo_merge_ofs = NULL;
10091011
off_t start, table_start, next_ext;
10101012

10111013
uint32_t base = bitmap_writer_nr_selected_commits(writer);
10121014
size_t i, j = 0;
10131015

1014-
CALLOC_ARRAY(commits_bitmap, writer->pseudo_merges_nr);
10151016
CALLOC_ARRAY(pseudo_merge_ofs, writer->pseudo_merges_nr);
10161017

10171018
for (i = 0; i < writer->pseudo_merges_nr; i++) {
10181019
struct bitmapped_commit *merge = &writer->selected[base + i];
10191020
struct commit_list *p;
1021+
struct bitmap *parents = bitmap_new();
10201022

10211023
if (!merge->pseudo_merge)
10221024
BUG("found non-pseudo merge commit at %"PRIuMAX, (uintmax_t)i);
10231025

1024-
commits_bitmap[i] = bitmap_new();
1025-
10261026
for (p = merge->commit->parents; p; p = p->next)
1027-
bitmap_set(commits_bitmap[i],
1027+
bitmap_set(parents,
10281028
find_object_pos(writer, &p->item->object.oid,
10291029
NULL));
1030+
1031+
merge->pseudo_merge_parents = bitmap_to_ewah(parents);
1032+
bitmap_free(parents);
10301033
}
10311034

10321035
start = hashfile_total(f);
10331036

10341037
for (i = 0; i < writer->pseudo_merges_nr; i++) {
1035-
struct ewah_bitmap *commits_ewah = bitmap_to_ewah(commits_bitmap[i]);
1038+
struct bitmapped_commit *merge = &writer->selected[base + i];
1039+
1040+
if (!merge->pseudo_merge)
1041+
BUG("found non-pseudo merge commit at %"PRIuMAX, (uintmax_t)i);
1042+
1043+
if (!merge->pseudo_merge_parents)
1044+
BUG("missing pseudo-merge parents bitmap for commit %s",
1045+
oid_to_hex(&merge->commit->object.oid));
10361046

10371047
pseudo_merge_ofs[i] = hashfile_total(f);
10381048

1039-
dump_bitmap(f, commits_ewah);
1049+
dump_bitmap(f, merge->pseudo_merge_parents);
10401050
dump_bitmap(f, writer->selected[base+i].write_as);
1041-
1042-
ewah_free(commits_ewah);
10431051
}
10441052

10451053
next_ext = st_add(hashfile_total(f),
@@ -1122,12 +1130,8 @@ static void write_pseudo_merges(struct bitmap_writer *writer,
11221130
hashwrite_be64(f, table_start - start);
11231131
hashwrite_be64(f, hashfile_total(f) - start + sizeof(uint64_t));
11241132

1125-
for (i = 0; i < writer->pseudo_merges_nr; i++)
1126-
bitmap_free(commits_bitmap[i]);
1127-
11281133
oid_array_clear(&commits);
11291134
free(pseudo_merge_ofs);
1130-
free(commits_bitmap);
11311135
}
11321136

11331137
static int table_cmp(const void *_va, const void *_vb, void *_data)

0 commit comments

Comments
 (0)