git-ls-remote.shon commit whatchanged: Default to DIFF_FORMAT_RAW (9dafea2)
   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://* )
  53        if [ -n "$GIT_SSL_NO_VERIFY" ]; then
  54            curl_extra_args="-k"
  55        fi
  56        curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
  57                echo "failed    slurping"
  58        ;;
  59
  60rsync://* )
  61        mkdir $tmpdir &&
  62        rsync -rlq "$peek_repo/HEAD" $tmpdir &&
  63        rsync -rq "$peek_repo/refs" $tmpdir || {
  64                echo "failed    slurping"
  65                exit
  66        }
  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"
  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* )
  84        git-peek-remote $exec "$peek_repo" ||
  85                echo "failed    slurping"
  86        ;;
  87esac |
  88sort -t '       ' -k 2 |
  89while read sha1 path
  90do
  91        case "$sha1" in
  92        failed)
  93                die "Failed to find remote refs"
  94        esac
  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
 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
 122        esac
 123        case "$match" in
 124        no)
 125                continue ;;
 126        esac
 127        echo "$sha1     $path"
 128done