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

this is useful for scripting, and convenient for
interactive use.
This commit is contained in:
Ori Bernstein 2022-07-03 04:38:13 +00:00
parent d457233c70
commit 21aac62c1f
2 changed files with 15 additions and 2 deletions

View file

@ -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

View file

@ -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;