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

[PATCH v3 3/5] refactor(remote): rename query_refspecs functions

From
Meet Soni <meetsoni3017@gmail.com>
Date
Feb 1, 2025, 06:42 UTC
Message-ID
<20250201064202.76116-4-meetsoni3017@gmail.com>
In-Reply-To
<20250201064202.76116-1-meetsoni3017@gmail.com>

Rename `query_refspecs()` to `find_refspec_match` for clarity, as it finds a single matching refspec.

Rename `query_refspecs_multiple()` to `find_all_refspec_matches` to better reflect that it collects all matching refspecs instead of returning just the first match.

Rename `query_matches_negative_refspec()` to `find_negative_refspec_match` for consistency with the updated naming convention.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
---
 builtin/push.c |  2 +-
 remote.c       | 20 ++++++++++----------
 remote.h       |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/builtin/push.c b/builtin/push.c
index 90de3746b5..e6527b0b04 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -78,7 +78,7 @@ static void refspec_append_mapped(struct refspec *refspec, const char *ref,
 			.src = matched->name,
 		};
 
-		if (!query_refspecs(&remote->push, &query) && query.dst) {
+		if (!find_refspec_match(&remote->push, &query) && query.dst) {
 			refspec_appendf(refspec, "%s%s:%s",
 					query.force ? "+" : "",
 					query.src, query.dst);
diff --git a/remote.c b/remote.c
index 1da8ec7037..4654bce5d4 100644
--- a/remote.c
+++ b/remote.c
@@ -925,7 +925,7 @@ struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs)
 	return ref_map;
 }
 
-static int query_matches_negative_refspec(struct refspec *rs, struct refspec_item *query)
+static int find_negative_refspec_match(struct refspec *rs, struct refspec_item *query)
 {
 	int i, matched_negative = 0;
 	int find_src = !query->src;
@@ -982,7 +982,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
 	return matched_negative;
 }
 
