Skip to content

Commit

Permalink
pack-bitmap: add free function
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jonathantanmy authored and gitster committed Jun 21, 2018
1 parent 3ae5fa0 commit f3c23db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -2945,6 +2945,7 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
}

traverse_bitmap_commit_list(bitmap_git, &add_object_entry_from_bitmap);
free_bitmap_index(bitmap_git);
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
if (max_count >= 0 && max_count < commit_count)
commit_count = max_count;
printf("%d\n", commit_count);
free_bitmap_index(bitmap_git);
return 0;
}
} else if (revs.max_count < 0 &&
revs.tag_objects && revs.tree_objects && revs.blob_objects) {
struct bitmap_index *bitmap_git;
if ((bitmap_git = prepare_bitmap_walk(&revs))) {
traverse_bitmap_commit_list(bitmap_git, &show_object_fast);
free_bitmap_index(bitmap_git);
return 0;
}
}
Expand Down
4 changes: 4 additions & 0 deletions pack-bitmap-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack)
writer.reused = kh_init_sha1();
rebuild_existing_bitmaps(bitmap_git, to_pack, writer.reused,
writer.show_progress);
/*
* NEEDSWORK: rebuild_existing_bitmaps() makes writer.reused reference
* some bitmaps in bitmap_git, so we can't free the latter.
*/
}

static struct ewah_bitmap *find_reused_bitmap(const unsigned char *sha1)
Expand Down
35 changes: 29 additions & 6 deletions pack-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct bitmap_index {
/* Number of bitmapped commits */
uint32_t entry_count;

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

/*
Expand Down Expand Up @@ -350,6 +350,7 @@ struct bitmap_index *prepare_bitmap_git(void)
if (!open_pack_bitmap(bitmap_git) && !load_pack_bitmap(bitmap_git))
return bitmap_git;

free_bitmap_index(bitmap_git);
return NULL;
}

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

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

/* if we don't want anything, we're done here */
if (!wants)
return NULL;
goto cleanup;

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

object_array_clear(&revs->pending);

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

bitmap_free(haves_bitmap);
return bitmap_git;

cleanup:
free_bitmap_index(bitmap_git);
return NULL;
}

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

bitmap_free(result);
free_bitmap_index(bitmap_git);
}

static int rebuild_bitmap(uint32_t *reposition,
Expand Down Expand Up @@ -1093,3 +1098,21 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
bitmap_free(rebuild);
return 0;
}

void free_bitmap_index(struct bitmap_index *b)
{
if (!b)
return;

if (b->map)
munmap(b->map, b->map_size);
ewah_pool_free(b->commits);
ewah_pool_free(b->trees);
ewah_pool_free(b->blobs);
ewah_pool_free(b->tags);
kh_destroy_sha1(b->bitmaps);
free(b->ext_index.objects);
free(b->ext_index.hashes);
bitmap_free(b->result);
free(b);
}
1 change: 1 addition & 0 deletions pack-bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *,
uint32_t *entries, off_t *up_to);
int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
khash_sha1 *reused_bitmaps, int show_progress);
void free_bitmap_index(struct bitmap_index *);

void bitmap_writer_show_progress(int show);
void bitmap_writer_set_checksum(unsigned char *sha1);
Expand Down

0 comments on commit f3c23db

Please sign in to comment.