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 <mhag...@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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to