From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] diff: request for some eyeballs/testing
Date: Mon, 05 Aug 2024 02:23:38 -0400 [thread overview]
Message-ID: <4C539264EE17F49630F4A09810EE9E53@eigenstate.org> (raw)
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:
reply other threads:[~2024-08-05 6:28 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=4C539264EE17F49630F4A09810EE9E53@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).