[PATCH/RFC 5/7] ruby: rewrite perl script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ruby can do it just fine, no need for perl.

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 git-request-pull.rb | 66 ++++++++++++++++++++++++++---------------------------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/git-request-pull.rb b/git-request-pull.rb
index b6d0156..6a96a98 100644
--- a/git-request-pull.rb
+++ b/git-request-pull.rb
@@ -67,39 +67,39 @@ die "No commits in common between #{base} and #{head}" unless $?.success?
 # 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 ($tagged, $branch, $found);
-  while (<STDIN>) {
-    my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
-    next unless ($sha1 eq $ARGV[1]);
-    $found = abbr($ref);
-    if ($deref && $ref eq "tags/$ARGV[2]") {
-      $tagged = $found;
-      last;
-    }
-    if ($ref =~ m|/\Q$ARGV[0]\E$|) {
-      $exact = $found;
-    }
-  }
-  if ($tagged) {
-    print "$tagged\n";
-  } elsif ($exact) {
-    print "$exact\n";
-  } elsif ($found) {
-    print "$found\n";
-  }
-'
-
-ref = `git ls-remote "#{url}" | perl -e '#{find_matching_ref}' "#{head}" "#{headrev}" "#{tag_name}"`.chomp
+
+def abbr(ref)
+    if (ref =~ /^refs\/heads\/(.*)/ || ref =~ /^refs\/(tags\/.*)/)
+      return $1
+    end
+    return ref
+end
+
+found = tagged = exact = 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)
+    if (deref && ref == "tags/#{tag_name}")
+      tagged = found
+      break
+    end
+    if (ref =~ /\/#{Regexp.escape(head)}$/m)
+      exact = found
+    end
+  end
+end
+
+if tagged
+  ref = tagged
+elsif exact
+  ref = exact
+else
+  ref = found
+end
+
+ref = '' if ref == nil
 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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]