request-pull: stop depending on Perl
While git-request-pull(1) is written as a shell script, for it to function we depend on Perl being available. The script gets installed unconditionally though, regardless of whether or not Perl is even available on the system. When it's not available, the `@PERL_PATH@` variable may be substituted with a nonexistent executable path and thus cause the script to fail. Refactor the script so that it does not depend on Perl at all anymore. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 16, 2025 at 14:16 UTC
76042228f20bd9b97a7454b62c70b28117c351c0
2 files changed
+40
-40
git-request-pull.sh
+40
-34
@@ -78,41 +78,47 @@ fi
78
merge_base=$(git merge-base $baserev $headrev) ||
79
die "fatal: No commits in common between $base and $head"
80
81
-# $head is the refname from the command line.
82
-# Find a ref with the same name as $head that exists at the remote
81
+find_matching_ref () {
82
+ while read sha1 ref
83
+ do
84
+ case "$ref" in
85
+ *"^"?*)
86
+ ref="${ref%"^"*}"
87
+ deref=true
88
+ ;;
89
+ *)
90
+ deref=
91
+ ;;
92
+ esac
93
+
94
+ if test "$sha1" = "${remote:-HEAD}"
95
+ then
96
+ echo "$sha1 $sha1"
97
+ break
98
+ fi
99
+
100
+ case "$ref" in
101
+ "${remote:-HEAD}"|*"/${remote:-HEAD}")
102
+ if test -z "$deref"
103
+ then
104
+ # Remember the matching unpeeled object on the
105
+ # remote side.
106
+ remote_sha1="$sha1"
107
+ fi
108
+
109
+ if test "$sha1" = "$headrev"
110
+ then
111
+ echo "${remote_sha1:-$headrev} $ref"
112
+ break
113
+ fi
114
+ ;;
115
+ esac
116
+ done
117
+}
118
+
119
+# Find a ref with the same name as $remote that exists at the remote
120
# and points to the same commit as the local object.
84
-find_matching_ref='
85
- my ($head,$headrev) = (@ARGV);
86
- my $pattern = qr{/\Q$head\E$};
87
- my ($remote_sha1, $found);
88
-
89
- while (<STDIN>) {
90
- chomp;
91
- my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
92
-
93
- if ($sha1 eq $head) {
94
- $found = $remote_sha1 = $sha1;
95
- break;
96
- }
97
-
98
- if ($ref eq $head || $ref =~ $pattern) {
99
- if ($deref eq "") {
100
- # Remember the matching object on the remote side
101
- $remote_sha1 = $sha1;
102
- }
103
- if ($sha1 eq $headrev) {
104
- $found = $ref;
105
- break;
106
- }
107
- }
108
- }
109
- if ($found) {
110
- $remote_sha1 = $headrev if ! defined $remote_sha1;
111
- print "$remote_sha1 $found\n";
112
- }
113
-'
114
-
115
-set fnord $(git ls-remote "$url" | @PERL_PATH@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
121
+set fnord $(git ls-remote "$url" | find_matching_ref)
122
remote_sha1=$2
123
ref=$3
124
t/t5150-request-pull.sh
-6
@@ -7,12 +7,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8
. ./test-lib.sh
9
10
-if ! test_have_prereq PERL
11
-then
12
- skip_all='skipping request-pull tests, perl not available'
13
- test_done
14
-fi
15
-
10
test_expect_success 'setup' '
11
12
git init --bare upstream.git &&