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=T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3587 invoked from network); 28 May 2022 22:17:00 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 28 May 2022 22:17:00 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 9front; Sat May 28 18:16:02 -0400 2022 Received: from stockyard (cpe-68-174-86-38.nyc.res.rr.com [68.174.86.38]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 104b51c9 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Sat, 28 May 2022 15:15:54 -0700 (PDT) Message-ID: <79D7A1463120367C9148BF05B1160617@eigenstate.org> To: 9front@9front.org Date: Sat, 28 May 2022 18:15:52 -0400 From: ori@eigenstate.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 configuration control Subject: [9front] diff: avoid empty hunks when there are no changes Reply-To: 9front@9front.org Precedence: bulk Currently, diff outputs a file header, even if there are no changes to the file. This is wonky. It means that the header chunks are ambiguous, since not all header chunks are followed by '@@ hunk', and '--- file', '+++ file' lines can be generated from file content. This changes the way that we decide to print the file header, so we only print it when outputting the first hunk on flushchanges. Flushchanges is called once per regular file, at the end of `diffreg`, so we output a hunk header once per file. diff b75e549126641108880a24a4ff0b38171eb1a856 uncommitted --- a/sys/src/cmd/diff/diff.h +++ b/sys/src/cmd/diff/diff.h @@ -28,6 +28,5 @@ void panic(int, char *, ...); void check(Biobuf *, Biobuf *); void change(int, int, int, int); -void fileheader(void); void flushchanges(void); --- a/sys/src/cmd/diff/diffio.c +++ b/sys/src/cmd/diff/diffio.c @@ -330,23 +330,17 @@ } void -fileheader(void) -{ - if(mode != 'u') - return; - Bprint(&stdout, "--- %s\n", file1); - Bprint(&stdout, "+++ %s\n", file2); -} void flushchanges(void) { - int a, b, c, d, at; + int a, b, c, d, at, hdr; int i, j; if(nchanges == 0) return; - + + hdr = 0; for(i=0; i