0001-request-pull-use-awk-instead-of-perl-to-parse-ls-rem.patch (2125B)
- From 742272838f08fa1b9fe47ef842253ac84a502ee7 Mon Sep 17 00:00:00 2001
- From: Michael Forney <mforney@mforney.org>
- Date: Tue, 16 Mar 2021 17:21:31 -0700
- Subject: [PATCH] request-pull: use awk instead of perl to parse ls-remote
- output
- ---
- git-request-pull.sh | 48 +++++++++++++++++++++++++++------------------
- 1 file changed, 29 insertions(+), 19 deletions(-)
- diff --git a/git-request-pull.sh b/git-request-pull.sh
- index 775ba8ea11..a7177c5e1c 100755
- --- a/git-request-pull.sh
- +++ b/git-request-pull.sh
- @@ -82,37 +82,47 @@ die "fatal: No commits in common between $base and $head"
- # Find a ref with the same name as $head that exists at the remote
- # and points to the same commit as the local object.
- find_matching_ref='
- - my ($head,$headrev) = (@ARGV);
- - my $pattern = qr{/\Q$head\E$};
- - my ($remote_sha1, $found);
- + function endswith(s, t) {
- + n = length(s)
- + m = length(t)
- + return m <= n && substr(s, n - m + 1) == t
- + }
- - while (<STDIN>) {
- - chomp;
- - my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
- + {
- + sha1 = $1
- + ref = $2
- - if ($sha1 eq $head) {
- - $found = $remote_sha1 = $sha1;
- - break;
- + if (sha1 == head) {
- + found = remote_sha1 = sha1
- + exit
- }
- - if ($ref eq $head || $ref =~ $pattern) {
- - if ($deref eq "") {
- + deref = index(ref, "^")
- + if (deref)
- + ref = substr(ref, 1, deref - 1)
- +
- + if (ref == head || endswith(ref, "/" head)) {
- + if (!deref) {
- # Remember the matching object on the remote side
- - $remote_sha1 = $sha1;
- + remote_sha1 = sha1
- }
- - if ($sha1 eq $headrev) {
- - $found = $ref;
- - break;
- + if (sha1 == headrev) {
- + found = ref
- + exit
- }
- }
- }
- - if ($found) {
- - $remote_sha1 = $headrev if ! defined $remote_sha1;
- - print "$remote_sha1 $found\n";
- +
- + END {
- + if (found) {
- + if (!remote_sha1)
- + remote_sha1 = headrev
- + print remote_sha1 " " found
- + }
- }
- '
- -set fnord $(git ls-remote "$url" | @PERL_PATH@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
- +set fnord $(git ls-remote "$url" | awk -v "head=${remote:-HEAD}" -v "headrev=$headrev" "$find_matching_ref")
- remote_sha1=$2
- ref=$3
- --
- 2.45.2