diff mbox series

[2/3] pack-bitmap.c: extract `fill_in_bitmap()`

Message ID 7624d3b5ba0415588a924aad2b855088e3d2028b.1682380788.git.me@ttaylorr.com (mailing list archive)
State Superseded
Headers show
Series pack-bitmap: boundary-based bitmap traversal | expand

Commit Message

Taylor Blau April 25, 2023, midnight UTC
To prepare for the boundary-based bitmap walk to perform a fill-in
traversal using the boundary of either side as the tips, extract routine
used to perform fill-in traversal by `find_objects()` so that it can be
used in both places.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap.c | 66 +++++++++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 29 deletions(-)

Comments

Junio C Hamano April 25, 2023, 6:32 p.m. UTC | #1
Taylor Blau <me@ttaylorr.com> writes:

> To prepare for the boundary-based bitmap walk to perform a fill-in
> traversal using the boundary of either side as the tips, extract routine
> used to perform fill-in traversal by `find_objects()` so that it can be
> used in both places.

What is done is not a literal "extract", though.  Worth mentioning here?

> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  pack-bitmap.c | 66 +++++++++++++++++++++++++++++----------------------
>  1 file changed, 37 insertions(+), 29 deletions(-)
>
> +	if (base == NULL)
> +		base = bitmap_new();

Style?

> +	incdata.bitmap_git = bitmap_git;
> +	incdata.base = base;
> +	incdata.seen = seen;
> +
> +	revs->include_check = should_include;
> +	revs->include_check_obj = should_include_obj;
> +	revs->include_check_data = &incdata;
> +
> +	if (prepare_revision_walk(revs))
> +		die("revision walk setup failed");
> +
> +	show_data.bitmap_git = bitmap_git;
> +	show_data.base = base;
> +
> +	traverse_commit_list_filtered(revs, show_commit, show_object,
> +				      &show_data, NULL);

The original uses the variant without "_filtered" suffix.  In a
later update when the second caller is added, the new caller may
need to extend it, but shouldn't that wait until that step?

Thanks.
Taylor Blau April 25, 2023, 6:51 p.m. UTC | #2
On Tue, Apr 25, 2023 at 11:32:25AM -0700, Junio C Hamano wrote:
> Taylor Blau <me@ttaylorr.com> writes:
>
> > To prepare for the boundary-based bitmap walk to perform a fill-in
> > traversal using the boundary of either side as the tips, extract routine
> > used to perform fill-in traversal by `find_objects()` so that it can be
> > used in both places.
>
> What is done is not a literal "extract", though.  Worth mentioning here?

Oops. It is supposed to be a literal extraction, but this patch was
originally written before 3e0370a8d2 (list-objects: consolidate
traverse_commit_list[_filtered], 2022-03-09).

> > ---
> >  pack-bitmap.c | 66 +++++++++++++++++++++++++++++----------------------
> >  1 file changed, 37 insertions(+), 29 deletions(-)
> >
> > +	if (base == NULL)
> > +		base = bitmap_new();
>
> Style?

...It was also written before afe8a9070b (tree-wide: apply
equals-null.cocci, 2022-05-02), which is where this "if (base == NULL)"
thing comes from. I fixed both to be a clean extraction with no
functional changes.

Thanks,
Taylor
diff mbox series

Patch

diff --git a/pack-bitmap.c b/pack-bitmap.c
index b2e7d06d60..046240d072 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1040,6 +1040,41 @@  static int add_commit_to_bitmap(struct bitmap_index *bitmap_git,
 	return 1;
 }
 
+static struct bitmap *fill_in_bitmap(struct bitmap_index *bitmap_git,
+				     struct rev_info *revs,
+				     struct bitmap *base,
+				     struct bitmap *seen)
+{
+	struct include_data incdata;
+	struct bitmap_show_data show_data;
+
+	if (base == NULL)
+		base = bitmap_new();
+
+	incdata.bitmap_git = bitmap_git;
+	incdata.base = base;
+	incdata.seen = seen;
+
+	revs->include_check = should_include;
+	revs->include_check_obj = should_include_obj;
+	revs->include_check_data = &incdata;
+
+	if (prepare_revision_walk(revs))
+		die("revision walk setup failed");
+
+	show_data.bitmap_git = bitmap_git;
+	show_data.base = base;
+
+	traverse_commit_list_filtered(revs, show_commit, show_object,
+				      &show_data, NULL);
+
+	revs->include_check = NULL;
+	revs->include_check_obj = NULL;
+	revs->include_check_data = NULL;
+
+	return base;
+}
+
 static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
 				   struct rev_info *revs,
 				   struct object_list *roots,
@@ -1105,35 +1140,8 @@  static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
 		}
 	}
 
-	if (needs_walk) {
-		struct include_data incdata;
-		struct bitmap_show_data show_data;
-
-		if (!base)
-			base = bitmap_new();
-
-		incdata.bitmap_git = bitmap_git;
-		incdata.base = base;
-		incdata.seen = seen;
-
-		revs->include_check = should_include;
-		revs->include_check_obj = should_include_obj;
-		revs->include_check_data = &incdata;
-
-		if (prepare_revision_walk(revs))
-			die(_("revision walk setup failed"));
-
-		show_data.bitmap_git = bitmap_git;
-		show_data.base = base;
-
-		traverse_commit_list(revs,
-				     show_commit, show_object,
-				     &show_data);
-
-		revs->include_check = NULL;
-		revs->include_check_obj = NULL;
-		revs->include_check_data = NULL;
-	}
+	if (needs_walk)
+		base = fill_in_bitmap(bitmap_git, revs, base, seen);
 
 	return base;
 }