]>
Commit | Line | Data |
---|---|---|
0fec0822 JH |
1 | #!/bin/sh |
2 | # | |
0fec0822 JH |
3 | |
4 | usage () { | |
96b086d6 MO |
5 | echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]" |
6 | echo >&2 " <repository> <refs>..." | |
0fec0822 JH |
7 | exit 1; |
8 | } | |
9 | ||
1abacf3b JH |
10 | die () { |
11 | echo >&2 "$*" | |
12 | exit 1 | |
13 | } | |
14 | ||
96b086d6 | 15 | exec= |
0fec0822 JH |
16 | while case "$#" in 0) break;; esac |
17 | do | |
18 | case "$1" in | |
19 | -h|--h|--he|--hea|--head|--heads) | |
20 | heads=heads; shift ;; | |
0fec0822 JH |
21 | -t|--t|--ta|--tag|--tags) |
22 | tags=tags; shift ;; | |
96b086d6 MO |
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;; | |
0fec0822 JH |
28 | --) |
29 | shift; break ;; | |
30 | -*) | |
31 | usage ;; | |
32 | *) | |
33 | break ;; | |
34 | esac | |
35 | done | |
36 | ||
972b6fe7 | 37 | case "$#" in 0) usage ;; esac |
0fec0822 JH |
38 | |
39 | case ",$heads,$tags," in | |
40 | ,,,) heads=heads tags=tags other=other ;; | |
41 | esac | |
42 | ||
215a7ad1 | 43 | . git-parse-remote |
e0bfc81e | 44 | peek_repo="$(get_remote_url "$@")" |
972b6fe7 | 45 | shift |
0fec0822 JH |
46 | |
47 | tmp=.ls-remote-$$ | |
48 | trap "rm -fr $tmp-*" 0 1 2 3 15 | |
49 | tmpdir=$tmp-d | |
50 | ||
51 | case "$peek_repo" in | |
52 | http://* | https://* ) | |
53 | if [ -n "$GIT_SSL_NO_VERIFY" ]; then | |
54 | curl_extra_args="-k" | |
55 | fi | |
7fa8ddd6 | 56 | curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" || |
a5cd85e0 | 57 | echo "failed slurping" |
0fec0822 JH |
58 | ;; |
59 | ||
60 | rsync://* ) | |
e686eba4 JH |
61 | mkdir $tmpdir && |
62 | rsync -rlq "$peek_repo/HEAD" $tmpdir && | |
a5cd85e0 JH |
63 | rsync -rq "$peek_repo/refs" $tmpdir || { |
64 | echo "failed slurping" | |
65 | exit | |
66 | } | |
e686eba4 JH |
67 | head=$(cat "$tmpdir/HEAD") && |
68 | case "$head" in | |
69 | ref:' '*) | |
70 | head=$(expr "z$head" : 'zref: \(.*\)') && | |
71 | head=$(cat "$tmpdir/$head") || exit | |
72 | esac && | |
73 | echo "$head HEAD" | |
0fec0822 JH |
74 | (cd $tmpdir && find refs -type f) | |
75 | while read path | |
76 | do | |
77 | cat "$tmpdir/$path" | tr -d '\012' | |
78 | echo " $path" | |
79 | done && | |
80 | rm -fr $tmpdir | |
81 | ;; | |
82 | ||
83 | * ) | |
96b086d6 | 84 | git-peek-remote $exec "$peek_repo" || |
a5cd85e0 | 85 | echo "failed slurping" |
0fec0822 JH |
86 | ;; |
87 | esac | | |
972b6fe7 | 88 | sort -t ' ' -k 2 | |
0fec0822 JH |
89 | while read sha1 path |
90 | do | |
a5cd85e0 JH |
91 | case "$sha1" in |
92 | failed) | |
93 | die "Failed to find remote refs" | |
94 | esac | |
0fec0822 JH |
95 | case "$path" in |
96 | refs/heads/*) | |
97 | group=heads ;; | |
98 | refs/tags/*) | |
99 | group=tags ;; | |
100 | *) | |
101 | group=other ;; | |
102 | esac | |
103 | case ",$heads,$tags,$other," in | |
104 | *,$group,*) | |
105 | ;; | |
106 | *) | |
107 | continue;; | |
108 | esac | |
972b6fe7 JH |
109 | case "$#" in |
110 | 0) | |
111 | match=yes ;; | |
112 | *) | |
113 | match=no | |
114 | for pat | |
115 | do | |
116 | case "/$path" in | |
117 | */$pat ) | |
118 | match=yes | |
119 | break ;; | |
120 | esac | |
121 | done | |
0fec0822 | 122 | esac |
972b6fe7 JH |
123 | case "$match" in |
124 | no) | |
125 | continue ;; | |
126 | esac | |
127 | echo "$sha1 $path" | |
0fec0822 | 128 | done |