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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Feb 2, 2007 at 00:05 UTC
7a8c9ec1a95a368c5f32d430058d67109feccfee
1 file changed
+23
-20
git-remote.perl
+23
-20
@@ -130,7 +130,7 @@ sub update_ls_remote {
130
$info->{'LS_REMOTE'} = \@ref;
131
}
132
133
-sub show_wildcard_mapping {
133
+sub list_wildcard_mapping {
134
my ($forced, $ours, $ls) = @_;
135
my %refs;
136
for (@$ls) {
@@ -156,25 +156,14 @@ sub show_wildcard_mapping {
156
push @tracked, $_;
157
}
158
}
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;
160
}
161
173
-sub show_mapping {
162
+sub list_mapping {
163
my ($name, $info) = @_;
164
my $fetch = $info->{'FETCH'};
165
my $ls = $info->{'LS_REMOTE'};
177
- my (@stale, @tracked);
166
+ my (@new, @stale, @tracked);
167
168
for (@$fetch) {
169
next unless (/(\+)?([^:]+):(.*)/);
@@ -182,7 +171,11 @@ sub show_mapping {
171
if ($theirs eq 'refs/heads/*' &&
172
$ours =~ /^refs\/remotes\/(.*)\/\*$/) {
173
# 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;
179
}
180
elsif ($theirs =~ /\*/ || $ours =~ /\*/) {
181
print STDERR "Warning: unrecognized mapping in remotes.$name.fetch: $_\n";
@@ -196,13 +189,23 @@ sub show_mapping {
189
}
190
}
191
}
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) {
203
print " Stale tracking branches in remotes/$name (you'd better remove them)\n";
201
- print " @stale\n";
204
+ print " @$stale\n";
205
}
203
- if (@tracked) {
206
+ if (@$tracked) {
207
print " Tracked remote branches\n";
205
- print " @tracked\n";
208
+ print " @$tracked\n";
209
}
210
}
211