format-patch: use same number of digits in numbers
[git/jnareb-git/bp-gitweb.git] / git-ls-remote.sh
blobf69926862fba15c28933c6dd616065d331b9a89b
1 #!/bin/sh
4 usage () {
5 echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
6 exit 1;
9 die () {
10 echo >&2 "$*"
11 exit 1
14 while case "$#" in 0) break;; esac
16 case "$1" in
17 -h|--h|--he|--hea|--head|--heads)
18 heads=heads; shift ;;
19 -t|--t|--ta|--tag|--tags)
20 tags=tags; shift ;;
21 --)
22 shift; break ;;
23 -*)
24 usage ;;
26 break ;;
27 esac
28 done
30 case "$#" in 0) usage ;; esac
32 case ",$heads,$tags," in
33 ,,,) heads=heads tags=tags other=other ;;
34 esac
36 . git-parse-remote
37 peek_repo="$(get_remote_url "$@")"
38 shift
40 tmp=.ls-remote-$$
41 trap "rm -fr $tmp-*" 0 1 2 3 15
42 tmpdir=$tmp-d
44 case "$peek_repo" in
45 http://* | https://* )
46 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
47 curl_extra_args="-k"
49 curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
50 echo "failed slurping"
53 rsync://* )
54 mkdir $tmpdir
55 rsync -rq "$peek_repo/refs" $tmpdir || {
56 echo "failed slurping"
57 exit
59 (cd $tmpdir && find refs -type f) |
60 while read path
62 cat "$tmpdir/$path" | tr -d '\012'
63 echo " $path"
64 done &&
65 rm -fr $tmpdir
68 * )
69 git-peek-remote "$peek_repo" ||
70 echo "failed slurping"
72 esac |
73 sort -t ' ' -k 2 |
74 while read sha1 path
76 case "$sha1" in
77 failed)
78 die "Failed to find remote refs"
79 esac
80 case "$path" in
81 refs/heads/*)
82 group=heads ;;
83 refs/tags/*)
84 group=tags ;;
86 group=other ;;
87 esac
88 case ",$heads,$tags,$other," in
89 *,$group,*)
92 continue;;
93 esac
94 case "$#" in
96 match=yes ;;
98 match=no
99 for pat
101 case "/$path" in
102 */$pat )
103 match=yes
104 break ;;
105 esac
106 done
107 esac
108 case "$match" in
110 continue ;;
111 esac
112 echo "$sha1 $path"
113 done