logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-request-pull-use-awk-instead-of-perl-to-parse-ls-rem.patch (2125B)


  1. From 742272838f08fa1b9fe47ef842253ac84a502ee7 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Tue, 16 Mar 2021 17:21:31 -0700
  4. Subject: [PATCH] request-pull: use awk instead of perl to parse ls-remote
  5. output
  6. ---
  7. git-request-pull.sh | 48 +++++++++++++++++++++++++++------------------
  8. 1 file changed, 29 insertions(+), 19 deletions(-)
  9. diff --git a/git-request-pull.sh b/git-request-pull.sh
  10. index 775ba8ea11..a7177c5e1c 100755
  11. --- a/git-request-pull.sh
  12. +++ b/git-request-pull.sh
  13. @@ -82,37 +82,47 @@ die "fatal: No commits in common between $base and $head"
  14. # Find a ref with the same name as $head that exists at the remote
  15. # and points to the same commit as the local object.
  16. find_matching_ref='
  17. - my ($head,$headrev) = (@ARGV);
  18. - my $pattern = qr{/\Q$head\E$};
  19. - my ($remote_sha1, $found);
  20. + function endswith(s, t) {
  21. + n = length(s)
  22. + m = length(t)
  23. + return m <= n && substr(s, n - m + 1) == t
  24. + }
  25. - while (<STDIN>) {
  26. - chomp;
  27. - my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
  28. + {
  29. + sha1 = $1
  30. + ref = $2
  31. - if ($sha1 eq $head) {
  32. - $found = $remote_sha1 = $sha1;
  33. - break;
  34. + if (sha1 == head) {
  35. + found = remote_sha1 = sha1
  36. + exit
  37. }
  38. - if ($ref eq $head || $ref =~ $pattern) {
  39. - if ($deref eq "") {
  40. + deref = index(ref, "^")
  41. + if (deref)
  42. + ref = substr(ref, 1, deref - 1)
  43. +
  44. + if (ref == head || endswith(ref, "/" head)) {
  45. + if (!deref) {
  46. # Remember the matching object on the remote side
  47. - $remote_sha1 = $sha1;
  48. + remote_sha1 = sha1
  49. }
  50. - if ($sha1 eq $headrev) {
  51. - $found = $ref;
  52. - break;
  53. + if (sha1 == headrev) {
  54. + found = ref
  55. + exit
  56. }
  57. }
  58. }
  59. - if ($found) {
  60. - $remote_sha1 = $headrev if ! defined $remote_sha1;
  61. - print "$remote_sha1 $found\n";
  62. +
  63. + END {
  64. + if (found) {
  65. + if (!remote_sha1)
  66. + remote_sha1 = headrev
  67. + print remote_sha1 " " found
  68. + }
  69. }
  70. '
  71. -set fnord $(git ls-remote "$url" | @PERL_PATH@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
  72. +set fnord $(git ls-remote "$url" | awk -v "head=${remote:-HEAD}" -v "headrev=$headrev" "$find_matching_ref")
  73. remote_sha1=$2
  74. ref=$3
  75. --
  76. 2.45.2