From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 361 invoked from network); 26 Apr 2022 13:18:19 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 26 Apr 2022 13:18:19 -0000 Received: from vultr.musolino.id.au ([45.76.123.158]) by 9front; Tue Apr 26 09:17:05 -0400 2022 Received: from 180.150.112.168 ([180.150.112.168]) by vultr; Tue Apr 26 23:16:55 +1000 2022 Message-ID: From: Alex Musolino Date: Tue, 26 Apr 2022 13:16:08 +0000 From: Alex Musolino To: 9front@9front.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: service storage just-in-time optimizer Subject: [9front] [PATCH] git/log: fix bugs in filtermatch Reply-To: 9front@9front.org Precedence: bulk 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; }