Subject: git-cache-proxy: Handle extra-parameters for git protocol v2
Package: chiark-scripts
X-Debbugs-Cc: [email protected]
Severity: wishlist
Tags: patch upstream
Hi,
Recent version of QEMU (to be 8.1) started to use meson subproject to
clone extra repo. With the example of the subproject "dtc", they do a
shallow clone with a sha1. Meson end up running:
git fetch --depth 1 origin b6910bec11614980a21e46fbccc35934b671bd81
This command fails. I think the error message is something like "the
remote end hung up unexpectedly", on Debian Buster. A more useful
message with more recent version of git seems to be "couldn't find
remote ref".
If we allow git to communicate with the protocol v2, then the shallow
clone works.
I've prepared a patch.
Thanks,
--
Anthony PERARD
>From 08f56a629af409c11caa20de59676a5b68e46c44 Mon Sep 17 00:00:00 2001
From: Anthony PERARD <[email protected]>
Date: Thu, 22 Jun 2023 15:46:53 +0100
Subject: [PATCH] git-cache-proxy: Handle extra-parameters for git protocol v2
This patch allows git clients to communicate with the cache with the
git protocol version 2.
Even if the only described extra-parameters is "version=2", the protocol
describe how extra parameters are handled. `git-upload-pack` will just
ignore the ones it doesn't know about.
The first line of the git protocol is described at
https://github.com/git/git/blob/master/Documentation/gitprotocol-pack.txt
with "extra-parameters" been implemented here.
These parameters can be passed down to `git-upload-pack` via
the environment variable GIT_PROTOCOL like a clone over ssh would do
(if the ssh server allows GIT_PROTOCOL env variables).
GIT_PROTOCOL is described in
https://github.com/git/git/blob/master/Documentation/git.txt
The reason we need to be able to handle V2 is allow a shallow clone
with a sha1. Shallow clone seems to only work with a known ref with
the v1 of the protocol.
Example of command that fails when QEMU v8.1 tries to clone the
subproject "dtc" via meson.
git fetch --depth 1 origin b6910bec11614980a21e46fbccc35934b671bd81
This command also fails when git isn't able to send the envvar
GIT_PROTOCOL, like when cloning over ssh (without git-cache-proxy).
Signed-off-by: Anthony PERARD <[email protected]>
---
scripts/git-cache-proxy | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/scripts/git-cache-proxy b/scripts/git-cache-proxy
index 2d80cb1..13b13e7 100755
--- a/scripts/git-cache-proxy
+++ b/scripts/git-cache-proxy
@@ -244,7 +244,7 @@ sub xread {
chdir $cachedir or fail "chdir $cachedir: $!";
-our ($service,$specpath,$spechost,$subdir);
+our ($service,$specpath,$spechost,$extraparams,$subdir);
our ($tmpd,$gitd,$lock);
our ($fetch,$url);
@@ -259,8 +259,8 @@ sub readcommand () {
my $hex_len = xread 4;
fail "Bad hex in packet length" unless $hex_len =~ m|^[0-9a-fA-F]{4}$|;
my $line = xread -4 + hex $hex_len;
- unless (($service,$specpath,$spechost) = $line =~
- m|^(git-[a-z-]+) /*([!-~ ]+)\0host=([!-~]+)\0|) {
+ unless (($service,$specpath,$spechost,$extraparams) = $line =~
+ m|^(git-[a-z-]+) /*([!-~ ]+)\0host=([!-~]+)\0(\0(?:[^\0]+\0)+)?|) {
$line =~ s|[^ -~]+| |g;
gitfail "unknown/unsupported instruction `$line'"
}
@@ -561,6 +561,12 @@ sub runcommand () {
chdir $gitd or fail "chdir $gitd: $!";
+ if ($extraparams) {
+ $extraparams =~ s/^\0(.+)\0$/$1/;
+ $extraparams =~ s/\0/:/g;
+ $ENV{GIT_PROTOCOL} = "$extraparams";
+ }
+
exec qw(git-upload-pack --strict), "--timeout=$servetimeout", qw(.)
or fail "exec git-upload-pack: $!";
}
--
Anthony PERARD