Skip to content

Commit f3c23db

Browse files
jonathantanmygitster
authored andcommitted
pack-bitmap: add free function
Add a function to free struct bitmap_index instances, and use it where needed (except when rebuild_existing_bitmaps() is used, since it creates references to the bitmaps within the struct bitmap_index passed to it). Note that the hashes field in struct bitmap_index is not freed because it points to another field within the same struct. The documentation for that field has been updated to clarify that. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3ae5fa0 commit f3c23db

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

builtin/pack-objects.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,6 +2945,7 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
29452945
}
29462946

29472947
traverse_bitmap_commit_list(bitmap_git, &add_object_entry_from_bitmap);
2948+
free_bitmap_index(bitmap_git);
29482949
return 0;
29492950
}
29502951

builtin/rev-list.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
521521
if (max_count >= 0 && max_count < commit_count)
522522
commit_count = max_count;
523523
printf("%d\n", commit_count);
524+
free_bitmap_index(bitmap_git);
524525
return 0;
525526
}
526527
} else if (revs.max_count < 0 &&
527528
revs.tag_objects && revs.tree_objects && revs.blob_objects) {
528529
struct bitmap_index *bitmap_git;
529530
if ((bitmap_git = prepare_bitmap_walk(&revs))) {
530531
traverse_bitmap_commit_list(bitmap_git, &show_object_fast);
532+
free_bitmap_index(bitmap_git);
531533
return 0;
532534
}
533535
}

pack-bitmap-write.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
367367
writer.reused = kh_init_sha1();
368368
rebuild_existing_bitmaps(bitmap_git, to_pack, writer.reused,
369369
writer.show_progress);
370+
/*
371+
* NEEDSWORK: rebuild_existing_bitmaps() makes writer.reused reference
372+
* some bitmaps in bitmap_git, so we can't free the latter.
373+
*/
370374
}
371375

372376
static struct ewah_bitmap *find_reused_bitmap(const unsigned char *sha1)

pack-bitmap.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct bitmap_index {
6666
/* Number of bitmapped commits */
6767
uint32_t entry_count;
6868

69-
/* Name-hash cache (or NULL if not present). */
69+
/* If not NULL, this is a name-hash cache pointing into map. */
7070
uint32_t *hashes;
7171

7272
/*
@@ -350,6 +350,7 @@ struct bitmap_index *prepare_bitmap_git(void)
350350
if (!open_pack_bitmap(bitmap_git) && !load_pack_bitmap(bitmap_git))
351351
return bitmap_git;
352352

353+
free_bitmap_index(bitmap_git);
353354
return NULL;
354355
}
355356

@@ -690,7 +691,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
690691
/* try to open a bitmapped pack, but don't parse it yet
691692
* because we may not need to use it */
692693
if (open_pack_bitmap(bitmap_git) < 0)
693-
return NULL;
694+
goto cleanup;
694695

695696
for (i = 0; i < revs->pending.nr; ++i) {
696697
struct object *object = revs->pending.objects[i].item;
@@ -723,19 +724,19 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
723724
* optimize here
724725
*/
725726
if (haves && !in_bitmapped_pack(bitmap_git, haves))
726-
return NULL;
727+
goto cleanup;
727728

728729
/* if we don't want anything, we're done here */
729730
if (!wants)
730-
return NULL;
731+
goto cleanup;
731732

732733
/*
733734
* now we're going to use bitmaps, so load the actual bitmap entries
734735
* from disk. this is the point of no return; after this the rev_list
735736
* becomes invalidated and we must perform the revwalk through bitmaps
736737
*/
737738
if (!bitmap_git->loaded && load_pack_bitmap(bitmap_git) < 0)
738-
return NULL;
739+
goto cleanup;
739740

740741
object_array_clear(&revs->pending);
741742

@@ -761,6 +762,10 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
761762

762763
bitmap_free(haves_bitmap);
763764
return bitmap_git;
765+
766+
cleanup:
767+
free_bitmap_index(bitmap_git);
768+
return NULL;
764769
}
765770

766771
int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
@@ -1001,7 +1006,7 @@ void test_bitmap_walk(struct rev_info *revs)
10011006
else
10021007
fprintf(stderr, "Mismatch!\n");
10031008

1004-
bitmap_free(result);
1009+
free_bitmap_index(bitmap_git);
10051010
}
10061011

10071012
static int rebuild_bitmap(uint32_t *reposition,
@@ -1093,3 +1098,21 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
10931098
bitmap_free(rebuild);
10941099
return 0;
10951100
}
1101+
1102+
void free_bitmap_index(struct bitmap_index *b)
1103+
{
1104+
if (!b)
1105+
return;
1106+
1107+
if (b->map)
1108+
munmap(b->map, b->map_size);
1109+
ewah_pool_free(b->commits);
1110+
ewah_pool_free(b->trees);
1111+
ewah_pool_free(b->blobs);
1112+
ewah_pool_free(b->tags);
1113+
kh_destroy_sha1(b->bitmaps);
1114+
free(b->ext_index.objects);
1115+
free(b->ext_index.hashes);
1116+
bitmap_free(b->result);
1117+
free(b);
1118+
}

pack-bitmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *,
4848
uint32_t *entries, off_t *up_to);
4949
int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
5050
khash_sha1 *reused_bitmaps, int show_progress);
51+
void free_bitmap_index(struct bitmap_index *);
5152

5253
void bitmap_writer_show_progress(int show);
5354
void bitmap_writer_set_checksum(unsigned char *sha1);

0 commit comments

Comments
 (0)