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

[PATCH v4 16/26] refs.c: move ref iterators to the common code

From
David Turner <dturner@twopensource.com>
Date
Oct 15, 2015, 19:46 UTC
Message-ID
<1444938410-2345-17-git-send-email-dturner@twopensource.com>
In-Reply-To
<1444938410-2345-1-git-send-email-dturner@twopensource.com>
From: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 refs-be-files.c | 82 ---------------------------------------------------------
 refs.c          | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 82 deletions(-)
diff --git a/refs-be-files.c b/refs-be-files.c
index c8b44ab..14319cb 100644
--- a/refs-be-files.c
+++ b/refs-be-files.c
@@ -1668,23 +1668,6 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
 	return ret;
 }
 
-/* The argument to filter_refs */
-struct ref_filter {
-	const char *pattern;
-	each_ref_fn *fn;
-	void *cb_data;
-};
-
-static int filter_refs(const char *refname, const struct object_id *oid,
-			   int flags, void *data)
-{
-	struct ref_filter *filter = (struct ref_filter *)data;
-
-	if (wildmatch(filter->pattern, refname, 0, NULL))
-		return 0;
-	return filter->fn(refname, oid, flags, filter->cb_data);
-}
-
 enum peel_status {
 	/* object was peeled successfully: */
 	PEEL_PEELED = 0,
@@ -1950,37 +1933,6 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
 {
 	return do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);
 }
-
-int for_each_tag_ref(each_ref_fn fn, void *cb_data)
-{
-	return for_each_ref_in("refs/tags/", fn, cb_data);
-}
-
-int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
-{
-	return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data);
-}
-
-int for_each_branch_ref(each_ref_fn fn, void *cb_data)
-{
-	return for_each_ref_in("refs/heads/", fn, cb_data);
-}
-
-int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
-{
-	return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data);
-}
-
-int for_each_remote_ref(each_ref_fn fn, void *cb_data)
-{
-	return for_each_ref_in("refs/remotes/", fn, cb_data);
-}
-
-int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
-{
-	return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data);
-}
-
 int for_each_replace_ref(each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref(&ref_cache, git_replace_ref_base, fn,
@@ -2012,40 +1964,6 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
 	return ret;
 }
 
-int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
-	const char *prefix, void *cb_data)
-{
-	struct strbuf real_pattern = STRBUF_INIT;
-	struct ref_filter filter;
-	int ret;
-
-	if (!prefix && !starts_with(pattern, "refs/"))
-		strbuf_addstr(&real_pattern, "refs/");
-	else if (prefix)
-		strbuf_addstr(&real_pattern, prefix);
-	strbuf_addstr(&real_pattern, pattern);
-
-	if (!has_glob_specials(pattern)) {
-		/* Append implied '/' '*' if not present. */
-		strbuf_complete(&real_pattern, '/');
-		/* No need to check for '*', there is none. */
-		strbuf_addch(&real_pattern, '*');
-	}
-
-	filter.pattern = real_pattern.buf;
-	filter.fn = fn;
-	filter.cb_data = cb_data;
-	ret = for_each_ref(filter_refs, &filter);
-
-	strbuf_release(&real_pattern);
-	return ret;
-}
-
-int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
-{
-	return for_each_glob_ref_in(fn, pattern, NULL, cb_data);
-}
-
 int for_each_rawref(each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref(&ref_cache, "", fn, 0,
diff --git a/refs.c b/refs.c
index 642a2ab..f7aa9b3 100644
--- a/refs.c
+++ b/refs.c
@@ -746,3 +746,84 @@ const char *prettify_refname(const char *name)
 		starts_with(name, "refs/remotes/") ? 13 :
 		0);
 }
