code: plan9front

Download patch

ref: 21aac62c1f0fa565a860d4880ec56b84eb9dd8dd
parent: d457233c70ef6aa28861dd2978e92968ffba0920
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jul 3 00:38:13 EDT 2022

git/log: support -n option to restrict log counts

this is useful for scripting, and convenient for
interactive use.

--- a/sys/man/1/git
+++ b/sys/man/1/git
@@ -96,6 +96,10 @@
 .I expr
 ]
 [
+.B -n
+.I count
+]
+[
 .B -s
 ]
 [
@@ -383,6 +387,11 @@
 The
 .I -s
 option shows a summary of the commit, instead of the full message.
+The
+.I -n count
+option stops printing messages after
+.I count
+messages.
 The
 .I -e expr
 option shows commits matching the query expression provided.
--- a/sys/src/cmd/git/log.c
+++ b/sys/src/cmd/git/log.c
@@ -14,6 +14,7 @@
 char	*queryexpr;
 char	*commitid;
 int	shortlog;
+int	msgcount;
 
 Objset	done;
 Objq	objq;
@@ -180,7 +181,7 @@
 
 	if((n = resolverefs(&h, q)) == -1)
 		sysfatal("resolve: %r");
-	for(i = 0; i < n; i++){
+	for(i = 0; i < n && msgcount-- > 0; i++){
 		if((o = readobject(h[i])) == nil)
 			sysfatal("read %H: %r", h[i]);
 		show(o);
@@ -206,7 +207,7 @@
 	qinit(&objq);
 	osinit(&done);
 	qput(&objq, o, 0);
-	while(qpop(&objq, &e)){
+	while(qpop(&objq, &e) && msgcount-- > 0){
 		show(e.o);
 		for(i = 0; i < e.o->commit->nparent; i++){
 			if(oshas(&done, e.o->commit->parent[i]))
@@ -242,6 +243,9 @@
 		break;
 	case 's':
 		shortlog++;
+		break;
+	case 'n':
+		msgcount = atoi(EARGF(usage()));
 		break;
 	default:
 		usage();