git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Santi Béjar" <sbejar@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Subject: "git cat" and "git ls"
Date: Wed, 18 Jan 2006 16:10:16 +0100	[thread overview]
Message-ID: <87irsh6087.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

Hello,

        following the "git diff" wrapper I've done two new wrappers:

git cat: USAGE='<tag|commit|blob> | [<ent>|-1|-2|-3] -- <file>'

    It shows the content of the giventag/commit/blob.

    You can also ask for a file in a tree or in the index (stage
    optional).

git ls: USAGE='[<ent>] [--] <path>'

    It lists the files in <path> in the <ent> or in the index.

  Santi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: git-cat.sh --]
[-- Type: text/x-sh, Size: 1011 bytes --]

#!/bin/sh
#

USAGE='<tag|commit|blob> | [<ent>|-1|-2|-3] -- <file>'
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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: git-ls.sh --]
[-- Type: text/x-sh, Size: 335 bytes --]

#!/bin/sh
#

USAGE='[<ent>] [--] <path>'
SUBDIRECTORY_OK='Yes'
. git-sh-setup

tree=$(git-rev-parse --verify $1^{tree} 2>/dev/null)
[ -n "$tree" ] && shift
files=$(git-rev-parse --no-revs --no-flags --sq "$@")

case "$tree" in
"")
        cmd="git-ls-files -s $files"
	;;
?*)
	cmd="git-ls-tree $tree $files"
	;;
esac

eval "$cmd"
exit

             reply	other threads:[~2006-01-18 15:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-18 15:10 Santi Béjar [this message]
2006-01-18 17:14 ` "git cat" and "git ls" Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87irsh6087.fsf@gmail.com \
    --to=sbejar@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).