git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: simple git repository browser with vim

From
EWEric Wong <normalperson@yhbt.net>
Date
Nov 26, 2005, 22:05 UTC
Message-ID
<20051126220517.GC3899@mail.yhbt.net>
In-Reply-To
<7v8xveuyq0.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
Show 14 quoted lines
> Eric Wong <normalperson@yhbt.net> 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.

Show 5 quoted lines
> 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
Previous: Junio C Hamano
Message 3 of 3 in “simple git repository browser with vim”
  1. Eric WongNov 24, 2005
  2. Junio C HamanoNov 24, 2005
  3. Eric WongNov 26, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.