git-ls-remote.shon commit Merge branch 'master' into jc/fsck-reflog (90cee09)
   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://* | ftp://* )
  53        if [ -n "$GIT_SSL_NO_VERIFY" ]; then
  54            curl_extra_args="-k"
  55        fi
  56        if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
  57                "`git-repo-config --bool http.noEPSV`" = true ]; then
  58                curl_extra_args="${curl_extra_args} --disable-epsv"
  59        fi
  60        curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
  61                echo "failed    slurping"
  62        ;;
  63
  64rsync://* )
  65        mkdir $tmpdir &&
  66        rsync -rlq "$peek_repo/HEAD" $tmpdir &&
  67        rsync -rq "$peek_repo/refs" $tmpdir || {
  68                echo "failed    slurping"
  69                exit
  70        }
  71        head=$(cat "$tmpdir/HEAD") &&
  72        case "$head" in
  73        ref:' '*)
  74                head=$(expr "z$head" : 'zref: \(.*\)') &&
  75                head=$(cat "$tmpdir/$head") || exit
  76        esac &&
  77        echo "$head     HEAD"
  78        (cd $tmpdir && find refs -type f) |
  79        while read path
  80        do
  81                cat "$tmpdir/$path" | tr -d '\012'
  82                echo "  $path"
  83        done &&
  84        rm -fr $tmpdir
  85        ;;
  86
  87* )
  88        git-peek-remote $exec "$peek_repo" ||
  89                echo "failed    slurping"
  90        ;;
  91esac |
  92sort -t '       ' -k 2 |
  93while read sha1 path
  94do
  95        case "$sha1" in
  96        failed)
  97                exit 1 ;;
  98        esac
  99        case "$path" in
 100        refs/heads/*)
 101                group=heads ;;
 102        refs/tags/*)
 103                group=tags ;;
 104        *)
 105                group=other ;;
 106        esac
 107        case ",$heads,$tags,$other," in
 108        *,$group,*)
 109                ;;
 110        *)
 111                continue;;
 112        esac
 113        case "$#" in
 114        0)
 115                match=yes ;;
 116        *)
 117                match=no
 118                for pat
 119                do
 120                        case "/$path" in
 121                        */$pat )
 122                                match=yes
 123                                break ;;
 124                        esac
 125                done
 126        esac
 127        case "$match" in
 128        no)
 129                continue ;;
 130        esac
 131        echo "$sha1     $path"
 132done