From: Michael Haggerty <mhagger@alum.mit.edu>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Michael Haggerty <mhagger@alum.mit.edu>
Subject: [RFC 01/11] get_stale_heads(): allow limiting to refname patterns
Date: Wed, 4 Dec 2013 06:44:40 +0100 [thread overview]
Message-ID: <1386135890-13954-2-git-send-email-mhagger@alum.mit.edu> (raw)
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
next prev parent reply other threads:[~2013-12-04 5:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-04 5:44 [RFC 00/11] Make reference pruning more configurable Michael Haggerty
2013-12-04 5:44 ` Michael Haggerty [this message]
2013-12-04 5:44 ` [RFC 02/11] remote.c: add infrastructure for parsing --prune options Michael Haggerty
2013-12-04 12:57 ` Duy Nguyen
2013-12-04 17:04 ` Michael Haggerty
2013-12-04 5:44 ` [RFC 03/11] fetch: use the new functions for handling " Michael Haggerty
2013-12-04 5:44 ` [RFC 04/11] remote: " Michael Haggerty
2013-12-04 5:44 ` [RFC 05/11] remote.c: add infrastructure to handle --prune=<pattern> Michael Haggerty
2013-12-04 5:44 ` [RFC 06/11] fetch --prune: allow refname patterns to be specified Michael Haggerty
2013-12-04 5:44 ` [RFC 07/11] remote update " Michael Haggerty
2013-12-04 5:44 ` [RFC 08/11] string_list_append_list(): new function Michael Haggerty
2013-12-04 5:44 ` [RFC 09/11] remote prune: allow --prune=<pattern> options Michael Haggerty
2013-12-04 5:44 ` [RFC 10/11] remote show: " Michael Haggerty
2013-12-04 5:44 ` [RFC 11/11] remote: allow prune patterns to be configured Michael Haggerty
2013-12-04 20:25 ` [RFC 00/11] Make reference pruning more configurable Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386135890-13954-2-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).