]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-bitmap.c: introduce 'bitmap_is_preferred_refname()'
authorTaylor Blau <me@ttaylorr.com>
Tue, 31 Aug 2021 20:52:16 +0000 (16:52 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Sep 2021 20:56:43 +0000 (13:56 -0700)
In a recent commit, pack-objects learned support for the
'pack.preferBitmapTips' configuration. This patch prepares the
multi-pack bitmap code to respect this configuration, too.

The yet-to-be implemented code will find that it is more efficient to
check whether each reference contains a prefix found in the configured
set of values rather than doing an additional traversal.

Implement a function 'bitmap_is_preferred_refname()' which will perform
that check. Its caller will be added in a subsequent patch.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-bitmap.c
pack-bitmap.h

index 612f62da97ea26e5f9c36b5d61537917a240acc0..d5296750eb0762fa40b79fc8001a86c68a35459f 100644 (file)
@@ -1658,3 +1658,19 @@ const struct string_list *bitmap_preferred_tips(struct repository *r)
 {
        return repo_config_get_value_multi(r, "pack.preferbitmaptips");
 }
+
+int bitmap_is_preferred_refname(struct repository *r, const char *refname)
+{
+       const struct string_list *preferred_tips = bitmap_preferred_tips(r);
+       struct string_list_item *item;
+
+       if (!preferred_tips)
+               return 0;
+
+       for_each_string_list_item(item, preferred_tips) {
+               if (starts_with(refname, item->string))
+                       return 1;
+       }
+
+       return 0;
+}
index 020cd8d868f9d327b99bc62c801b2c2ee432f67e..52ea10de5117ab9228f79be743ce3e89457885c0 100644 (file)
@@ -94,5 +94,6 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
                          uint16_t options);
 
 const struct string_list *bitmap_preferred_tips(struct repository *r);
+int bitmap_is_preferred_refname(struct repository *r, const char *refname);
 
 #endif