+
+/* The argument to filter_refs */
+struct ref_filter {
+	const char *pattern;
+	each_ref_fn *fn;
+	void *cb_data;
+};
+
+static int filter_refs(const char *refname, const struct object_id *oid, int flags,
+		       void *data)
+{
+	struct ref_filter *filter = (struct ref_filter *)data;
+
+	if (wildmatch(filter->pattern, refname, 0, NULL))
+		return 0;
+	return filter->fn(refname, oid, flags, filter->cb_data);
+}
+
+int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
+	const char *prefix, void *cb_data)
+{
+	struct strbuf real_pattern = STRBUF_INIT;
+	struct ref_filter filter;
+	int ret;
+
+	if (!prefix && !starts_with(pattern, "refs/"))
+		strbuf_addstr(&real_pattern, "refs/");
+	else if (prefix)
+		strbuf_addstr(&real_pattern, prefix);
+	strbuf_addstr(&real_pattern, pattern);
+
+	if (!has_glob_specials(pattern)) {
+		/* Append implied '/' '*' if not present. */
+		strbuf_complete(&real_pattern, '/');
+		/* No need to check for '*', there is none. */
+		strbuf_addch(&real_pattern, '*');
+	}
+
+	filter.pattern = real_pattern.buf;
+	filter.fn = fn;
+	filter.cb_data = cb_data;
+	ret = for_each_ref(filter_refs, &filter);
+
+	strbuf_release(&real_pattern);
+	return ret;
+}
+
+int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
+{
+	return for_each_glob_ref_in(fn, pattern, NULL, cb_data);
+}
+
+int for_each_tag_ref(each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in("refs/tags/", fn, cb_data);
+}
+
+int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data);
+}
+
+int for_each_branch_ref(each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in("refs/heads/", fn, cb_data);
+}
+
+int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data);
+}
+
+int for_each_remote_ref(each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in("refs/remotes/", fn, cb_data);
+}
+
+int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data);
+}
-- 
2.4.2.644.g97b850b-twtrsrc
Previous: David TurnerNext: David Turner
Message 22 of 35 in “refs backend pre-vtable patches”
  1. 00/26 refs backend pre-vtable patchesDavid Turner, Oct 15, 2015
  2. 01/26 refs.c: create a public version of verify_refname_availableDavid Turner, Oct 15, 2015
  3. 02/26 refs: make repack_without_refs and is_branch publicDavid Turner, Oct 15, 2015
  4. Michael HaggertyOct 16, 2015
  5. David TurnerOct 19, 2015
  6. 03/26 refs-be-files.c: rename refs to refs-be-filesDavid Turner, Oct 15, 2015
  7. Michael HaggertyOct 16, 2015
  8. 04/26 refs.c: add a new refs.c file to hold all common refs codeDavid Turner, Oct 15, 2015
  9. 05/26 refs.c: move update_ref to refs.cDavid Turner, Oct 15, 2015
  10. David TurnerOct 21, 2015
  11. 06/26 refs.c: move delete_pseudoref and delete_ref to the common codeDavid Turner, Oct 15, 2015
  12. David TurnerOct 21, 2015
  13. 07/26 refs.c: move read_ref_at to the common refs fileDavid Turner, Oct 15, 2015
  14. 08/26 refs.c: move the hidden refs functions to the common codeDavid Turner, Oct 15, 2015
  15. 09/26 refs.c: move dwim and friend functions to the common refs codeDavid Turner, Oct 15, 2015
  16. 10/26 refs.c: move warn_if_dangling_symref* to the common codeDavid Turner, Oct 15, 2015
  17. 11/26 refs.c: move read_ref, read_ref_full and ref_exists to the common codeDavid Turner, Oct 15, 2015
  18. 12/26 refs.c: move resolve_refdup to commonDavid Turner, Oct 15, 2015
  19. 13/26 refs.c: move check_refname_format to the common codeDavid Turner, Oct 15, 2015
  20. 14/26 refs.c: move is_branch to the common codeDavid Turner, Oct 15, 2015
  21. 15/26 refs.c: move prettify_refname to the common codeDavid Turner, Oct 15, 2015
  22. 16/26 refs.c: move ref iterators to the common codeDavid Turner, Oct 15, 2015
  23. 17/26 refs.c: move head_ref_namespaced to the common codeDavid Turner, Oct 15, 2015
  24. 18/26 refs: move transaction functions into common codeDavid Turner, Oct 15, 2015
  25. 19/26 refs.c: move refname_is_safe to the common codeDavid Turner, Oct 15, 2015
  26. 20/26 refs.c: move copy_msg to the common codeDavid Turner, Oct 15, 2015
  27. 21/26 refs.c: move peel_object to the common codeDavid Turner, Oct 15, 2015
  28. 22/26 refs.c: move should_autocreate_reflog to common codeDavid Turner, Oct 15, 2015
  29. 23/26 initdb: move safe_create_dir into common codeDavid Turner, Oct 15, 2015
  30. Junio C HamanoOct 21, 2015
  31. David TurnerOct 21, 2015
  32. 24/26 refs: make files_log_ref_write functions publicDavid Turner, Oct 15, 2015
  33. 25/26 refs: break out ref conflict checksDavid Turner, Oct 15, 2015
  34. 26/26 introduce "extensions" form of core.repositoryformatversionDavid Turner, Oct 15, 2015
  35. Junio C HamanoOct 21, 2015

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.