shithub: git9

ref: 8fb116e331e879f493fccef746d43ba12f6fb072
dir: /log/

View raw version
#!/bin/rc -e
rfork en
. /sys/lib/git/common.rc

usage='
	git/log [-q query] [file ...]
'

gitup

base=/mnt/git/object/
branch=`{git/branch}
query=()

while(~ $1 -* && ! ~ $1 --){
	switch($1){
	case -b
		branch=$2
		shift
	case -q
		query=$2
		shift
	case *
		usage
	}
	shift
}
if(~ $1 --)
	shift
if(~ $#query 0)
	commits=`{git/query $branch}
if not
	commits=`{git/query $query}
files=()
if(! ~ $#* 0)
	files=`$nl{walk -f $*}

if(! ~ $#files 0)
	nids=`{sha1sum $base/$commits(1)^/tree/$files | awk '{print $1}' >[2]/dev/null}

while(! ~ $#commits 0){
	ids=$nids
	c=$commits(1)
	if(! ~ $#files 0)
		nids=`{sha1sum $base/$commits(1)^/tree/$files | awk '{print $1}' >[2]/dev/null}
		commits=$commits(2-)
		if(~ $#query 0)
			commits=($commits `{cat $base/$c/parent >[2]/dev/null})
	if(! ~ $#commits 0)
		commits=`$nl{walk -emp -n0 $base^$commits | sort -rn | uniq | awk -F/ '{print $NF}'}

	if(~ $#files 0 || ! ~ $"ids $"nids || ~ $#commits 0){
		echo -n 'Hash:	'`''{cat $base/$c/hash}
		echo -n 'Author:	'`''{cat $base/$c/author}
		echo -n 'Date:	'`''{date `{mtime $base/$c/msg | awk '{print $1}'}}
		sed 's/^/	/g' $base/$c/msg
		echo
	}
}