diff: retain original file names
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.
This commit is contained in:
parent
1bb7aa60c4
commit
8eedca7656
4 changed files with 12 additions and 13 deletions
|
@ -23,8 +23,8 @@ void *emalloc(unsigned);
|
||||||
void *erealloc(void *, unsigned);
|
void *erealloc(void *, unsigned);
|
||||||
void diff(char *, char *, int);
|
void diff(char *, char *, int);
|
||||||
void diffdir(char *, char *, int);
|
void diffdir(char *, char *, int);
|
||||||
void diffreg(char *, char *);
|
void diffreg(char *, char *, char *, char *);
|
||||||
Biobuf *prepare(int, char *);
|
Biobuf *prepare(int, char *, char *);
|
||||||
void panic(int, char *, ...);
|
void panic(int, char *, ...);
|
||||||
void check(Biobuf *, Biobuf *);
|
void check(Biobuf *, Biobuf *);
|
||||||
void change(int, int, int, int);
|
void change(int, int, int, int);
|
||||||
|
|
|
@ -104,7 +104,7 @@ readhash(Biobuf *bp, char *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
Biobuf *
|
Biobuf *
|
||||||
prepare(int i, char *arg)
|
prepare(int i, char *arg, char *orig)
|
||||||
{
|
{
|
||||||
Line *p;
|
Line *p;
|
||||||
int j, h;
|
int j, h;
|
||||||
|
@ -143,11 +143,10 @@ prepare(int i, char *arg)
|
||||||
file[i] = p;
|
file[i] = p;
|
||||||
input[i] = bp; /*fix*/
|
input[i] = bp; /*fix*/
|
||||||
if (i == 0) { /*fix*/
|
if (i == 0) { /*fix*/
|
||||||
file1 = arg;
|
file1 = orig;
|
||||||
firstchange = 0;
|
firstchange = 0;
|
||||||
}
|
} else
|
||||||
else
|
file2 = orig;
|
||||||
file2 = arg;
|
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -363,16 +363,16 @@ cmp(Biobuf* b1, Biobuf* b2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
diffreg(char *f, char *t)
|
diffreg(char *f, char *fo, char *t, char *to)
|
||||||
{
|
{
|
||||||
Biobuf *b0, *b1;
|
Biobuf *b0, *b1;
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
binary = 0;
|
binary = 0;
|
||||||
b0 = prepare(0, f);
|
b0 = prepare(0, f, fo);
|
||||||
if (!b0)
|
if (!b0)
|
||||||
return;
|
return;
|
||||||
b1 = prepare(1, t);
|
b1 = prepare(1, t, to);
|
||||||
if (!b1) {
|
if (!b1) {
|
||||||
Bterm(b0);
|
Bterm(b0);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -149,7 +149,7 @@ diff(char *f, char *t, int level)
|
||||||
Bprint(&stdout, "Common subdirectories: %s and %s\n", fp, tp);
|
Bprint(&stdout, "Common subdirectories: %s and %s\n", fp, tp);
|
||||||
}
|
}
|
||||||
else if (REGULAR_FILE(fsb) && REGULAR_FILE(tsb))
|
else if (REGULAR_FILE(fsb) && REGULAR_FILE(tsb))
|
||||||
diffreg(fp, tp);
|
diffreg(fp, f, tp, t);
|
||||||
else {
|
else {
|
||||||
if (REGULAR_FILE(fsb)) {
|
if (REGULAR_FILE(fsb)) {
|
||||||
if ((p = utfrrune(f, '/')) == 0)
|
if ((p = utfrrune(f, '/')) == 0)
|
||||||
|
@ -157,14 +157,14 @@ diff(char *f, char *t, int level)
|
||||||
else
|
else
|
||||||
p++;
|
p++;
|
||||||
if (mkpathname(tb, tp, p) == 0)
|
if (mkpathname(tb, tp, p) == 0)
|
||||||
diffreg(fp, tb);
|
diffreg(fp, f, tb, t);
|
||||||
} else {
|
} else {
|
||||||
if ((p = utfrrune(t, '/')) == 0)
|
if ((p = utfrrune(t, '/')) == 0)
|
||||||
p = t;
|
p = t;
|
||||||
else
|
else
|
||||||
p++;
|
p++;
|
||||||
if (mkpathname(fb, fp, p) == 0)
|
if (mkpathname(fb, fp, p) == 0)
|
||||||
diffreg(fb, tp);
|
diffreg(fb, f, tp, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(fsb);
|
free(fsb);
|
||||||
|
|
Loading…
Reference in a new issue