9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Ori Bernstein <ori@eigenstate.org>
To: 9front@9front.org
Subject: [9front] [PATCH] diff: retain original file names
Date: Sun, 22 May 2022 16:41:47 +0000	[thread overview]
Message-ID: <2FD13CB117DFE6893A17A959B97B8C03@eigenstate.org> (raw)


When diffing non-regular files, like /dev/null,
pipes, and similar, diff will generate a temp
file to diff against. This is the right thing
to do, but the temp file leaks into the diff.

This patch retains the original file name all
the way through to diff output.
---
diff 4649189126e1ad98f9a07afd078096227668bfd1 23f8872bc10fbe9ffd2b0067db1f91d8eaaabb40
--- a/sys/src/cmd/diff/diff.h	Sun May 22 12:34:33 2022
+++ b/sys/src/cmd/diff/diff.h	Sun May 22 12:41:47 2022
@@ -23,8 +23,8 @@
 void *erealloc(void *, unsigned);
 void diff(char *, char *, int);
 void diffdir(char *, char *, int);
-void diffreg(char *, char *);
-Biobuf *prepare(int, char *);
+void diffreg(char *, char *, char *, char *);
+Biobuf *prepare(int, char *, char *);
 void panic(int, char *, ...);
 void check(Biobuf *, Biobuf *);
 void change(int, int, int, int);
--- a/sys/src/cmd/diff/diffio.c	Sun May 22 12:34:33 2022
+++ b/sys/src/cmd/diff/diffio.c	Sun May 22 12:41:47 2022
@@ -104,7 +104,7 @@
 }
 
 Biobuf *
-prepare(int i, char *arg)
+prepare(int i, char *arg, char *orig)
 {
 	Line *p;
 	int j, h;
@@ -143,11 +143,10 @@
 	file[i] = p;
 	input[i] = bp;			/*fix*/
 	if (i == 0) {			/*fix*/
-		file1 = arg;
+		file1 = orig;
 		firstchange = 0;
-	}
-	else
-		file2 = arg;
+	} else
+		file2 = orig;
 	return bp;
 }
 
--- a/sys/src/cmd/diff/diffreg.c	Sun May 22 12:34:33 2022
+++ b/sys/src/cmd/diff/diffreg.c	Sun May 22 12:41:47 2022
@@ -363,16 +363,16 @@
 }
 
 void
-diffreg(char *f, char *t)
+diffreg(char *f, char *fo, char *t, char *to)
 {
 	Biobuf *b0, *b1;
 	int k;
 
 	binary = 0;
-	b0 = prepare(0, f);
+	b0 = prepare(0, f, fo);
 	if (!b0)
 		return;
-	b1 = prepare(1, t);
+	b1 = prepare(1, t, to);
 	if (!b1) {
 		Bterm(b0);
 		return;
--- a/sys/src/cmd/diff/main.c	Sun May 22 12:34:33 2022
+++ b/sys/src/cmd/diff/main.c	Sun May 22 12:41:47 2022
@@ -149,7 +149,7 @@
 			Bprint(&stdout, "Common subdirectories: %s and %s\n", fp, tp);
 	}
 	else if (REGULAR_FILE(fsb) && REGULAR_FILE(tsb))
-		diffreg(fp, tp);
+		diffreg(fp, f, tp, t);
 	else {
 		if (REGULAR_FILE(fsb)) {
 			if ((p = utfrrune(f, '/')) == 0)
@@ -157,14 +157,14 @@
 			else
 				p++;
 			if (mkpathname(tb, tp, p) == 0)
-				diffreg(fp, tb);
+				diffreg(fp, f, tb, t);
 		} else {
 			if ((p = utfrrune(t, '/')) == 0)
 				p = t;
 			else
 				p++;
 			if (mkpathname(fb, fp, p) == 0)
-				diffreg(fb, tp);
+				diffreg(fb, f, tp, t);
 		}
 	}
 	free(fsb);

             reply	other threads:[~2022-05-22 16:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-22 16:41 Ori Bernstein [this message]
2022-05-22 18:45 ` Jacob Moody
2022-05-22 23:24   ` ori

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=2FD13CB117DFE6893A17A959B97B8C03@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).