Skip to content

Commit 7604222

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6d8550 commit 7604222

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

git-request-pull.sh

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,41 +78,47 @@ fi
7878
merge_base=$(git merge-base $baserev $headrev) ||
7979
die "fatal: No commits in common between $base and $head"
8080

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
83120
# 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)
116122
remote_sha1=$2
117123
ref=$3
118124

t/t5150-request-pull.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

88
. ./test-lib.sh
99

10-
if ! test_have_prereq PERL
11-
then
12-
skip_all='skipping request-pull tests, perl not available'
13-
test_done
14-
fi
15-
1610
test_expect_success 'setup' '
1711
1812
git init --bare upstream.git &&

0 commit comments

Comments
 (0)