#!/bin/sh # USAGE=' | [|-1|-2|-3] -- ' SUBDIRECTORY_OK='Yes' . git-sh-setup rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit flags=$(git-rev-parse --no-revs --flags "$@") files=$(git-rev-parse --no-revs --no-flags --sq "$@") case "$rev,$files" in ?*' '?*,*|*,?*' '?*) usage ;; ?*,?*) sha1=$(eval "git-ls-tree $rev $files" | cut -f 1 | cut -d " " -f 3) ;; ?*,) sha1=$rev ;; ,?*) # Only one file [ $(eval "git-ls-files $files | wc -l") != 1 ] && usage stg=0 flag=${flags#-} case $flag in 1|2|3) stg=$flag;; esac sha1=$(eval "git-ls-files -s $files" | while read -r mode sha stage name ; do [ $stage -eq $stg ] && echo $sha && break ; done) ;; *) usage ;; esac [ -z $sha1 ] && echo "$(basename $0): $files: Not found" && exit 1 type=$(eval "git-cat-file -t $sha1") case $type in tree) usage ;; tag|blob) cmd="git-cat-file $type $sha1" ;; commit) cmd="git-rev-list --max-count=1 $sha1 --pretty=fuller" ;; esac eval "$cmd" exit