git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] pack-refs: use new ref_visible() helper

From
John Cai via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 21, 2023, 19:35 UTC
Message-ID
<144ad0b48a4e8491c4e2609458be653087ced804.1687376112.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1515.git.git.1687376112.gitgitgadget@gmail.com>
From: John Cai <johncai86@gmail.com>

replace the current logic in pack-refs that takes into account included refs with the new ref_visible() helper.

Signed-off-by: John Cai <johncai86@gmail.com>
---
 builtin/pack-refs.c       | 14 ++++++++------
 refs/files-backend.c      | 11 +----------
 t/helper/test-ref-store.c |  6 ++----
 3 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index ff07986edaf..5d6dc363085 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -15,17 +15,16 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
 {
 	unsigned int flags = PACK_REFS_PRUNE;
 	static struct ref_visibility visibility = REF_VISIBILITY_INIT;
-	static struct string_list included_refs = STRING_LIST_INIT_NODUP;
 	struct pack_refs_opts pack_refs_opts = { .visibility = &visibility,
-						 .includes = &included_refs,
 						 .flags = flags };
 	static struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
+	static struct string_list option_included_refs = STRING_LIST_INIT_NODUP;
 	struct string_list_item *item;
 
 	struct option opts[] = {
 		OPT_BIT(0, "all",   &pack_refs_opts.flags, N_("pack everything"), PACK_REFS_ALL),
 		OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
-		OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
+		OPT_STRING_LIST(0, "include", &option_included_refs, N_("pattern"),
 			N_("references to include")),
 		OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
 			N_("references to exclude")),
@@ -38,11 +37,14 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
 	for_each_string_list_item(item, &option_excluded_refs)
 		add_ref_exclusion(pack_refs_opts.visibility, item->string);
 
+	for_each_string_list_item(item, &option_included_refs)
+		add_ref_inclusion(pack_refs_opts.visibility, item->string);
+
 	if (pack_refs_opts.flags & PACK_REFS_ALL)
-		string_list_append(pack_refs_opts.includes, "*");
+		add_ref_inclusion(pack_refs_opts.visibility, "*");
 
-	if (!pack_refs_opts.includes->nr)
-		string_list_append(pack_refs_opts.includes, "refs/tags/*");
+	if (!option_included_refs.nr)
+		add_ref_inclusion(pack_refs_opts.visibility, "refs/tags/*");
 
 	return refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
 }
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 2e716a3e201..2dfe7f7e787 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1179,8 +1179,6 @@ static int should_pack_ref(const char *refname,
 			   const struct object_id *oid, unsigned int ref_flags,
 			   struct pack_refs_opts *opts)
 {
-	struct string_list_item *item;
-
 	/* Do not pack per-worktree refs: */
 	if (parse_worktree_ref(refname, NULL, NULL, NULL) !=
 	    REF_WORKTREE_SHARED)
@@ -1194,14 +1192,7 @@ static int should_pack_ref(const char *refname,
 	if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
 		return 0;
 
-	if (ref_excluded(opts->visibility, refname))
-		return 0;
-
-	for_each_string_list_item(item, opts->includes)
-		if (!wildmatch(item->string, refname, 0))
-			return 1;
-
-	return 0;
+	return ref_visible(opts->visibility, refname);
 }
 
 static int files_pack_refs(struct ref_store *ref_store,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 504935c1d84..81e0b5ea0a0 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -118,13 +118,11 @@ static int cmd_pack_refs(struct ref_store *refs, const char **argv)
 {
 	unsigned int flags = arg_flags(*argv++, "flags", pack_flags);
 	static struct ref_visibility visibility = REF_VISIBILITY_INIT;
-	static struct string_list included_refs = STRING_LIST_INIT_NODUP;
 	struct pack_refs_opts pack_opts = { .flags = flags,
-					    .visibility = &visibility,
-					    .includes = &included_refs };
+					    .visibility = &visibility };
 
 	if (pack_opts.flags & PACK_REFS_ALL)
-		string_list_append(pack_opts.includes, "*");
+		add_ref_inclusion(&visibility, "*");
 
 	return refs_pack_refs(refs, &pack_opts);
 }
-- 
gitgitgadget
Previous: Taylor BlauNext: Junio C Hamano
Message 5 of 13 in “revision: refactor ref_excludes to ref_visibility”
  1. 0/3 revision: refactor ref_excludes to ref_visibilityJohn Cai via GitGitGadget, Jun 21, 2023
  2. 2/3 revision: add ref_visible() helperJohn Cai via GitGitGadget, Jun 21, 2023
  3. 1/3 revision: rename ref_excludes to ref_visibilityJohn Cai via GitGitGadget, Jun 21, 2023
  4. Taylor BlauJun 22, 2023
  5. 3/3 pack-refs: use new ref_visible() helperJohn Cai via GitGitGadget, Jun 21, 2023
  6. Junio C HamanoJun 21, 2023
  7. Taylor BlauJun 22, 2023
  8. Taylor BlauJun 22, 2023
  9. Taylor BlauJun 22, 2023
  10. Taylor BlauJun 22, 2023
  11. Taylor BlauJun 22, 2023
  12. John CaiJun 23, 2023
  13. Junio C HamanoJun 23, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.