From: Alex Musolino <alex@musolino.id.au>
From: Alex Musolino <alex@musolino.id.au>
To: 9front@9front.org
Subject: [9front] [PATCH] git/log: fix bugs in filtermatch
Date: Tue, 26 Apr 2022 13:16:08 +0000 [thread overview]
Message-ID: <E8C4E15A4AE4C69E697D56E202F7942F@musolino.id.au> (raw)
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;
}
reply other threads:[~2022-04-26 13:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E8C4E15A4AE4C69E697D56E202F7942F@musolino.id.au \
--to=alex@musolino.id.au \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).