shithub: git9

ref: 777e9c6d56ed9eaeb28196b3b6da77a34139f892
dir: /export/

View raw version
#!/bin/rc
rfork ne
. /sys/lib/git/common.rc

patchname=/tmp/git.patchname.$pid
patchfile=/tmp/git.patchfile.$pid
fn sigexit{
	rm -f $patchname $patchfile
}

gitup

flagfmt='o:patchdir patchdir'; args='[query]'
eval `''{aux/getflags $*} || exec aux/usage

if(~ $#patchdir 1 && ! test -d $patchdir)
	mkdir -p $patchdir

q=$*
if(~ $#q 0)
	q=HEAD
commits=`{/$cputype/bin/git/query $q || die $status}
n=1
m=$#commits
mntgen /mnt/scratch
for(c in $commits){
	cp=`{/$cputype/bin/git/query -p $c}
	pp=`{/$cputype/bin/git/query -p $c'^'}

	@{
		rfork n
		cd /mnt/scratch
		bind $pp/tree a
		bind $cp/tree b
		
		echo From $c
		echo From: `{cat $cp/author}
		echo Date: `{date -m `{mtime $cp/author | awk '{print $1}'}}
		<$cp/msg awk '
		BEGIN {RS = ""; FS = "\n"}
		NR == 1 {
			n = ENVIRON["n"]
			m = ENVIRON["m"]
			if(m > 1)
				patch = sprintf("[PATCH %d/%d]", n, m)
			else
				patch = "[PATCH]"
			printf "Subject: %s", patch
			for(i = 1; i <= NF; i++)
				msg = msg " " $i
			printf "%s\n\n", msg
			
			gsub("^[ 	]|[ 	]$", "", msg)
			gsub("[/ 	]", "-", msg)
			printf "%.4d-%s.patch", n, msg >ENVIRON["patchname"]
			next
		}
		{print; printf "\n"}'
		ape/diff -urN a b
	} >$patchfile
	if(~ $#patchdir 0){
		cat $patchfile
		! ~ $n $m && echo
	}
	if not
		mv $patchfile $patchdir/`{cat $patchname}
	n=`{echo $n + 1 | bc}
}
exit ''