shithub: git9

Download patch

ref: 8fec5d15308b5b99b246e521f6db16422adea3e9
parent: e90fb0398fb401f1bd93d49d4986b27cb9deb87e
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 30 11:43:56 EDT 2019

Allow filtering logging by file name.

--- a/README
+++ b/README
@@ -143,5 +143,3 @@
 
 	git/patch -c:	Generate a 'git am' compatible patch.
 	git/patch -a:	Apply a diff.
-	git/log:	Need to figure out how to make it filter
-			by files.
--- a/commit
+++ b/commit
@@ -48,10 +48,8 @@
 	echo '# Author: '$name' <'$email'>' >> $msgfile.tmp
 	echo '#' $nl'# ' ^ `$nl{git/walk -fAMR} >> $msgfile.tmp
 	sam $msgfile.tmp
-	if(! test -s $msgfile.tmp || ~ `{wc -l <{grep -v '^[ 	]*[\n#]' $msgfile.tmp}} 0){
-		echo 'cancelling commit: empty message' >[1=2]
-		exit 'nocommit'
-	}
+	if(~ `{grep -v '^[ 	]*($|#.*$)' $msgfile.tmp | wc -l} 0)
+		exit 'empty commit message'
 	grep -v '^[ 	]*#' < $msgfile.tmp > $msgfile
 }
 
--- a/git.1
+++ b/git.1
@@ -66,6 +66,13 @@
 ]
 .PP
 .B git/log
+[
+.B -b
+.I branch
+]
+[
+.I files...
+]
 .PP
 .B git/merge
 .I theirs
--- a/log
+++ b/log
@@ -3,20 +3,37 @@
 rfork en
 
 base=/mnt/git/object/
-branch=$1
-if(~ $1 '')
-	branch='master'
-if(! test -e /mnt/git/ctl)
-	git/fs
+branch=master
+git/fs
 
+while(~ $1 -* && ! ~ $1 --){
+	switch($1){
+	case -b;
+		shift
+		branch=$1
+	case -*;
+		exit usage
+	}
+	shift
+}
 commits=(`{git/query $branch})
+
+# Logging a directory needs a recursive list.
+files=()
+for(f in $*){
+	if(test -d $f)
+		files=($files `{walk -f $f})
+	if not
+		files=($files $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)
-	
-	echo 'Hash:	' `{cat $base/$c/hash}
-	echo 'Author:	' `{cat $base/$c/author}
-	cat $base/$c/msg | sed 's/^/	/g'
-	echo ''
+	if(! ~ $#files 0)
+		nids=`{sha1sum $base/$commits(1)^/tree/$files | awk '{print $1}' >[2]/dev/null}
 
 	commits=($commits(2-) `{cat $base/$c/parent >[2]/dev/null})
 	if(! ~ $#commits 0)
@@ -23,4 +40,13 @@
 		commits=`{mtime $base^$commits |
 			sort -rn | uniq |
 			awk -F/ '{print $NF}'}
+
+	if(~ $#files 0 || ! ~ $"ids $"nids || ~ $#commits 0){
+		echo 'Hash:	' `{cat $base/$c/hash}
+		echo 'Author:	' `{cat $base/$c/author}
+		cat $base/$c/msg | sed 's/^/	/g'
+		echo ''
+	}
+
+
 }