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.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 9896 invoked from network); 3 Oct 2022 19:36:47 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 3 Oct 2022 19:36:47 -0000 Received: from mail-il1-f177.google.com ([209.85.166.177]) by 9front; Mon Oct 3 15:35:00 -0400 2022 Received: by mail-il1-f177.google.com with SMTP id y17so1600204ilq.8 for <9front@9front.org>; Mon, 03 Oct 2022 12:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mforney.org; s=google; h=content-transfer-encoding:mime-version:to:subject:date:from :message-id:from:to:cc:subject:date; bh=IoCFFval/F5wb/jiA1rRpnHka1ChaC448FWmQUfeU/E=; b=r3KGJgDfqoQnVRStvCeu9pgGXXb/hP7CaNnLpwNlc7cO+AvpA6TKEatPpGfS8kFuaF IsP72honwwYAf+e8cWJngtqGsBvmh6OgyLy3vk3b96R2YF/Xdzc7qaockkG7XM+Rnil+ DU4JeN+B4ypbwgeIblzjRwuWTQ8Kz3LWi0T4e7sq6aV98Vg6fPSGlBKoNQKjWOH1LiCp YADzTDrqsVo4IKrQjFxvdUDFL4I9pdJSkb31FrnymZT7m3MrIwKEjURo33ilcIjN/emn NE2inG/Cgvv885Jg2PqZpNiJYSPJUxisrdhJcnU2tikaHw/Qz450w7ynYoDGYVMibmIq c0Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:to:subject:date:from :message-id:x-gm-message-state:from:to:cc:subject:date; bh=IoCFFval/F5wb/jiA1rRpnHka1ChaC448FWmQUfeU/E=; b=SYVeNkvWTJ6ph0iXQFQR1cF/MFix82+mlGWhCh7D2Vr9GOxOe8s37dI48yMr0YPo2M CE3+jAnegVuJclT3Qadh2Eniep2kiWOwGsFImIuk3pfbyKJq2J3adc0HAP/MkeiHUyi4 O2iaN4kYVJ/2GVu+BP/1rOpCCbIr6y+VFlQ1hAlXT7nyDPumYI6ig/EpdHnvu08BcZYj cSHZJ/tRbng4GvppbhKUXzQTWK2+I6wVloJd2sNdg1YsycpZSZNtORs0fMUHXs+Drteh 6HanasIiI92X2tDm6GPncvaG+Zo7NMrQm/V2Ai/A/QTvSrrRthKdn2wd776qyuK4vs0e 7PFQ== X-Gm-Message-State: ACrzQf323xdN6U+yEPJbofnMPfAErAyA18p72NPNcu6WVMq56vw0DpUb KNh4rzZsrTsKHWDK0/WRDlM3lpFrvnUNklex X-Google-Smtp-Source: AMsMyM4P7dnMe+Q+XIIG03S/mu4h2MCNxOnShpReaHksp9w65zSpG+D06dql9r4kOYOxXq8wAxpqQw== X-Received: by 2002:a92:d28b:0:b0:2f9:95e5:fae6 with SMTP id p11-20020a92d28b000000b002f995e5fae6mr4245307ilp.313.1664825696438; Mon, 03 Oct 2022 12:34:56 -0700 (PDT) Return-Path: Received: from novus ([64.93.113.86]) by smtp.gmail.com with ESMTPSA id m127-20020a6b3f85000000b006a4e07e6c90sm4864588ioa.34.2022.10.03.12.34.55 for <9front@9front.org> (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Oct 2022 12:34:55 -0700 (PDT) Message-ID: <08EFF1FAF1422A02191E5789046BEA99@mforney.org> From: Michael Forney Date: Mon, 03 Oct 2022 19:32:17 +0000 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: structured shared interface CSS-aware database Subject: [9front] [PATCH] patch: fix consecutive deletions Reply-To: 9front@9front.org Precedence: bulk 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. 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;