Ruby can do it just fine, no need for perl.
Signed-off-by: Felipe Contreras <[email protected]>
---
Notes:
I'm mostly ignoring the comment, my hope is that it would be redundant, as
the
code would be self-documenting.
git-request-pull.rb | 65 +++++++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 35 deletions(-)
diff --git a/git-request-pull.rb b/git-request-pull.rb
index 60cf6ce..eee2e28 100755
--- a/git-request-pull.rb
+++ b/git-request-pull.rb
@@ -14,6 +14,35 @@ EOF
exit 1
end
+def abbr(ref)
+ if (ref =~ %r{^refs/heads/(.*)} || ref =~ %r{^refs/(tags/.*)})
+ return $1
+ end
+ return ref
+end
+
+# $head is the token given from the command line, and $tag_name, if
+# exists, is the tag we are going to show the commit information for.
+# If that tag exists at the remote and it points at the commit, use it.
+# Otherwise, if a branch with the same name as $head exists at the remote
+# and their values match, use that instead.
+#
+# Otherwise find a random ref that matches $headrev.
+
+def get_ref(url, headref, headrev, tag_name)
+ found = nil
+ IO.popen(%[git ls-remote "#{url}"]) do |out|
+ out.each do |l|
+ sha1, ref, deref = l.scan(/^(\S+)\s+(\S+?)(\^\{\})?$/).first
+ next unless sha1 == headrev
+ found = abbr(ref)
+ break if (deref && ref == "refs/tags/#{tag_name}")
+ break if ref == headref
+ end
+ end
+ return found
+end
+
until ARGV.empty?
case ARGV.first
when '-p'
@@ -57,41 +86,7 @@ die "Not a valid revision: #{head}" if headrev.empty?
merge_base = `git merge-base #{baserev} #{headrev}`.chomp
die "No commits in common between #{base} and #{head}" unless $?.success?
-# $head is the token given from the command line, and $tag_name, if
-# exists, is the tag we are going to show the commit information for.
-# If that tag exists at the remote and it points at the commit, use it.
-# Otherwise, if a branch with the same name as $head exists at the remote
-# and their values match, use that instead.
-#
-# Otherwise find a random ref that matches $headrev.
-find_matching_ref='
- sub abbr {
- my $ref = shift;
- if ($ref =~ s|^refs/heads/|| || $ref =~ s|^refs/tags/|tags/|) {
- return $ref;
- } else {
- return $ref;
- }
- }
-
- my ($found);
- while (<STDIN>) {
- my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
- next unless ($sha1 eq $ARGV[1]);
- $found = abbr($ref);
- if ($deref && $ref eq "refs/tags/$ARGV[2]") {
- last;
- }
- if ($ref eq $ARGV[0]) {
- last;
- }
- }
- if ($found) {
- print "$found\n";
- }
-'
-
-ref = `git ls-remote "#{url}" | perl -e '#{find_matching_ref}' "#{headref}"
"#{headrev}" "#{tag_name}"`.chomp
+ref = get_ref(url, headref, headrev, tag_name) || ''
url = `git ls-remote --get-url "#{url}"`.chomp
begin
--
1.8.4-fc
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html