summaryrefslogtreecommitdiff
path: root/pkg/git/patch/0001-request-pull-use-awk-instead-of-perl-to-parse-ls-rem.patch
blob: 2a4c95c036fe2c97603fb375e54ebc68edec9b70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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