git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Sep 21, 2013, 18:48 UTC
Message-ID
<1379789295-18519-6-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1379789295-18519-1-git-send-email-felipe.contreras@gmail.com>
Ruby can do it just fine, no need for perl.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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
Previous: Felipe ContrerasNext: Felipe Contreras
Message 6 of 26 in “Support for Ruby”
  1. 0/7 Support for RubyFelipe Contreras, Sep 21, 2013
  2. 1/7 Add support for ruby commandsFelipe Contreras, Sep 21, 2013
  3. 2/7 ruby: add setup scriptFelipe Contreras, Sep 21, 2013
  4. 3/7 ruby: add simple wrappersFelipe Contreras, Sep 21, 2013
  5. 4/7 ruby: rewrite 'request-pull'Felipe Contreras, Sep 21, 2013
  6. 5/7 ruby: rewrite perl scriptFelipe Contreras, Sep 21, 2013
  7. 6/7 ruby: remove one forkFelipe Contreras, Sep 21, 2013
  8. 7/7 ruby: rewrite 'reset'Felipe Contreras, Sep 21, 2013
  9. brian m. carlsonSep 21, 2013
  10. Felipe ContrerasSep 21, 2013
  11. brian m. carlsonSep 21, 2013
  12. Felipe ContrerasSep 22, 2013
  13. Fredrik GustafssonSep 22, 2013
  14. Felipe ContrerasSep 22, 2013
  15. Fredrik GustafssonSep 22, 2013
  16. Felipe ContrerasSep 22, 2013
  17. Patrick DonnellySep 23, 2013
  18. Felipe ContrerasSep 23, 2013
  19. Patrick DonnellySep 23, 2013
  20. Felipe ContrerasSep 23, 2013
  21. Junio C HamanoSep 23, 2013
  22. brian m. carlsonSep 23, 2013
  23. Felipe ContrerasSep 28, 2013
  24. Felipe ContrerasSep 23, 2013
  25. Felipe ContrerasSep 28, 2013
  26. Felipe ContrerasSep 28, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.