From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] diff: avoid empty hunks when there are no changes
Date: Sat, 28 May 2022 18:15:52 -0400 [thread overview]
Message-ID: <79D7A1463120367C9148BF05B1160617@eigenstate.org> (raw)
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<nchanges; ){
j = changeset(i);
a = changes[i].a-Lines;
@@ -369,6 +363,11 @@
j = nchanges;
}
if(mode == 'u'){
+ if(!hdr){
+ Bprint(&stdout, "--- %s\n", file1);
+ Bprint(&stdout, "+++ %s\n", file2);
+ hdr = 1;
+ }
Bprint(&stdout, "@@ -%d,%d +%d,%d @@\n", a, b-a+1, c, d-c+1);
}else{
Bprint(&stdout, "%s:", file1);
--- a/sys/src/cmd/diff/diffreg.c
+++ b/sys/src/cmd/diff/diffreg.c
@@ -284,7 +284,6 @@
m = len[0];
J[0] = 0;
J[m+1] = len[1]+1;
- fileheader();
if (mode != 'e') {
for (i0 = 1; i0 <= m; i0 = i1+1) {
while (i0 <= m && J[i0] == J[i0-1]+1)
reply other threads:[~2022-05-28 22:17 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=79D7A1463120367C9148BF05B1160617@eigenstate.org \
--to=ori@eigenstate.org \
--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).