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