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 05/11] remote.c: add infrastructure to handle --prune=<pattern>
Date: Wed, 4 Dec 2013 06:44:44 +0100 [thread overview]
Message-ID: <1386135890-13954-6-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1386135890-13954-1-git-send-email-mhagger@alum.mit.edu>
This will soon be used to allow the user to tell what reference
namespaces should be subjected to pruning. But since the callers of
these functions still use PARSE_OPT_NOARG, the new functionality is
not yet visible.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
remote.c | 35 +++++++++++++++++++++++++++++------
remote.h | 11 +++++++----
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/remote.c b/remote.c
index 297e52f..89c9eaa 100644
--- a/remote.c
+++ b/remote.c
@@ -6,7 +6,6 @@
#include "revision.h"
#include "dir.h"
#include "tag.h"
-#include "string-list.h"
#include "argv-array.h"
#include "mergesort.h"
@@ -64,9 +63,16 @@ int prune_option_parse(const struct option *opt, const char *arg, int unset)
struct prune_option *target = opt->value;
if (unset) {
+ if (arg) {
+ error("--no-prune must not be used with an argument");
+ return 1;
+ }
target->prune = 0;
+ string_list_clear(&target->prune_patterns, 0);
} else {
target->prune = 1;
+ if (arg)
+ string_list_append(&target->prune_patterns, arg);
}
return 0;
}
@@ -104,20 +110,37 @@ void prune_option_fill(struct remote *remote,
prune_option->prune = default_prune;
}
}
+
+ if (prune_option->prune && !prune_option->prune_patterns.nr) {
+ /*
+ * We want to prune, but no pruning patterns were
+ * specified on the command line. Default to "*".
+ */
+ string_list_append(&prune_option->prune_patterns, "*");
+ }
}
void argv_push_prune_option(struct argv_array *argv,
struct prune_option *prune_option)
{
- if (prune_option->prune != -1)
- argv_array_pushf(argv,
- prune_option->prune
- ? "--prune"
- : "--no-prune");
+ if (prune_option->prune != -1) {
+ if (prune_option->prune && prune_option->prune_patterns.nr) {
+ struct string_list_item *item;
+
+ for_each_string_list_item(item, &prune_option->prune_patterns)
+ argv_array_pushf(argv, "--prune=%s", item->string);
+ } else {
+ argv_array_pushf(argv,
+ prune_option->prune
+ ? "--prune"
+ : "--no-prune");
+ }
+ }
}
void prune_option_clear(struct prune_option *prune_option)
{
+ string_list_clear(&prune_option->prune_patterns, 0);
}
static int valid_remote(const struct remote *remote)
diff --git a/remote.h b/remote.h
index 21ff4cb..a484290 100644
--- a/remote.h
+++ b/remote.h
@@ -2,6 +2,7 @@
#define REMOTE_H
#include "parse-options.h"
+#include "string-list.h"
enum {
REMOTE_CONFIG,
@@ -53,15 +54,18 @@ struct remote {
char *http_proxy;
};
-/* Structure to hold parsed --prune/--no-prune options */
+/* Structure to hold parsed --prune/--prune=<pattern>/--no-prune options */
struct prune_option {
/* Should we prune at all? -1 is indeterminate. */
int prune;
+
+ /* Arguments passed to --prune=<pattern> */
+ struct string_list prune_patterns;
};
-#define PRUNE_OPTION_INIT { -1 }
+#define PRUNE_OPTION_INIT { -1, STRING_LIST_INIT_DUP }
-/* parse_opts() callback for --prune/--no-prune options */
+/* parse_opts() callback for --prune/--prune=<pattern>/--no-prune options */
int prune_option_parse(const struct option *opt, const char *arg, int unset);
/*
@@ -272,7 +276,6 @@ struct ref *guess_remote_head(const struct ref *head,
* Return refs that no longer exist on remote and that match one of
* the patterns.
*/
-struct string_list;
struct ref *get_stale_heads(struct refspec *refs, int ref_count,
struct ref *fetch_map,
struct string_list *patterns);
--
1.8.4.3
next prev parent reply other threads:[~2013-12-04 5:53 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 ` [RFC 01/11] get_stale_heads(): allow limiting to refname patterns Michael Haggerty
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 ` Michael Haggerty [this message]
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-6-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).