#!/bin/sh # proc usage { echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack ]> !2 "usage: $0 [--heads] [--tags] [-u|--upload-pack ]" echo >&2 " ...> !2 " ..." exit 1; } proc die { echo >&2 "$ifsjoin(Argv)> !2 "$*" exit 1 } setglobal exec = '' while test $# != 0 { match $1 { with -h|--h|--he|--hea|--head|--heads setglobal heads = 'heads'; shift with -t|--t|--ta|--tag|--tags setglobal tags = 'tags'; shift with -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\ --upload-pac|--upload-pack shift setglobal exec = ""--upload-pack=$1"" shift with -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\ --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=* setglobal exec = "--upload-pack=$[expr "z$1" : 'z-[^=]*=\(.*\)]" shift with -- shift; break with -* usage with * break } } match "$Argc" { with 0 usage } match ",$heads,$tags," { with ,,, setglobal heads = 'heads', tags = 'tags', other = 'other' } source git-parse-remote setglobal peek_repo = $[get_remote_url @Argv] shift setglobal tmp = ".ls-remote-$Pid" trap "rm -fr $tmp-*" 0 1 2 3 15 setglobal tmpdir = "$tmp-d" match $peek_repo { with http://* | https://* | ftp://* if test -n $GIT_SSL_NO_VERIFY -o \ $[git config --bool http.sslVerify] = false { setglobal curl_extra_args = '"-k'" } if test -n $GIT_CURL_FTP_NO_EPSV -o \ $[git config --bool http.noEPSV] = true { setglobal curl_extra_args = ""$(curl_extra_args) --disable-epsv"" } curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" || echo "failed slurping" with rsync://* mkdir $tmpdir && rsync -rlq "$peek_repo/HEAD" $tmpdir && rsync -rq "$peek_repo/refs" $tmpdir || do { echo "failed slurping" exit } setglobal head = $[cat "$tmpdir/HEAD] && match $head { with ref:' '* setglobal head = $[expr "z$head" : 'zref: \(.*\)] && setglobal head = $[cat "$tmpdir/$head] || exit } && echo "$head HEAD" shell {cd $tmpdir && find refs -type f} | while read path { tr -d '\012' <"$tmpdir/$path" echo " $path" } && rm -fr $tmpdir with * if test -f $peek_repo { git bundle list-heads $peek_repo || echo "failed slurping" } else { git-peek-remote $exec $peek_repo || echo "failed slurping" } } | sort -t ' ' -k 2 | while read sha1 path { match $sha1 { with failed exit 1 } match $path { with refs/heads/* setglobal group = 'heads' with refs/tags/* setglobal group = 'tags' with * setglobal group = 'other' } match ",$heads,$tags,$other," { with *,$group,* with * continue } match "$Argc" { with 0 setglobal match = 'yes' with * setglobal match = 'no'for pat in @Argv { match "/$path" { with */$pat setglobal match = 'yes' break } } } match $match { with no continue } echo "$sha1 $path" }