Skip to content

Commit 7a8c9ec

Browse files
spearceJunio C Hamano
authored andcommitted
Pull out remote listing functions in git-remote.
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22600a2 commit 7a8c9ec

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

git-remote.perl

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ sub update_ls_remote {
130130
$info->{'LS_REMOTE'} = \@ref;
131131
}
132132

133-
sub show_wildcard_mapping {
133+
sub list_wildcard_mapping {
134134
my ($forced, $ours, $ls) = @_;
135135
my %refs;
136136
for (@$ls) {
@@ -156,33 +156,26 @@ sub show_wildcard_mapping {
156156
push @tracked, $_;
157157
}
158158
}
159-
if (@new) {
160-
print " New remote branches (next fetch will store in remotes/$ours)\n";
161-
print " @new\n";
162-
}
163-
if (@stale) {
164-
print " Stale tracking branches in remotes/$ours (you'd better remove them)\n";
165-
print " @stale\n";
166-
}
167-
if (@tracked) {
168-
print " Tracked remote branches\n";
169-
print " @tracked\n";
170-
}
159+
return \@new, \@stale, \@tracked;
171160
}
172161

173-
sub show_mapping {
162+
sub list_mapping {
174163
my ($name, $info) = @_;
175164
my $fetch = $info->{'FETCH'};
176165
my $ls = $info->{'LS_REMOTE'};
177-
my (@stale, @tracked);
166+
my (@new, @stale, @tracked);
178167

179168
for (@$fetch) {
180169
next unless (/(\+)?([^:]+):(.*)/);
181170
my ($forced, $theirs, $ours) = ($1, $2, $3);
182171
if ($theirs eq 'refs/heads/*' &&
183172
$ours =~ /^refs\/remotes\/(.*)\/\*$/) {
184173
# wildcard mapping
185-
show_wildcard_mapping($forced, $1, $ls);
174+
my ($w_new, $w_stale, $w_tracked)
175+
= list_wildcard_mapping($forced, $1, $ls);
176+
push @new, @$w_new;
177+
push @stale, @$w_stale;
178+
push @tracked, @$w_tracked;
186179
}
187180
elsif ($theirs =~ /\*/ || $ours =~ /\*/) {
188181
print STDERR "Warning: unrecognized mapping in remotes.$name.fetch: $_\n";
@@ -196,13 +189,23 @@ sub show_mapping {
196189
}
197190
}
198191
}
199-
if (@stale) {
192+
return \@new, \@stale, \@tracked;
193+
}
194+
195+
sub show_mapping {
196+
my ($name, $info) = @_;
197+
my ($new, $stale, $tracked) = list_mapping($name, $info);
198+
if (@$new) {
199+
print " New remote branches (next fetch will store in remotes/$name)\n";
200+
print " @$new\n";
201+
}
202+
if (@$stale) {
200203
print " Stale tracking branches in remotes/$name (you'd better remove them)\n";
201-
print " @stale\n";
204+
print " @$stale\n";
202205
}
203-
if (@tracked) {
206+
if (@$tracked) {
204207
print " Tracked remote branches\n";
205-
print " @tracked\n";
208+
print " @$tracked\n";
206209
}
207210
}
208211

0 commit comments

Comments
 (0)