{"thread":{"id":"6621","subject":"[PATCH 1/2] Pull out remote listing functions in git-remote.","startedAt":"2007-02-02T05:05:55Z","lastAt":"2007-02-02T05:05:55Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"33334","messageId":"20070202050554.GA20505@spearce.org","threadId":"6621","inReplyTo":null,"subject":"[PATCH 1/2] Pull out remote listing functions in git-remote.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-02T05:05:55Z","receivedAt":"2007-02-02T05:05:55Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"I want to reuse the stale branch detection to implement a new\n'git remote prune' subcommand.  Easiest way to do that is to use\nthe same logic that 'git remote show' uses to determine the stale\ntracking branches, then delete those.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n git-remote.perl |   43 +++++++++++++++++++++++--------------------\n 1 files changed, 23 insertions(+), 20 deletions(-)\n\ndiff --git a/git-remote.perl b/git-remote.perl\nindex c813fe1..969d33b 100755\n--- a/git-remote.perl\n+++ b/git-remote.perl\n@@ -130,7 +130,7 @@ sub update_ls_remote {\n \t$info->{'LS_REMOTE'} = \\@ref;\n }\n \n-sub show_wildcard_mapping {\n+sub list_wildcard_mapping {\n \tmy ($forced, $ours, $ls) = @_;\n \tmy %refs;\n \tfor (@$ls) {\n@@ -156,25 +156,14 @@ sub show_wildcard_mapping {\n \t\t\tpush @tracked, $_;\n \t\t}\n \t}\n-\tif (@new) {\n-\t\tprint \"  New remote branches (next fetch will store in remotes/$ours)\\n\";\n-\t\tprint \"    @new\\n\";\n-\t}\n-\tif (@stale) {\n-\t\tprint \"  Stale tracking branches in remotes/$ours (you'd better remove them)\\n\";\n-\t\tprint \"    @stale\\n\";\n-\t}\n-\tif (@tracked) {\n-\t\tprint \"  Tracked remote branches\\n\";\n-\t\tprint \"    @tracked\\n\";\n-\t}\n+\treturn \\@new, \\@stale, \\@tracked;\n }\n \n-sub show_mapping {\n+sub list_mapping {\n \tmy ($name, $info) = @_;\n \tmy $fetch = $info->{'FETCH'};\n \tmy $ls = $info->{'LS_REMOTE'};\n-\tmy (@stale, @tracked);\n+\tmy (@new, @stale, @tracked);\n \n \tfor (@$fetch) {\n \t\tnext unless (/(\\+)?([^:]+):(.*)/);\n@@ -182,7 +171,11 @@ sub show_mapping {\n \t\tif ($theirs eq 'refs/heads/*' &&\n \t\t    $ours =~ /^refs\\/remotes\\/(.*)\\/\\*$/) {\n \t\t\t# wildcard mapping\n-\t\t\tshow_wildcard_mapping($forced, $1, $ls);\n+\t\t\tmy ($w_new, $w_stale, $w_tracked)\n+\t\t\t\t= list_wildcard_mapping($forced, $1, $ls);\n+\t\t\tpush @new, @$w_new;\n+\t\t\tpush @stale, @$w_stale;\n+\t\t\tpush @tracked, @$w_tracked;\n \t\t}\n \t\telsif ($theirs =~ /\\*/ || $ours =~ /\\*/) {\n \t\t\tprint STDERR \"Warning: unrecognized mapping in remotes.$name.fetch: $_\\n\";\n@@ -196,13 +189,23 @@ sub show_mapping {\n \t\t\t}\n \t\t}\n \t}\n-\tif (@stale) {\n+\treturn \\@new, \\@stale, \\@tracked;\n+}\n+\n+sub show_mapping {\n+\tmy ($name, $info) = @_;\n+\tmy ($new, $stale, $tracked) = list_mapping($name, $info);\n+\tif (@$new) {\n+\t\tprint \"  New remote branches (next fetch will store in remotes/$name)\\n\";\n+\t\tprint \"    @$new\\n\";\n+\t}\n+\tif (@$stale) {\n \t\tprint \"  Stale tracking branches in remotes/$name (you'd better remove them)\\n\";\n-\t\tprint \"    @stale\\n\";\n+\t\tprint \"    @$stale\\n\";\n \t}\n-\tif (@tracked) {\n+\tif (@$tracked) {\n \t\tprint \"  Tracked remote branches\\n\";\n-\t\tprint \"    @tracked\\n\";\n+\t\tprint \"    @$tracked\\n\";\n \t}\n }\n \n-- \n1.5.0.rc3.1.ge4b0e\n"}]}