diff mbox series

[1/4] t/helper/test-bitmap.c: add 'dump-hashes' mode

Message ID 918f9b275a1a03b6383e32f28cf1db26a6d67633.1631049462.git.me@ttaylorr.com (mailing list archive)
State Superseded
Headers show
Series pack-bitmap: permute existing namehash values | expand

Commit Message

Taylor Blau Sept. 7, 2021, 9:17 p.m. UTC
The pack-bitmap writer code is about to learn how to propagate values
from an existing hash-cache. To prepare, teach the test-bitmap helper to
dump the values from a bitmap's hash-cache extension in order to test
those changes.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap.c          | 22 ++++++++++++++++++++++
 pack-bitmap.h          |  1 +
 t/helper/test-bitmap.c | 10 +++++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)

Comments

Ævar Arnfjörð Bjarmason Sept. 8, 2021, 1:37 a.m. UTC | #1
On Tue, Sep 07 2021, Taylor Blau wrote:

> +int test_bitmap_hashes(struct repository *r)
> +{
> +	struct bitmap_index *bitmap_git = prepare_bitmap_git(r);
> +	struct object_id oid;
> +	uint32_t i;
> +
> +	if (!bitmap_git->hashes)
> +		goto cleanup;
> +
> +	for (i = 0; i < bitmap_num_objects(bitmap_git); i++) {
> +		nth_bitmap_object_oid(bitmap_git, &oid, i);
> +
> +		printf("%s %"PRIu32"\n",
> +		       oid_to_hex(&oid), get_be32(bitmap_git->hashes + i));
> +	}
> +
> +cleanup:
> +	free_bitmap_index(bitmap_git);
> +
> +	return 0;
> +}

Seems like it should return void, it doesn't ever return non-0, nor in
the rest of this series....

> +static int bitmap_dump_hashes(void)
> +{
> +	return test_bitmap_hashes(the_repository);
> +}
> [...]
>  		return bitmap_list_commits();
> +	if (!strcmp(argv[1], "dump-hashes"))
> +		return bitmap_dump_hashes();

Perhaps the return code only for the brevity of this test-only code?
Seems like having bitmap_dump_hashes() do the "return 0" would be better
in that case.
Taylor Blau Sept. 8, 2021, 2:24 a.m. UTC | #2
On Wed, Sep 08, 2021 at 03:37:05AM +0200, Ævar Arnfjörð Bjarmason wrote:
> > +static int bitmap_dump_hashes(void)
> > +{
> > +	return test_bitmap_hashes(the_repository);
> > +}
> > [...]
> >  		return bitmap_list_commits();
> > +	if (!strcmp(argv[1], "dump-hashes"))
> > +		return bitmap_dump_hashes();
>
> Perhaps the return code only for the brevity of this test-only code?
> Seems like having bitmap_dump_hashes() do the "return 0" would be better
> in that case.

Yeah, it is silly to just return a constant from bitmap_dump_hashes
(and ditto for bitmap_list_commits), but it makes this easier to write.

I don't care either way. If you feel strongly, then please say so (but I
can't imagine that you do).

Thanks,
Taylor
diff mbox series

Patch

diff --git a/pack-bitmap.c b/pack-bitmap.c
index fa69ed7a6d..e44af36933 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1744,6 +1744,28 @@  int test_bitmap_commits(struct repository *r)
 	return 0;
 }
 
+int test_bitmap_hashes(struct repository *r)
+{
+	struct bitmap_index *bitmap_git = prepare_bitmap_git(r);
+	struct object_id oid;
+	uint32_t i;
+
+	if (!bitmap_git->hashes)
+		goto cleanup;
+
+	for (i = 0; i < bitmap_num_objects(bitmap_git); i++) {
+		nth_bitmap_object_oid(bitmap_git, &oid, i);
+
+		printf("%s %"PRIu32"\n",
+		       oid_to_hex(&oid), get_be32(bitmap_git->hashes + i));
+	}
+
+cleanup:
+	free_bitmap_index(bitmap_git);
+
+	return 0;
+}
+
 int rebuild_bitmap(const uint32_t *reposition,
 		   struct ewah_bitmap *source,
 		   struct bitmap *dest)
diff --git a/pack-bitmap.h b/pack-bitmap.h
index 81664f933f..b29514418c 100644
--- a/pack-bitmap.h
+++ b/pack-bitmap.h
@@ -53,6 +53,7 @@  void traverse_bitmap_commit_list(struct bitmap_index *,
 				 show_reachable_fn show_reachable);
 void test_bitmap_walk(struct rev_info *revs);
 int test_bitmap_commits(struct repository *r);
+int test_bitmap_hashes(struct repository *r);
 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
 					 struct list_objects_filter_options *filter,
 					 int filter_provided_objects);
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index 134a1e9d76..ff35f5999b 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -7,6 +7,11 @@  static int bitmap_list_commits(void)
 	return test_bitmap_commits(the_repository);
 }
 
+static int bitmap_dump_hashes(void)
+{
+	return test_bitmap_hashes(the_repository);
+}
+
 int cmd__bitmap(int argc, const char **argv)
 {
 	setup_git_directory();
@@ -16,9 +21,12 @@  int cmd__bitmap(int argc, const char **argv)
 
 	if (!strcmp(argv[1], "list-commits"))
 		return bitmap_list_commits();
+	if (!strcmp(argv[1], "dump-hashes"))
+		return bitmap_dump_hashes();
 
 usage:
-	usage("\ttest-tool bitmap list-commits");
+	usage("\ttest-tool bitmap list-commits\n"
+	      "\ttest-tool bitmap dump-hashes");
 
 	return -1;
 }