Code

diffcore-break: micro-optimize by avoiding delta between identical files.
[git.git] / git-ls-remote.sh
1 #!/bin/sh
2 #
4 usage () {
5     echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6     echo >&2 "          <repository> <refs>..."
7     exit 1;
8 }
10 die () {
11     echo >&2 "$*"
12     exit 1
13 }
15 exec=
16 while case "$#" in 0) break;; esac
17 do
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
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"
55         fi
56         curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
57                 echo "failed    slurping"
58         ;;
60 rsync://* )
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         ;;
75 * )
76         git-peek-remote $exec "$peek_repo" ||
77                 echo "failed    slurping"
78         ;;
79 esac |
80 sort -t '       ' -k 2 |
81 while read sha1 path
82 do
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"
120 done