Shuffle path lookup functions.
[git/dscho.git] / git-ls-remote.sh
blobd62a859ae2d01f547b26be94e18e623d7f91319c
1 #!/bin/sh
4 usage () {
5 echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6 echo >&2 " <repository> <refs>..."
7 exit 1;
10 die () {
11 echo >&2 "$*"
12 exit 1
15 # Fix some commands on Windows
16 case $(uname -s) in
17 *MINGW*)
18 # Windows has its own (incompatible) sort and find
19 sort () {
20 /usr/bin/sort "$@"
22 find () {
23 /usr/bin/find "$@"
26 esac
28 exec=
29 while test $# != 0
31 case "$1" in
32 -h|--h|--he|--hea|--head|--heads)
33 heads=heads; shift ;;
34 -t|--t|--ta|--tag|--tags)
35 tags=tags; shift ;;
36 -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
37 --upload-pac|--upload-pack)
38 shift
39 exec="--upload-pack=$1"
40 shift;;
41 -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\
42 --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
43 exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
44 shift;;
45 --)
46 shift; break ;;
47 -*)
48 usage ;;
50 break ;;
51 esac
52 done
54 case "$#" in 0) usage ;; esac
56 case ",$heads,$tags," in
57 ,,,) heads=heads tags=tags other=other ;;
58 esac
60 . git-parse-remote
61 peek_repo="$(get_remote_url "$@")"
62 shift
64 tmp=.ls-remote-$$
65 trap "rm -fr $tmp-*" 0 1 2 3 15
66 tmpdir=$tmp-d
68 case "$peek_repo" in
69 http://* | https://* | ftp://* )
70 if [ -n "$GIT_SSL_NO_VERIFY" -o \
71 "`git config --bool http.sslVerify`" = false ]; then
72 curl_extra_args="-k"
74 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
75 "`git config --bool http.noEPSV`" = true ]; then
76 curl_extra_args="${curl_extra_args} --disable-epsv"
78 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
79 echo "failed slurping"
82 rsync://* )
83 mkdir $tmpdir &&
84 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
85 rsync -rq "$peek_repo/refs" $tmpdir || {
86 echo "failed slurping"
87 exit
89 head=$(cat "$tmpdir/HEAD") &&
90 case "$head" in
91 ref:' '*)
92 head=$(expr "z$head" : 'zref: \(.*\)') &&
93 head=$(cat "$tmpdir/$head") || exit
94 esac &&
95 echo "$head HEAD"
96 (cd $tmpdir && find refs -type f) |
97 while read path
99 tr -d '\012' <"$tmpdir/$path"
100 echo " $path"
101 done &&
102 rm -fr $tmpdir
106 if test -f "$peek_repo" ; then
107 git bundle list-heads "$peek_repo" ||
108 echo "failed slurping"
109 else
110 git-peek-remote $exec "$peek_repo" ||
111 echo "failed slurping"
114 esac |
115 sort -t ' ' -k 2 |
116 while read sha1 path
118 case "$sha1" in
119 failed)
120 exit 1 ;;
121 esac
122 case "$path" in
123 refs/heads/*)
124 group=heads ;;
125 refs/tags/*)
126 group=tags ;;
128 group=other ;;
129 esac
130 case ",$heads,$tags,$other," in
131 *,$group,*)
134 continue;;
135 esac
136 case "$#" in
138 match=yes ;;
140 match=no
141 for pat
143 case "/$path" in
144 */$pat )
145 match=yes
146 break ;;
147 esac
148 done
149 esac
150 case "$match" in
152 continue ;;
153 esac
154 echo "$sha1 $path"
155 done