-static void query_refspecs_multiple(struct refspec *rs,
+static void find_all_refspec_matches(struct refspec *rs,
 				    struct refspec_item *query,
 				    struct string_list *results)
 {
@@ -990,9 +990,9 @@ static void query_refspecs_multiple(struct refspec *rs,
 	int find_src = !query->src;
 
 	if (find_src && !query->dst)
-		BUG("query_refspecs_multiple: need either src or dst");
+		BUG("find_all_refspec_matches: need either src or dst");
 
-	if (query_matches_negative_refspec(rs, query))
+	if (find_negative_refspec_match(rs, query))
 		return;
 
 	for (i = 0; i < rs->nr; i++) {
@@ -1013,7 +1013,7 @@ static void query_refspecs_multiple(struct refspec *rs,
 	}
 }
 
-int query_refspecs(struct refspec *rs, struct refspec_item *query)
+int find_refspec_match(struct refspec *rs, struct refspec_item *query)
 {
 	int i;
 	int find_src = !query->src;
@@ -1021,9 +1021,9 @@ int query_refspecs(struct refspec *rs, struct refspec_item *query)
 	char **result = find_src ? &query->src : &query->dst;
 
 	if (find_src && !query->dst)
-		BUG("query_refspecs: need either src or dst");
+		BUG("find_refspec_match: need either src or dst");
 
-	if (query_matches_negative_refspec(rs, query))
+	if (find_negative_refspec_match(rs, query))
 		return -1;
 
 	for (i = 0; i < rs->nr; i++) {
@@ -1054,7 +1054,7 @@ char *apply_refspecs(struct refspec *rs, const char *name)
 	memset(&query, 0, sizeof(struct refspec_item));
 	query.src = (char *)name;
 
-	if (query_refspecs(rs, &query))
+	if (find_refspec_match(rs, &query))
 		return NULL;
 
 	return query.dst;
@@ -1062,7 +1062,7 @@ char *apply_refspecs(struct refspec *rs, const char *name)
 
 int remote_find_tracking(struct remote *remote, struct refspec_item *refspec)
 {
-	return query_refspecs(&remote->fetch, refspec);
+	return find_refspec_match(&remote->fetch, refspec);
 }
 
 static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
@@ -2487,7 +2487,7 @@ static int get_stale_heads_cb(const char *refname, const char *referent UNUSED,
 	memset(&query, 0, sizeof(struct refspec_item));
 	query.dst = (char *)refname;
 
-	query_refspecs_multiple(info->rs, &query, &matches);
+	find_all_refspec_matches(info->rs, &query, &matches);
 	if (matches.nr == 0)
 		goto clean_exit; /* No matches */
 
diff --git a/remote.h b/remote.h
index 66ee53411d..f109310eda 100644
--- a/remote.h
+++ b/remote.h
@@ -269,7 +269,7 @@ int refname_matches_negative_refspec_item(const char *refname, struct refspec *r
  */
 struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs);
 
-int query_refspecs(struct refspec *rs, struct refspec_item *query);
+int find_refspec_match(struct refspec *rs, struct refspec_item *query);
 char *apply_refspecs(struct refspec *rs, const char *name);
 
 int check_push_refs(struct ref *src, struct refspec *rs);
-- 
2.34.1
Previous: Meet SoniNext: Patrick Steinhardt
Message 18 of 33 in “refspec: centralize refspec-related logic”
  1. 0/3 refspec: centralize refspec-related logicMeet Soni, Jan 27, 2025
  2. 1/3 refspec: relocate omit_name_by_refspec and related functionsMeet Soni, Jan 27, 2025
  3. Junio C HamanoJan 27, 2025
  4. Meet SoniJan 29, 2025
  5. 2/3 refspec: relocate query related functionsMeet Soni, Jan 27, 2025
  6. Junio C HamanoJan 27, 2025
  7. Meet SoniJan 29, 2025
  8. 3/3 refspec: relocate apply_refspecs and related funtionsMeet Soni, Jan 27, 2025
  9. Junio C HamanoJan 27, 2025
  10. Meet SoniJan 29, 2025
  11. Meet SoniJan 27, 2025
  12. Junio C HamanoJan 27, 2025
  13. Meet SoniJan 29, 2025
  14. 0/5 refspec: centralize refspec-related logicMeet Soni, Feb 1, 2025
  15. 1/5 refactor(remote): rename function omit_name_by_refspecMeet Soni, Feb 1, 2025
  16. Patrick SteinhardtFeb 3, 2025
  17. 2/5 refspec: relocate refname_matches_negative_refspec_itemMeet Soni, Feb 1, 2025
  18. 3/5 refactor(remote): rename query_refspecs functionsMeet Soni, Feb 1, 2025
  19. Patrick SteinhardtFeb 3, 2025
  20. Meet SoniFeb 4, 2025
  21. Junio C HamanoFeb 4, 2025
  22. 4/5 refspec: relocate matching related functionsMeet Soni, Feb 1, 2025
  23. 5/5 refspec: relocate apply_refspecs and related funtionsMeet Soni, Feb 1, 2025
  24. [GSoC][PATCH v4 0/5] refspec: centralize refspec-related logicMeet Soni, Feb 4, 2025
  25. [GSoC][PATCH v4 1/5] remote: rename function omit_name_by_refspecMeet Soni, Feb 4, 2025
  26. Karthik NayakFeb 4, 2025
  27. Meet SoniFeb 4, 2025
  28. Karthik NayakFeb 6, 2025
  29. [GSoC][PATCH v4 2/5] refspec: relocate refname_matches_negative_refspec_itemMeet Soni, Feb 4, 2025
  30. [GSoC][PATCH v4 3/5] remote: rename query_refspecs functionsMeet Soni, Feb 4, 2025
  31. [GSoC][PATCH v4 4/5] refspec: relocate matching related functionsMeet Soni, Feb 4, 2025
  32. [GSoC][PATCH v4 5/5] refspec: relocate apply_refspecs and related funtionsMeet Soni, Feb 4, 2025
  33. Patrick SteinhardtFeb 4, 2025

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.