git-rev-list: make --dense the default (and introduce "--sparse")
[git/jnareb-git/bp-gitweb.git] / git-ls-remote.sh
blobf0f0b07f6f8c85219104303d65dabbba80fd3098
1 #!/bin/sh
3 . git-sh-setup
5 usage () {
6 echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
7 exit 1;
10 while case "$#" in 0) break;; esac
12 case "$1" in
13 -h|--h|--he|--hea|--head|--heads)
14 heads=heads; shift ;;
15 -t|--t|--ta|--tag|--tags)
16 tags=tags; shift ;;
17 --)
18 shift; break ;;
19 -*)
20 usage ;;
22 break ;;
23 esac
24 done
26 case "$#" in 0) usage ;; esac
28 case ",$heads,$tags," in
29 ,,,) heads=heads tags=tags other=other ;;
30 esac
32 . git-parse-remote
33 peek_repo="$(get_remote_url "$@")"
34 shift
36 tmp=.ls-remote-$$
37 trap "rm -fr $tmp-*" 0 1 2 3 15
38 tmpdir=$tmp-d
40 case "$peek_repo" in
41 http://* | https://* )
42 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
43 curl_extra_args="-k"
45 curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
46 echo "failed slurping"
49 rsync://* )
50 mkdir $tmpdir
51 rsync -rq "$peek_repo/refs" $tmpdir || {
52 echo "failed slurping"
53 exit
55 (cd $tmpdir && find refs -type f) |
56 while read path
58 cat "$tmpdir/$path" | tr -d '\012'
59 echo " $path"
60 done &&
61 rm -fr $tmpdir
64 * )
65 git-peek-remote "$peek_repo" ||
66 echo "failed slurping"
68 esac |
69 sort -t ' ' -k 2 |
70 while read sha1 path
72 case "$sha1" in
73 failed)
74 die "Failed to find remote refs"
75 esac
76 case "$path" in
77 refs/heads/*)
78 group=heads ;;
79 refs/tags/*)
80 group=tags ;;
82 group=other ;;
83 esac
84 case ",$heads,$tags,$other," in
85 *,$group,*)
88 continue;;
89 esac
90 case "$#" in
92 match=yes ;;
94 match=no
95 for pat
97 case "/$path" in
98 */$pat )
99 match=yes
100 break ;;
101 esac
102 done
103 esac
104 case "$match" in
106 continue ;;
107 esac
108 echo "$sha1 $path"
109 done