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

[RFC 03/11] fetch: use the new functions for handling --prune options

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 4, 2013, 05:44 UTC
Message-ID
<1386135890-13954-4-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1386135890-13954-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/fetch.c | 36 ++++++++----------------------------
 1 file changed, 8 insertions(+), 28 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 9a04512..fcc06a4 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -30,8 +30,7 @@ enum {
 	TAGS_SET = 2
 };
 
-static int fetch_prune_config = -1; /* unspecified */
-static int prune = -1; /* unspecified */
+static struct prune_option prune_option = PRUNE_OPTION_INIT;
 #define PRUNE_BY_DEFAULT 0 /* do we prune by default? */
 
 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
@@ -59,15 +58,6 @@ static int option_parse_recurse_submodules(const struct option *opt,
 	return 0;
 }
 
-static int git_fetch_config(const char *k, const char *v, void *cb)
-{
-	if (!strcmp(k, "fetch.prune")) {
-		fetch_prune_config = git_config_bool(k, v);
-		return 0;
-	}
-	return 0;
-}
-
 static struct option builtin_fetch_options[] = {
 	OPT__VERBOSITY(&verbosity),
 	OPT_BOOL(0, "all", &all,
@@ -83,8 +73,9 @@ static struct option builtin_fetch_options[] = {
 		    N_("fetch all tags and associated objects"), TAGS_SET),
 	OPT_SET_INT('n', NULL, &tags,
 		    N_("do not fetch all tags (--no-tags)"), TAGS_UNSET),
-	OPT_BOOL('p', "prune", &prune,
-		 N_("prune remote-tracking branches no longer on remote")),
+	{ OPTION_CALLBACK, 'p', "prune", &prune_option, N_("pattern"),
+		    N_("prune remote-tracking branches no longer on remote"),
+		    PARSE_OPT_NOARG, prune_option_parse },
 	{ OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"),
 		    N_("control recursive fetching of submodules"),
 		    PARSE_OPT_OPTARG, option_parse_recurse_submodules },
@@ -848,7 +839,7 @@ static int do_fetch(struct transport *transport,
 		retcode = 1;
 		goto cleanup;
 	}
-	if (prune) {
+	if (prune_option.prune) {
 		/*
 		 * We only prune based on refspecs specified
 		 * explicitly (via command line or configuration); we
@@ -935,8 +926,7 @@ static void add_options_to_argv(struct argv_array *argv)
 {
 	if (dry_run)
 		argv_array_push(argv, "--dry-run");
-	if (prune != -1)
-		argv_array_push(argv, prune ? "--prune" : "--no-prune");
+	argv_push_prune_option(argv, &prune_option);
 	if (update_head_ok)
 		argv_array_push(argv, "--update-head-ok");
 	if (force)
@@ -1002,17 +992,9 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 		die(_("No remote repository specified.  Please, specify either a URL or a\n"
 		    "remote name from which new revisions should be fetched."));
 
-	gtransport = prepare_transport(remote);
+	prune_option_fill(remote, &prune_option, PRUNE_BY_DEFAULT);
 
-	if (prune < 0) {
-		/* no command line request */
-		if (0 <= gtransport->remote->prune)
-			prune = gtransport->remote->prune;
-		else if (0 <= fetch_prune_config)
-			prune = fetch_prune_config;
-		else
-			prune = PRUNE_BY_DEFAULT;
-	}
+	gtransport = prepare_transport(remote);
 
 	if (argc > 0) {
 		int j = 0;
@@ -1063,8 +1045,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	for (i = 1; i < argc; i++)
 		strbuf_addf(&default_rla, " %s", argv[i]);
 
-	git_config(git_fetch_config, NULL);
-
 	argc = parse_options(argc, argv, prefix,
 			     builtin_fetch_options, builtin_fetch_usage, 0);
 
-- 
1.8.4.3
Previous: Michael HaggertyNext: Michael Haggerty
Message 6 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.