git-ls-remote.shon commit parse-remote and ls-remote clean-up. (e8cc80d)
   1#!/bin/sh
   2#
   3
   4usage () {
   5    echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
   6    exit 1;
   7}
   8
   9while case "$#" in 0) break;; esac
  10do
  11  case "$1" in
  12  -h|--h|--he|--hea|--head|--heads)
  13  heads=heads; shift ;;
  14  -t|--t|--ta|--tag|--tags)
  15  tags=tags; shift ;;
  16  --)
  17  shift; break ;;
  18  -*)
  19  usage ;;
  20  *)
  21  break ;;
  22  esac
  23done
  24
  25case "$#" in 0) usage ;; esac
  26
  27case ",$heads,$tags," in
  28,,,) heads=heads tags=tags other=other ;;
  29esac
  30
  31. git-parse-remote
  32peek_repo="$(get_remote_url "$@")"
  33shift
  34
  35tmp=.ls-remote-$$
  36trap "rm -fr $tmp-*" 0 1 2 3 15
  37tmpdir=$tmp-d
  38
  39case "$peek_repo" in
  40http://* | https://* )
  41        if [ -n "$GIT_SSL_NO_VERIFY" ]; then
  42            curl_extra_args="-k"
  43        fi
  44        curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
  45                echo "failed    slurping"
  46        ;;
  47
  48rsync://* )
  49        mkdir $tmpdir
  50        rsync -rq "$peek_repo/refs" $tmpdir || {
  51                echo "failed    slurping"
  52                exit
  53        }
  54        (cd $tmpdir && find refs -type f) |
  55        while read path
  56        do
  57                cat "$tmpdir/$path" | tr -d '\012'
  58                echo "  $path"
  59        done &&
  60        rm -fr $tmpdir
  61        ;;
  62
  63* )
  64        git-peek-remote "$peek_repo" ||
  65                echo "failed    slurping"
  66        ;;
  67esac |
  68sort -t '       ' -k 2 |
  69while read sha1 path
  70do
  71        case "$sha1" in
  72        failed)
  73                die "Failed to find remote refs"
  74        esac
  75        case "$path" in
  76        refs/heads/*)
  77                group=heads ;;
  78        refs/tags/*)
  79                group=tags ;;
  80        *)
  81                group=other ;;
  82        esac
  83        case ",$heads,$tags,$other," in
  84        *,$group,*)
  85                ;;
  86        *)
  87                continue;;
  88        esac
  89        case "$#" in
  90        0)
  91                match=yes ;;
  92        *)
  93                match=no
  94                for pat
  95                do
  96                        case "/$path" in
  97                        */$pat )
  98                                match=yes
  99                                break ;;
 100                        esac
 101                done
 102        esac
 103        case "$match" in
 104        no)
 105                continue ;;
 106        esac
 107        echo "$sha1     $path"
 108done