[RFC 05/11] remote.c: add infrastructure to handle --prune=<pattern>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---
 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

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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]