All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Pull out remote listing functions in git-remote.
@ 2007-02-02  5:05 Shawn O. Pearce
  0 siblings, 0 replies; only message in thread
From: Shawn O. Pearce @ 2007-02-02  5:05 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

I want to reuse the stale branch detection to implement a new
'git remote prune' subcommand.  Easiest way to do that is to use
the same logic that 'git remote show' uses to determine the stale
tracking branches, then delete those.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-remote.perl |   43 +++++++++++++++++++++++--------------------
 1 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/git-remote.perl b/git-remote.perl
index c813fe1..969d33b 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -130,7 +130,7 @@ sub update_ls_remote {
 	$info->{'LS_REMOTE'} = \@ref;
 }
 
-sub show_wildcard_mapping {
+sub list_wildcard_mapping {
 	my ($forced, $ours, $ls) = @_;
 	my %refs;
 	for (@$ls) {
@@ -156,25 +156,14 @@ sub show_wildcard_mapping {
 			push @tracked, $_;
 		}
 	}
-	if (@new) {
-		print "  New remote branches (next fetch will store in remotes/$ours)\n";
-		print "    @new\n";
-	}
-	if (@stale) {
-		print "  Stale tracking branches in remotes/$ours (you'd better remove them)\n";
-		print "    @stale\n";
-	}
-	if (@tracked) {
-		print "  Tracked remote branches\n";
-		print "    @tracked\n";
-	}
+	return \@new, \@stale, \@tracked;
 }
 
-sub show_mapping {
+sub list_mapping {
 	my ($name, $info) = @_;
 	my $fetch = $info->{'FETCH'};
 	my $ls = $info->{'LS_REMOTE'};
-	my (@stale, @tracked);
+	my (@new, @stale, @tracked);
 
 	for (@$fetch) {
 		next unless (/(\+)?([^:]+):(.*)/);
@@ -182,7 +171,11 @@ sub show_mapping {
 		if ($theirs eq 'refs/heads/*' &&
 		    $ours =~ /^refs\/remotes\/(.*)\/\*$/) {
 			# wildcard mapping
-			show_wildcard_mapping($forced, $1, $ls);
+			my ($w_new, $w_stale, $w_tracked)
+				= list_wildcard_mapping($forced, $1, $ls);
+			push @new, @$w_new;
+			push @stale, @$w_stale;
+			push @tracked, @$w_tracked;
 		}
 		elsif ($theirs =~ /\*/ || $ours =~ /\*/) {
 			print STDERR "Warning: unrecognized mapping in remotes.$name.fetch: $_\n";
@@ -196,13 +189,23 @@ sub show_mapping {
 			}
 		}
 	}
-	if (@stale) {
+	return \@new, \@stale, \@tracked;
+}
+
+sub show_mapping {
+	my ($name, $info) = @_;
+	my ($new, $stale, $tracked) = list_mapping($name, $info);
+	if (@$new) {
+		print "  New remote branches (next fetch will store in remotes/$name)\n";
+		print "    @$new\n";
+	}
+	if (@$stale) {
 		print "  Stale tracking branches in remotes/$name (you'd better remove them)\n";
-		print "    @stale\n";
+		print "    @$stale\n";
 	}
-	if (@tracked) {
+	if (@$tracked) {
 		print "  Tracked remote branches\n";
-		print "    @tracked\n";
+		print "    @$tracked\n";
 	}
 }
 
-- 
1.5.0.rc3.1.ge4b0e

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2007-02-02  5:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-02  5:05 [PATCH 1/2] Pull out remote listing functions in git-remote Shawn O. Pearce

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.