Merge in xdiff cleanup pieces
[git/mingw/4msysgit/kblees.git] / git-ls-remote.sh
blobb6882a90c15a7b706966e608e00facbb80f26422
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 exec=
16 while case "$#" in 0) break;; esac
18 case "$1" in
19 -h|--h|--he|--hea|--head|--heads)
20 heads=heads; shift ;;
21 -t|--t|--ta|--tag|--tags)
22 tags=tags; shift ;;
23 -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
24 --upload-pac|--upload-pack)
25 shift
26 exec="--exec=$1"
27 shift;;
28 --)
29 shift; break ;;
30 -*)
31 usage ;;
33 break ;;
34 esac
35 done
37 case "$#" in 0) usage ;; esac
39 case ",$heads,$tags," in
40 ,,,) heads=heads tags=tags other=other ;;
41 esac
43 . git-parse-remote
44 peek_repo="$(get_remote_url "$@")"
45 shift
47 tmp=.ls-remote-$$
48 trap "rm -fr $tmp-*" 0 1 2 3 15
49 tmpdir=$tmp-d
51 case "$peek_repo" in
52 http://* | https://* )
53 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54 curl_extra_args="-k"
56 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
57 echo "failed slurping"
60 rsync://* )
61 mkdir $tmpdir
62 rsync -rq "$peek_repo/refs" $tmpdir || {
63 echo "failed slurping"
64 exit
66 (cd $tmpdir && find refs -type f) |
67 while read path
69 cat "$tmpdir/$path" | tr -d '\012'
70 echo " $path"
71 done &&
72 rm -fr $tmpdir
75 * )
76 git-peek-remote $exec "$peek_repo" ||
77 echo "failed slurping"
79 esac |
80 sort -t ' ' -k 2 |
81 while read sha1 path
83 case "$sha1" in
84 failed)
85 die "Failed to find remote refs"
86 esac
87 case "$path" in
88 refs/heads/*)
89 group=heads ;;
90 refs/tags/*)
91 group=tags ;;
93 group=other ;;
94 esac
95 case ",$heads,$tags,$other," in
96 *,$group,*)
99 continue;;
100 esac
101 case "$#" in
103 match=yes ;;
105 match=no
106 for pat
108 case "/$path" in
109 */$pat )
110 match=yes
111 break ;;
112 esac
113 done
114 esac
115 case "$match" in
117 continue ;;
118 esac
119 echo "$sha1 $path"
120 done