1#!/bin/sh
2#
3
4usage () {
5 echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6 echo >&2 " <repository> <refs>..."
7 exit 1;
8}
9
10die () {
11 echo >&2 "$*"
12 exit 1
13}
14
15exec=
16while case "$#" in 0) break;; esac
17do
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 ;;
32 *)
33 break ;;
34 esac
35done
36
37case "$#" in 0) usage ;; esac
38
39case ",$heads,$tags," in
40,,,) heads=heads tags=tags other=other ;;
41esac
42
43. git-parse-remote
44peek_repo="$(get_remote_url "$@")"
45shift
46
47tmp=.ls-remote-$$
48trap "rm -fr $tmp-*" 0 1 2 3 15
49tmpdir=$tmp-d
50
51case "$peek_repo" in
52http://* | https://* )
53 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54 curl_extra_args="-k"
55 fi
56 curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
57 echo "failed slurping"
58 ;;
59
60rsync://* )
61 mkdir $tmpdir
62 rsync -rq "$peek_repo/refs" $tmpdir || {
63 echo "failed slurping"
64 exit
65 }
66 (cd $tmpdir && find refs -type f) |
67 while read path
68 do
69 cat "$tmpdir/$path" | tr -d '\012'
70 echo " $path"
71 done &&
72 rm -fr $tmpdir
73 ;;
74
75* )
76 git-peek-remote $exec "$peek_repo" ||
77 echo "failed slurping"
78 ;;
79esac |
80sort -t ' ' -k 2 |
81while read sha1 path
82do
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 ;;
92 *)
93 group=other ;;
94 esac
95 case ",$heads,$tags,$other," in
96 *,$group,*)
97 ;;
98 *)
99 continue;;
100 esac
101 case "$#" in
102 0)
103 match=yes ;;
104 *)
105 match=no
106 for pat
107 do
108 case "/$path" in
109 */$pat )
110 match=yes
111 break ;;
112 esac
113 done
114 esac
115 case "$match" in
116 no)
117 continue ;;
118 esac
119 echo "$sha1 $path"
120done