Re: simple git repository browser with vim
- From
Junio C Hamano <junkio@cox.net>
- Date
- Nov 24, 2005, 10:28 UTC
- Message-ID
- <7v8xveuyq0.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <20051124093322.GA3899@mail.yhbt.net>
Eric Wong <normalperson@yhbt.net> writes:
Show 5 quoted lines
> It relies on a simple shell script I wrote called 'git-show' that picks > a reasonable way to display each of the blob, tree, or commit object > types. I'm fairly sure somebody else has written something like > git-show before, I just couldn't find it. I'd imagine it's pretty > useful standalone without vim, too.
Aha.
It strikes me that the blob case could be enhanced to do git-unpack-file, run "file -i" on it to figure out the file's mimetype, and then give it to an appropriate MIME type viewer ;-).
For a tag object, you might want to deref it, and also if it is a signed kind, you may want to do git-verify-tag it.
The following should not taken too seriously, but you might find it instructive to learn how to unwrap tag objects, verify them for signature, and pretty-print a single commit without running whatchanged. I suspect the script as posted by you shows the commit message twice, BTW.
-- >8 -- #!/bin/sh
extract_tag_info='
s/^object /sha1=/p
/^type /{
s//type=/
p
q
}
'
for sha1
do
type=`git-cat-file -t "$sha1"` || continue
while case "$type" in tag) ;; *) break ;; esac
do
echo "*** tag $sha1 ***"
git-cat-file tag "$sha1"
git-verify-tag "$sha1"
echo
eval `git-cat-file tag "$sha1" | sed -n -e "$extract_tag_info"`
done
case "$type" in
tree)
echo "*** $type $sha1 ***"
git-ls-tree -r "$sha1"
;;
blob)
temp=`git-unpack-file "$sha1"`
mimetype=`file -i "$temp" | sed -e 's/^[^:]*: *//'`
echo "*** $type ($mimetype) $sha1 ***"
case "$mimetype" in
image/*)
display "$temp" ;;
audio/*)
cat "$temp" >/dev/audio ;; # sorry I do not do audio
text/html)
links -dump "$temp" ;; # hello, Pasky
*)
cat "$temp" ;;
esac
rm -f $temp
;;
commit)
echo "*** $type $sha1 ***"
git-diff-tree --pretty -m -C --find-copies-harder -p "$sha1"
;;
esac
echo
done