* [9front] diff: request for some eyeballs/testing
@ 2024-08-05 6:23 ori
0 siblings, 0 replies; only message in thread
From: ori @ 2024-08-05 6:23 UTC (permalink / raw)
To: 9front
as a result of the recent 1oct1993 changes,
I discovered we don't currently handle file->dir
changes correctly in a bunch of our utilities;
diff, patch, and git are all a tad wonky when
it comes to this.
the first, er, diff to diff which should start
helping fix this is below -- it fixes both path
construction and makes it print a file deletion
and addition when a directory is involved in the
diff; patch should then have sufficient info to
apply the diff (though it currently doesn't handle
it correctly).
this fixes diff mis-constructing file paths,
diff 4c6701041ec241bbb900883043790af2fd5e8152 uncommitted
--- a/sys/src/cmd/diff/diffdir.c
+++ b/sys/src/cmd/diff/diffdir.c
@@ -19,14 +19,14 @@
int nitems;
int fd, n;
- if ((fd = open(name, OREAD)) < 0) {
+ cp = emalloc(sizeof(char*));
+ cp[0] = nil;
+ if(strcmp(name, "/dev/null") == 0)
+ return cp;
+ if((fd = open(name, OREAD)) < 0){
fprint(2, "%s: can't open %s: %r\n", argv0, name);
- /* fake an empty directory */
- cp = emalloc(sizeof(char*));
- cp[0] = 0;
return cp;
}
- cp = 0;
nitems = 0;
if((n = dirreadall(fd, &db)) > 0){
while (n--) {
@@ -44,18 +44,6 @@
return cp;
}
-static int
-isdotordotdot(char *p)
-{
- if (*p == '.') {
- if (!p[1])
- return 1;
- if (p[1] == '.' && !p[2])
- return 1;
- }
- return 0;
-}
-
void
diffdir(char *f, char *t, int level)
{
@@ -68,17 +56,11 @@
dt = scandir(t);
dirf = df;
dirt = dt;
+ if(level != 0 && !rflag)
+ return;
while (*df || *dt) {
from = *df;
to = *dt;
- if (from && isdotordotdot(from)) {
- df++;
- continue;
- }
- if (to && isdotordotdot(to)) {
- dt++;
- continue;
- }
if (!from)
res = 1;
else if (!to)
@@ -86,23 +68,30 @@
else
res = strcmp(from, to);
if (res < 0) {
- if (mode == 0 || mode == 'n')
+ if (mkpathname(fb, f, from))
+ continue;
+ if(rflag)
+ diff(fb, "/dev/null", level+1);
+ else if(mode == 0 || mode == 'n')
Bprint(&stdout, "Only in %s: %s\n", f, from);
df++;
- continue;
- }
- if (res > 0) {
+ }else if (res > 0){
+ if (mkpathname(tb, t, to))
+ continue;
+ if(rflag)
+ diff("/dev/null", tb, level+1);
if (mode == 0 || mode == 'n')
Bprint(&stdout, "Only in %s: %s\n", t, to);
dt++;
- continue;
+ }else{
+ if (mkpathname(fb, f, from))
+ continue;
+ if (mkpathname(tb, t, to))
+ continue;
+ diff(fb, tb, level+1);
+ df++;
+ dt++;
}
- if (mkpathname(fb, f, from))
- continue;
- if (mkpathname(tb, t, to))
- continue;
- diff(fb, tb, level+1);
- df++; dt++;
}
for (df = dirf; *df; df++)
free(*df);
@@ -115,7 +104,7 @@
void
diff(char *f, char *t, int level)
{
- char *fp, *tp, *p, fb[MAXPATHLEN+1], tb[MAXPATHLEN+1];
+ char *fp, *tp;
Dir *fsb, *tsb;
fsb = nil;
@@ -129,24 +118,15 @@
diffdir(fp, tp, level);
else
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, f, tp, t);
- else {
- if (REGULAR_FILE(fsb)) {
- if ((p = utfrrune(f, '/')) == 0)
- p = f;
- else
- p++;
- if (mkpathname(tb, tp, p) == 0)
- diffreg(fp, f, tb, t);
- } else {
- if ((p = utfrrune(t, '/')) == 0)
- p = t;
- else
- p++;
- if (mkpathname(fb, fp, p) == 0)
- diffreg(fb, f, tp, t);
+ }else{
+ if(REGULAR_FILE(fsb)){
+ diffreg(fp, f, "/dev/null", "/dev/null");
+ diffdir("/dev/null", tp, level);
+ }else{
+ diffdir(fp, "/dev/null", level);
+ diffreg("/dev/null", "/dev/null", tp, t);
}
}
Return:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-08-05 6:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-05 6:23 [9front] diff: request for some eyeballs/testing ori
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).