git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars Hjemli <hjemli@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 1/2] git remote: move part of prune() into prune_one()
Date: Tue, 23 Sep 2008 23:13:24 +0200	[thread overview]
Message-ID: <1222204405-30454-2-git-send-email-hjemli@gmail.com> (raw)
In-Reply-To: <1222204405-30454-1-git-send-email-hjemli@gmail.com>

The new function will be reused by prune_all() in the next patch.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
 builtin-remote.c |   67 +++++++++++++++++++++++++++++------------------------
 1 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/builtin-remote.c b/builtin-remote.c
index 4cb763f..626256e 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -537,6 +537,41 @@ static int show(int argc, const char **argv)
 	return result;
 }

+static int prune_one(const char *name, int dry_run)
+{
+	struct ref_states states;
+	int result = 0;
+	int i;
+
+	memset(&states, 0, sizeof(states));
+	get_remote_ref_states(name, &states, 1);
+
+	if (states.stale.nr) {
+		printf("Pruning %s\n", name);
+		printf("URL: %s\n",
+		       states.remote->url_nr
+		       ? states.remote->url[0]
+		       : "(no URL)");
+	}
+
+	for (i = 0; i < states.stale.nr; i++) {
+		const char *refname = states.stale.items[i].util;
+
+		if (!dry_run)
+			result |= delete_ref(refname, NULL);
+
+		printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
+		       abbrev_ref(refname, "refs/remotes/"));
+	}
+
+	/* NEEDSWORK: free remote */
+	string_list_clear(&states.new, 0);
+	string_list_clear(&states.stale, 0);
+	string_list_clear(&states.tracked, 0);
+
+	return result;
+}
+
 static int prune(int argc, const char **argv)
 {
 	int dry_run = 0, result = 0;
@@ -545,42 +580,14 @@ static int prune(int argc, const char **argv)
 		OPT__DRY_RUN(&dry_run),
 		OPT_END()
 	};
-	struct ref_states states;

 	argc = parse_options(argc, argv, options, builtin_remote_usage, 0);

 	if (argc < 1)
 		usage_with_options(builtin_remote_usage, options);

-	memset(&states, 0, sizeof(states));
-	for (; argc; argc--, argv++) {
-		int i;
-
-		get_remote_ref_states(*argv, &states, 1);
-
-		if (states.stale.nr) {
-			printf("Pruning %s\n", *argv);
-			printf("URL: %s\n",
-			       states.remote->url_nr
-			       ? states.remote->url[0]
-			       : "(no URL)");
-		}
-
-		for (i = 0; i < states.stale.nr; i++) {
-			const char *refname = states.stale.items[i].util;
-
-			if (!dry_run)
-				result |= delete_ref(refname, NULL);
-
-			printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
-			       abbrev_ref(refname, "refs/remotes/"));
-		}
-
-		/* NEEDSWORK: free remote */
-		string_list_clear(&states.new, 0);
-		string_list_clear(&states.stale, 0);
-		string_list_clear(&states.tracked, 0);
-	}
+	for (; argc; argc--, argv++)
+		result |= prune_one(*argv, dry_run);

 	return result;
 }
--
1.6.0.2.309.gc1f46

  reply	other threads:[~2008-09-23 21:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-23 21:13 [PATCH 0/2] Teach `git remote` howto prune all remotes Lars Hjemli
2008-09-23 21:13 ` Lars Hjemli [this message]
2008-09-23 21:13   ` [PATCH 2/2] git remote: prune all remotes with `prune -a` Lars Hjemli

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=1222204405-30454-2-git-send-email-hjemli@gmail.com \
    --to=hjemli@gmail.com \
    --cc=git@vger.kernel.org \
    /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).