9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] git/log: fix bugs in filtermatch
@ 2022-04-26 13:16 Alex Musolino, Alex Musolino
  0 siblings, 0 replies; only message in thread
From: Alex Musolino, Alex Musolino @ 2022-04-26 13:16 UTC (permalink / raw)
  To: 9front


Previously, commits with no parents would always match
even if they did not contain any of the files we had
listed on the command line.

This change also unrefs a tree object that was being
leaked in each call to filtermatch.
---
diff 99d69b52b3fa59b3c4414f1d3a711b3ba18ef52e 03b3300a2b2cd1cba994f219b6462bfe1ddce01f
--- a/sys/src/cmd/git/log.c	Sun Apr 24 12:21:46 2022
+++ b/sys/src/cmd/git/log.c	Tue Apr 26 22:46:08 2022
@@ -56,9 +56,11 @@
 {
 	int i;
 
-	for(i = 0; i < o->tree->nent; i++)
-		if(strcmp(o->tree->ent[i].name, pf->elt) == 0)
-			return o->tree->ent[i].h;
+	if(o){
+		for(i = 0; i < o->tree->nent; i++)
+			if(strcmp(o->tree->ent[i].name, pf->elt) == 0)
+				return o->tree->ent[i].h;
+	}
 	return Zhash;
 }
 
@@ -71,22 +73,23 @@
 
 	if(pf->show)
 		return 1;
-	if(t->type != pt->type)
+	if(pt && pt->type != t->type)
 		return 1;
 	if(t->type != GTree)
 		return 0;
 
+	b = nil;
 	for(i = 0; i < pf->nsub; i++){
 		ha = lookup(&pf->sub[i], t);
 		hb = lookup(&pf->sub[i], pt);
 		if(hasheq(&ha, &hb))
 			continue;
-		if(hasheq(&ha, &Zhash) || hasheq(&hb, &Zhash))
+		if(hasheq(&ha, &Zhash) || (pt != nil && hasheq(&hb, &Zhash)))
 			return 1;
 		if((a = readobject(ha)) == nil)
 			sysfatal("read %H: %r", ha);
-		if((b = readobject(hb)) == nil)
-			sysfatal("read %H: %r", hb);
+		if(pt != nil && (b = readobject(hb)) == nil)
+				sysfatal("read %H: %r", hb);
 		r = filtermatch1(&pf->sub[i], a, b);
 		unref(a);
 		unref(b);
@@ -100,6 +103,7 @@
 filtermatch(Object *o)
 {
 	Object *t, *p, *pt;
+	Hash h;
 	int i, r;
 
 	if(pathfilt == nil)
@@ -115,9 +119,13 @@
 		unref(p);
 		unref(pt);
 		if(r)
-			return 1;
+			goto Done;
 	}
-	return o->commit->nparent == 0;
+	if(o->commit->nparent == 0)
+		r = filtermatch1(pathfilt, t, nil);
+Done:
+	unref(t);
+	return r;
 }
 
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-26 13:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 13:16 [9front] [PATCH] git/log: fix bugs in filtermatch Alex Musolino, Alex Musolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).