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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 21635 invoked from network); 5 Nov 2021 19:04:51 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 5 Nov 2021 19:04:51 -0000 Received: from mail-pg1-f182.google.com ([209.85.215.182]) by 4ess; Fri Nov 5 15:00:41 -0400 2021 Received: by mail-pg1-f182.google.com with SMTP id p17so9122917pgj.2 for <9front@9front.org>; Fri, 05 Nov 2021 12:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:message-id:mime-version:content-disposition; bh=tC4Pun2HTCKFYS5QeAx2FsSbQY/5WhrkdJbJ+nhtdTc=; b=oSVrM4EKN5ndkijw9qfgqb9XzNUCO3YeK/RhtKC1Iwd8OTMQpMa6AlaCdOKZ3+pIKm 8gqBzbYKQ6pa9w2cp7QpOWRBP06JLsA3cpDnsmOAf/Dwon/7NZD0gd41IqARGlK2TDeb vBjzcn9n2s3Txay0t7e2gdcvkmPJdNJLRB0Nd5ul6cFWotuFROLWliZu6FpPYy9NK43m kFAFcFeXXAv+GCI3/Pe8pb69L+0ttDzFzexH8zSTgTQNHmLsM4kKSV2z+vtlbopqy/zx Ge/cBgaozrY0e06qLLYWnRIsI1T1gL/OW9vk9lEBhdx2HAf4vrPM46/aM63+LutHgBzq HSRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=tC4Pun2HTCKFYS5QeAx2FsSbQY/5WhrkdJbJ+nhtdTc=; b=kvICyEithT0Q2nY6pYg280ryvVMyHHGRWmpry9r+o7qQ5h7X0Xeh8MGJYLgE9Cf5g7 NHeR/BHQDU7fyEsfyQ/MHlN6DQ2tbbmymMg/ZWMaPAJnV1Hb1nUaGS0Ec2SaBx4jmXyw Fl8awV7gUaGi/IqwKGt+t9hHUAa0Ww9Rjefx+yX6XEBk9/WH9D36UgkN4T1Ry53bCM9t x7Vjb43nDAR/QkH6BkzXc/bX+B57gk1PqXFf2lOsK2bphhrcvehxaKIueb975GQ9+1DW h4O0+Wl4bqChpjBihs340ve3kjLJ9qSAIBukBm74A4FHND0FCHIT8FhwGyots297gi1r CxMA== X-Gm-Message-State: AOAM530BWXDv0IEy8LhCAXbCfEZ7sXnn6j/VgGmpU2iDVrugqkmI1AYx InnLCiYBlwVomYD4UBgP1S5fSVy0NqI= X-Google-Smtp-Source: ABdhPJx0Bl0WaolHV8gYLaqcifgw/qjtC3dfSumORibH3j7w+Y5vvfItNUoxZA0+RflIwJasFW68Qw== X-Received: by 2002:aa7:8d17:0:b0:44d:3593:2c1a with SMTP id j23-20020aa78d17000000b0044d35932c1amr61251468pfe.3.1636134678409; Fri, 05 Nov 2021 10:51:18 -0700 (PDT) Return-Path: Received: from imac.0x30.net (d205-250-121-157.bchsia.telus.net. [205.250.121.157]) by smtp.gmail.com with ESMTPSA id mm22sm6779865pjb.28.2021.11.05.10.51.17 for <9front@9front.org> (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 Nov 2021 10:51:17 -0700 (PDT) Date: Fri, 5 Nov 2021 10:51:15 -0700 From: Kyle Milz To: 9front@9front.org Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="diff_u_identical.diff" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: leveraged ISO-certified GPU DOM optimizer Subject: [9front] diff(1): fix -u when comparing identical files Reply-To: 9front@9front.org Precedence: bulk hi, i notice when comparing identical files with diff -u the header is always printed: % diff -u /dev/null /dev/null --- /tmp/diff100000021006 +++ /tmp/diff200000021006 i dont think this is correct and is not consistent with other diff formats like -c. i think the header should be printed only when there is at least one change (diff hunk), and only before the first change in a given file. it look like change() in diffio.c is only called when there is at least one change, and it already keeps track if the first change has been seen already. diff below moves the -u header printing into change() under the 'firstchange' condition. ive been testing this for a few days under different conditions and it has been working well: % diff -u /dev/null /dev/null % indeed the diff -u below was created with the diff below applied. kyle diff e2e4a46f26ff7268a696a45d82414fb992b648d5 uncommitted --- a/sys/src/cmd/diff/diff.h +++ b/sys/src/cmd/diff/diff.h @@ -22,6 +22,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 @@ -267,16 +267,22 @@ if (a > b && c > d) return; anychange = 1; - if (mflag && firstchange == 0) { - if(mode) { - buf[0] = '-'; - buf[1] = mode; - buf[2] = ' '; - buf[3] = '\0'; - } else { - buf[0] = '\0'; + if (firstchange == 0) { + if (mflag) { + if(mode) { + buf[0] = '-'; + buf[1] = mode; + buf[2] = ' '; + buf[3] = '\0'; + } else { + buf[0] = '\0'; + } + Bprint(&stdout, "diff %s%s %s\n", buf, file1, file2); } - Bprint(&stdout, "diff %s%s %s\n", buf, file1, file2); + if (mode == 'u') { + Bprint(&stdout, "--- %s\n", file1); + Bprint(&stdout, "+++ %s\n", file2); + } firstchange = 1; } verb = a > b ? 'a': c > d ? 'd': 'c'; @@ -337,15 +343,6 @@ if(i