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 23524 invoked from network); 7 Oct 2022 18:10:55 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 7 Oct 2022 18:10:55 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 9front; Fri Oct 7 14:09:48 -0400 2022 Received: from abbatoir (pool-108-27-53-161.nycmny.fios.verizon.net [108.27.53.161]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id b94a59c1 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Fri, 7 Oct 2022 11:09:45 -0700 (PDT) Message-ID: <0F5FA97017BDFEF80BBBAE2985BBA4EB@eigenstate.org> To: 9front@9front.org Date: Fri, 07 Oct 2022 14:09:44 -0400 From: ori@eigenstate.org In-Reply-To: <08EFF1FAF1422A02191E5789046BEA99@mforney.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: transactional shared reduce/map engine Subject: Re: [9front] [PATCH] patch: fix consecutive deletions Reply-To: 9front@9front.org Precedence: bulk Quoth Michael Forney : > > Consecutive delete hunks will both have newpath of /dev/null, but we > need to slurp oldpath between these hunks. > --- > Proposed fix for the issue I reported on the mailing list a few days > ago. This retains the current patch file selection behavior, though I > still think we should adopt the standard behavior for compatibility > with external patches and tools. Looks good to me. Changing our current behavior should be painless -- nothing currently should depend on it; git/patch is the heaviest user, and it hasn't been around long enough for a long tail of external scripts to care. > diff 8f1867a19f7ca881a32878dcee08ddce11b5db36 185bd356498369a987e364293f3942e047b99f48 > --- a/sys/src/cmd/patch.c > +++ b/sys/src/cmd/patch.c > @@ -556,9 +556,9 @@ > int > apply(Patch *p, char *fname) > { > - char *o, *s, *e, *curfile; > + char *o, *s, *e, *curfile, *nextfile; > int i, osz; > - Hunk *h; > + Hunk *h, *prevh; > Fbuf f; > > e = nil; > @@ -565,14 +565,26 @@ > o = nil; > osz = 0; > curfile = nil; > + h = nil; > + prevh = nil; > for(i = 0; i < p->nhunk; i++){ > h = &p->hunk[i]; > - if(curfile == nil || strcmp(curfile, h->newpath) != 0){ > + if(strcmp(h->newpath, "/dev/null") == 0) > + nextfile = h->oldpath; > + else > + nextfile = h->newpath; > + if(curfile == nil || strcmp(curfile, nextfile) != 0){ > + if(curfile != nil){ > + if(!dryrun) > + o = append(o, &osz, e, f.buf + f.len); > + blat(prevh->oldpath, prevh->newpath, o, osz); > + osz = 0; > + } > if(!dryrun){ > slurp(&f, h->oldpath); > e = f.buf; > } > - curfile = h->newpath; > + curfile = nextfile; > } > if(!dryrun){ > s = e; > @@ -581,12 +593,12 @@ > o = append(o, &osz, h->new, h->new + h->newlen); > e += h->oldlen; > } > - if(i+1 == p->nhunk || strcmp(curfile, p->hunk[i+1].newpath) != 0){ > - if(!dryrun) > - o = append(o, &osz, e, f.buf + f.len); > - blat(h->oldpath, h->newpath, o, osz); > - osz = 0; > - } > + prevh = h; > + } > + if(curfile != nil){ > + if(!dryrun) > + o = append(o, &osz, e, f.buf + f.len); > + blat(h->oldpath, h->newpath, o, osz); > } > free(o); > return 0;