From: Eric Wong Date: Sat, 26 Nov 2005 22:05:17 GMT Subject: Re: simple git repository browser with vim Message-ID: <20051126220517.GC3899@mail.yhbt.net> In-Reply-To: <7v8xveuyq0.fsf@assigned-by-dhcp.cox.net> Junio C Hamano wrote: > Eric Wong writes: > > > 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 > ;-). Maybe somebody else will find this useful, overkill for me. > 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. This is pretty useful, I've added it to my version, and also added extra vim foldmarkers for the dereferenced tag. > 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. That was semi-intentional, I wanted the short diff format with the sha1sums of the blobs so I could further expand those inside vim. Fortunately, I've figured out that diff-tree is better for this. Here's what I'm currently using: --- #!/bin/sh extract_tag_info=' s/^object /sha1=/p /^type /{ s//type=/ p q } ' sha1sums= while : ; do case "$1" in -f|--fold-marker) fold_marker=1 ;; *) sha1sums="$sha1sums $1" break ;; esac shift done for sha1 in $sha1sums do type=`git-cat-file -t $sha1` || continue test -n "$fold_marker" && echo "$type($1) {{{" while case "$type" in tag) ;; *) break ;; esac do git-cat-file tag "$sha1" git-verify-tag "$sha1" test -n "$fold_marker" && echo '}}}' eval `git-cat-file tag "$sha1" | sed -n -e "$extract_tag_info"` test -n "$fold_marker" && echo "$type($1) {{{" done case "$type" in tree) git-ls-tree -r "$sha1" ;; blob) git-cat-file blob "$sha1" ;; commit) git-diff-tree --pretty=raw -r -m -C --find-copies-harder "$sha1" test -n "$fold_marker" && echo "commit_diff($1) {{{" git-diff-tree -m -C --find-copies-harder -p "$sha1" test -n "$fold_marker" && echo '}}}' ;; esac test -n "$fold_marker" && echo '}}}' done