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

[RFC 02/11] remote.c: add infrastructure for parsing --prune options

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 4, 2013, 05:44 UTC
Message-ID
<1386135890-13954-3-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1386135890-13954-1-git-send-email-mhagger@alum.mit.edu>

For now, only handle --prune/--no-prune. But handle the option via a callback so that in the future --prune=PATTERN can be implemented.

The new functions are not yet used.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 remote.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 remote.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
diff --git a/remote.c b/remote.c
index 075ed71..297e52f 100644
--- a/remote.c
+++ b/remote.c
@@ -7,6 +7,7 @@
 #include "dir.h"
 #include "tag.h"
 #include "string-list.h"
+#include "argv-array.h"
 #include "mergesort.h"
 
 enum map_direction { FROM_SRC, FROM_DST };
@@ -58,6 +59,67 @@ static struct rewrites rewrites_push;
 #define BUF_SIZE (2048)
 static char buffer[BUF_SIZE];
 
+int prune_option_parse(const struct option *opt, const char *arg, int unset)
+{
+	struct prune_option *target = opt->value;
+
+	if (unset) {
+		target->prune = 0;
+	} else {
+		target->prune = 1;
+	}
+	return 0;
+}
+
+static int git_fetch_config(const char *k, const char *v, void *cb)
+{
+	int *fetch_prune_config = cb;
+
+	if (!strcmp(k, "fetch.prune")) {
+		*fetch_prune_config = git_config_bool(k, v);
+		return 0;
+	}
+	return 0;
+}
+
+void prune_option_fill(struct remote *remote,
+		       struct prune_option *prune_option, int default_prune)
+{
+	if (prune_option->prune < 0) {
+		/*
+		 * The user specified neither --prune nor --no-prune;
+		 * use the configured value of remote.<name>.prune or
+		 * fetch.prune:
+		 */
+		if (remote->prune >= 0) {
+			prune_option->prune = remote->prune;
+		} else {
+			int fetch_prune_config = -1;
+
+			git_config(git_fetch_config, &fetch_prune_config);
+
+			if (fetch_prune_config >= 0)
+				prune_option->prune = fetch_prune_config;
+			else
+				prune_option->prune = default_prune;
+		}
+	}
+}
+
+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");
+}
+
+void prune_option_clear(struct prune_option *prune_option)
+{
+}
+
 static int valid_remote(const struct remote *remote)
 {
 	return (!!remote->url) || (!!remote->foreign_vcs);
diff --git a/remote.h b/remote.h
index afa3792..21ff4cb 100644
--- a/remote.h
+++ b/remote.h
@@ -53,6 +53,40 @@ struct remote {
 	char *http_proxy;
 };
 
+/* Structure to hold parsed --prune/--no-prune options */
+struct prune_option {
+	/* Should we prune at all?  -1 is indeterminate. */
+	int prune;
+};
+
+#define PRUNE_OPTION_INIT { -1 }
+
+/* parse_opts() callback for --prune/--no-prune options */
+int prune_option_parse(const struct option *opt, const char *arg, int unset);
+
+/*
+ * Fill in prune_option for the specified remote, given the
+ * prune_option values parsed from the command-line.  default_prune
+ * specifies whether pruning should default to true or false if it has
+ * not been configured explicitly.
+ */
+void prune_option_fill(struct remote *remote,
+		       struct prune_option *prune_option, int default_prune);
+
+/*
+ * Add --prune/--prune=<pattern>/--no-prune options to the argv_array
+ * to represent the options in prune_options.
+ */
+struct argv_array;
+void argv_push_prune_option(struct argv_array *argv,
+			    struct prune_option *prune_option);
+
+/*
+ * Free any resources used by *prune_option (but not *prune_option
+ * itself).
+ */
+void prune_option_clear(struct prune_option *prune_option);
+
 struct remote *remote_get(const char *name);
 struct remote *pushremote_get(const char *name);
 int remote_is_configured(const char *name);
@@ -238,6 +272,7 @@ 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: Duy Nguyen
Message 3 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.