shithub: riscv

Download patch

ref: dd8a2d3964f430228dc00717e2055399593d30de
parent: d1acc5831683a713653255b27b1d42ef66825dfe
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jul 18 23:56:00 EDT 2022

git/log: only count the messages we show when limiting counts

when logging with `git/log -c count', we would count all messages
that we inspected, rather than just the ones that got printed.
This isn't what we should have done.

While we're in here, refactor show() to only show the message,
rather than filtering and then showing.

--- a/sys/src/cmd/git/log.c
+++ b/sys/src/cmd/git/log.c
@@ -64,7 +64,7 @@
 }
 
 int
-filtermatch1(Pfilt *pf, Object *t, Object *pt)
+matchesfilter1(Pfilt *pf, Object *t, Object *pt)
 {
 	Object *a, *b;
 	Hash ha, hb;
@@ -88,7 +88,7 @@
 			sysfatal("read %H: %r", ha);
 		if((b = readobject(hb)) == nil)
 			sysfatal("read %H: %r", hb);
-		r = filtermatch1(&pf->sub[i], a, b);
+		r = matchesfilter1(&pf->sub[i], a, b);
 		unref(a);
 		unref(b);
 		if(r)
@@ -98,11 +98,12 @@
 }
 
 int
-filtermatch(Object *o)
+matchesfilter(Object *o)
 {
 	Object *t, *p, *pt;
 	int i, r;
 
+	assert(o->type == GCommit);
 	if(pathfilt == nil)
 		return 1;
 	if((t = readobject(o->commit->tree)) == nil)
@@ -112,7 +113,7 @@
 			sysfatal("read %H: %r", o->commit->parent[i]);
 		if((pt = readobject(p->commit->tree)) == nil)
 			sysfatal("read %H: %r", o->commit->tree);
-		r = filtermatch1(pathfilt, t, pt);
+		r = matchesfilter1(pathfilt, t, pt);
 		unref(p);
 		unref(pt);
 		if(r)
@@ -131,7 +132,7 @@
 	return p;
 }
 
-static void
+static int
 show(Object *o)
 {
 	Tm tm;
@@ -138,9 +139,6 @@
 	char *p, *q, *e;
 
 	assert(o->type == GCommit);
-	if(!filtermatch(o))
-		return;
-
 	if(shortlog){
 		p = o->commit->msg;
 		e = p + o->commit->nmsg;
@@ -170,6 +168,7 @@
 		Bprint(out, "\n");
 	}
 	Bflush(out);
+	return 1;
 }
 
 static void
@@ -181,10 +180,14 @@
 
 	if((n = resolverefs(&h, q)) == -1)
 		sysfatal("resolve: %r");
-	for(i = 0; i < n && (msgcount == -1 || msgcount-- > 0); i++){
+	for(i = 0; i < n && (msgcount == -1 || msgcount > 0); i++){
 		if((o = readobject(h[i])) == nil)
 			sysfatal("read %H: %r", h[i]);
-		show(o);
+		if(matchesfilter(o)){
+			show(o);
+			if(msgcount != -1)
+				msgcount--;
+		}
 		unref(o);
 	}
 	exits(nil);
@@ -207,8 +210,12 @@
 	qinit(&objq);
 	osinit(&done);
 	qput(&objq, o, 0);
-	while(qpop(&objq, &e) && (msgcount == -1 || msgcount-- > 0)){
-		show(e.o);
+	while(qpop(&objq, &e) && (msgcount == -1 || msgcount > 0)){
+		if(matchesfilter(e.o)){
+			show(e.o);
+			if(msgcount != -1)
+				msgcount--;
+		}
 		for(i = 0; i < e.o->commit->nparent; i++){
 			if(oshas(&done, e.o->commit->parent[i]))
 				continue;