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

[RFC 01/11] get_stale_heads(): allow limiting to refname patterns

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 4, 2013, 05:44 UTC
Message-ID
<1386135890-13954-2-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1386135890-13954-1-git-send-email-mhagger@alum.mit.edu>

Add a "patterns" argument to get_stale_heads(). If it is non-NULL, then only refnames matching one of the glob patterns in the string list will be included in the output.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/fetch.c  |  3 ++-
 builtin/remote.c |  3 ++-
 remote.c         | 26 ++++++++++++++++++++++++--
 remote.h         |  9 +++++++--
 4 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 3d978eb..9a04512 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -711,7 +711,8 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
 static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
 {
 	int result = 0;
-	struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
+	struct ref *stale_refs = get_stale_heads(refs, ref_count, ref_map, NULL);
+	struct ref *ref;
 	const char *dangling_msg = dry_run
 		? _("   (%s will become dangling)")
 		: _("   (%s has become dangling)");
diff --git a/builtin/remote.c b/builtin/remote.c
index f532f35..c08dfa8 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -347,7 +347,8 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
 			string_list_append(&states->tracked, abbrev_branch(ref->name));
 	}
 	stale_refs = get_stale_heads(states->remote->fetch,
-				     states->remote->fetch_refspec_nr, fetch_map);
+				     states->remote->fetch_refspec_nr,
+				     fetch_map, NULL);
 	for (ref = stale_refs; ref; ref = ref->next) {
 		struct string_list_item *item =
 			string_list_append(&states->stale, abbrev_branch(ref->name));
diff --git a/remote.c b/remote.c
index dc56619..075ed71 100644
--- a/remote.c
+++ b/remote.c
@@ -1986,13 +1986,31 @@ struct stale_heads_info {
 	struct ref **stale_refs_tail;
 	struct refspec *refs;
 	int ref_count;
+	struct string_list *patterns;
 };
 
 static int get_stale_heads_cb(const char *refname,
-	const unsigned char *sha1, int flags, void *cb_data)
+			      const unsigned char *sha1, int flags,
+			      void *cb_data)
 {
 	struct stale_heads_info *info = cb_data;
 	struct refspec query;
+	struct string_list *patterns = info->patterns;
+
+	if (patterns) {
+		int refname_matches = 0;
+		struct string_list_item *item;
+
+		for_each_string_list_item(item, patterns) {
+			if (!fnmatch(item->string, refname, 0)) {
+				refname_matches = 1;
+				break;
+			}
+		}
+		if (!refname_matches)
+			return 0;
+	}
+
 	memset(&query, 0, sizeof(struct refspec));
 	query.dst = (char *)refname;
 
@@ -2014,15 +2032,19 @@ static int get_stale_heads_cb(const char *refname,
 	return 0;
 }
 
-struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fetch_map)
+struct ref *get_stale_heads(struct refspec *refs, int ref_count,
+			    struct ref *fetch_map,
+			    struct string_list *patterns)
 {
 	struct ref *ref, *stale_refs = NULL;
 	struct string_list ref_names = STRING_LIST_INIT_NODUP;
 	struct stale_heads_info info;
+
 	info.ref_names = &ref_names;
 	info.stale_refs_tail = &stale_refs;
 	info.refs = refs;
 	info.ref_count = ref_count;
+	info.patterns = patterns;
 	for (ref = fetch_map; ref; ref = ref->next)
 		string_list_append(&ref_names, ref->name);
 	sort_string_list(&ref_names);
diff --git a/remote.h b/remote.h
index c07eb99..afa3792 100644
--- a/remote.h
+++ b/remote.h
@@ -234,8 +234,13 @@ struct ref *guess_remote_head(const struct ref *head,
 			      const struct ref *refs,
 			      int all);
 
-/* Return refs which no longer exist on remote */
-struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fetch_map);
+/*
+ * Return refs that no longer exist on remote and that match one of
+ * the patterns.
+ */
+struct ref *get_stale_heads(struct refspec *refs, int ref_count,
+			    struct ref *fetch_map,
+			    struct string_list *patterns);
 
 /*
  * Compare-and-swap
-- 
1.8.4.3
Previous: Michael HaggertyNext: Michael Haggerty
Message 2 of 15 in “[RFC 00/11] Make reference pruning more configurable”
  1. Michael HaggertyDec 4, 2013
  2. 01/11 get_stale_heads(): allow limiting to refname patternsMichael Haggerty, Dec 4, 2013
  3. 02/11 remote.c: add infrastructure for parsing --prune optionsMichael Haggerty, Dec 4, 2013
  4. Duy NguyenDec 4, 2013
  5. Michael HaggertyDec 4, 2013
  6. 03/11 fetch: use the new functions for handling --prune optionsMichael Haggerty, Dec 4, 2013
  7. 04/11 remote: use the new functions for handling --prune optionsMichael Haggerty, Dec 4, 2013
  8. 05/11 remote.c: add infrastructure to handle --prune=<pattern>Michael Haggerty, Dec 4, 2013
  9. 06/11 fetch --prune: allow refname patterns to be specifiedMichael Haggerty, Dec 4, 2013
  10. 07/11 remote update --prune: allow refname patterns to be specifiedMichael Haggerty, Dec 4, 2013
  11. 08/11 string_list_append_list(): new functionMichael Haggerty, Dec 4, 2013
  12. 09/11 remote prune: allow --prune=<pattern> optionsMichael Haggerty, Dec 4, 2013
  13. 10/11 remote show: allow --prune=<pattern> optionsMichael Haggerty, Dec 4, 2013
  14. 11/11 remote: allow prune patterns to be configuredMichael Haggerty, Dec 4, 2013
  15. Junio C HamanoDec 4, 2013

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.