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

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

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 4, 2013, 05:44 UTC
Message-ID
<1386135890-13954-6-git-send-email-mhagger@alum.mit.edu>
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
Previous: Michael HaggertyNext: Michael Haggerty
Message 8 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.