summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2022-07-03 04:38:13 +0000
committerOri Bernstein <ori@eigenstate.org>2022-07-03 04:38:13 +0000
commit21aac62c1f0fa565a860d4880ec56b84eb9dd8dd (patch)
treec095e06aea6160188a9f8c61141b986c52735c91
parentd457233c70ef6aa28861dd2978e92968ffba0920 (diff)
git/log: support -n option to restrict log counts
this is useful for scripting, and convenient for interactive use.
-rw-r--r--sys/man/1/git9
-rw-r--r--sys/src/cmd/git/log.c8
2 files changed, 15 insertions, 2 deletions
diff --git a/sys/man/1/git b/sys/man/1/git
index 5f1e7cef6..d4681e273 100644
--- a/sys/man/1/git
+++ b/sys/man/1/git
@@ -96,6 +96,10 @@ git/pull, git/rm, git/serve
.I expr
]
[
+.B -n
+.I count
+]
+[
.B -s
]
[
@@ -384,6 +388,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.
The expression is in the syntax of
diff --git a/sys/src/cmd/git/log.c b/sys/src/cmd/git/log.c
index a06c427d0..ac60a7d4d 100644
--- a/sys/src/cmd/git/log.c
+++ b/sys/src/cmd/git/log.c
@@ -14,6 +14,7 @@ Biobuf *out;
char *queryexpr;
char *commitid;
int shortlog;
+int msgcount;
Objset done;
Objq objq;
@@ -180,7 +181,7 @@ showquery(char *q)
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 @@ showcommits(char *c)
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]))
@@ -243,6 +244,9 @@ main(int argc, char **argv)
case 's':
shortlog++;
break;
+ case 'n':
+ msgcount = atoi(EARGF(usage()));
+ break;
default:
usage();
break;