aboutsummaryrefslogtreecommitdiff
path: root/git-request-pull.sh
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-04-16 14:16:08 +0200
committerJunio C Hamano <gitster@pobox.com>2025-04-16 07:30:29 -0700
commit76042228f20bd9b97a7454b62c70b28117c351c0 (patch)
tree0014a74c148ca303554167c1c16fed1bff944b05 /git-request-pull.sh
parentf6d855091e73fdab8a39185a8392b9d0df7ed46f (diff)
downloadgit-76042228f20bd9b97a7454b62c70b28117c351c0.tar.xz
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>
Diffstat (limited to 'git-request-pull.sh')
-rwxr-xr-xgit-request-pull.sh68
1 files changed, 37 insertions, 31 deletions
diff --git a/git-request-pull.sh b/git-request-pull.sh
index 775ba8ea11..6a7b793678 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -78,41 +78,47 @@ fi
merge_base=$(git merge-base $baserev $headrev) ||
die "fatal: No commits in common between $base and $head"
-# $head is the refname from the command line.
-# 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);
+find_matching_ref () {
+ while read sha1 ref
+ do
+ case "$ref" in
+ *"^"?*)
+ ref="${ref%"^"*}"
+ deref=true
+ ;;
+ *)
+ deref=
+ ;;
+ esac
- while (<STDIN>) {
- chomp;
- my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
+ if test "$sha1" = "${remote:-HEAD}"
+ then
+ echo "$sha1 $sha1"
+ break
+ fi
- if ($sha1 eq $head) {
- $found = $remote_sha1 = $sha1;
- break;
- }
+ case "$ref" in
+ "${remote:-HEAD}"|*"/${remote:-HEAD}")
+ if test -z "$deref"
+ then
+ # Remember the matching unpeeled object on the
+ # remote side.
+ remote_sha1="$sha1"
+ fi
- if ($ref eq $head || $ref =~ $pattern) {
- if ($deref eq "") {
- # Remember the matching object on the remote side
- $remote_sha1 = $sha1;
- }
- if ($sha1 eq $headrev) {
- $found = $ref;
- break;
- }
- }
- }
- if ($found) {
- $remote_sha1 = $headrev if ! defined $remote_sha1;
- print "$remote_sha1 $found\n";
- }
-'
+ if test "$sha1" = "$headrev"
+ then
+ echo "${remote_sha1:-$headrev} $ref"
+ break
+ fi
+ ;;
+ esac
+ done
+}
-set fnord $(git ls-remote "$url" | @PERL_PATH@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
+# Find a ref with the same name as $remote that exists at the remote
+# and points to the same commit as the local object.
+set fnord $(git ls-remote "$url" | find_matching_ref)
remote_sha1=$2
ref=$3