9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] git/save: allow files to become dirs
@ 2024-08-05  6:44 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2024-08-05  6:44 UTC (permalink / raw)
  To: 9front

git code assumed that a file, once checked in, would always
be a file; this changes the code to lift that assumption;
again, reviews and testing would be appreciated.

diff 4c6701041ec241bbb900883043790af2fd5e8152 uncommitted
--- a/sys/src/cmd/git/save.c
+++ b/sys/src/cmd/git/save.c
@@ -243,8 +243,10 @@
 		for(ep = p; ep != epath; ep++){
 			if(strncmp(elt, *ep + off, ne) != 0)
 				break;
-			if((*ep)[off+ne] != '\0' && (*ep)[off+ne] != '/')
+			if(!isdir && (*ep)[off+ne] != '\0')
 				break;
+			if(isdir && (*ep)[off+ne] != '/')
+				break;
 		}
 		e = dirent(&ent, &nent, elt);
 		if(e->islink)
@@ -251,6 +253,7 @@
 			sysfatal("symlinks may not be modified: %s", *path);
 		if(e->ismod)
 			sysfatal("submodules may not be modified: %s", *path);
+		d = dirstat(*p);
 		if(isdir){
 			e->mode = DMDIR | 0755;
 			sub[nsub] = readobject(e->h);
@@ -270,19 +273,17 @@
 			else if(n == -1)
 				goto err;
 		}else{
-			d = dirstat(*p);
-			if(d != nil && tracked(*p))
+			if(d != nil && !(d->mode & DMDIR) && tracked(*p))
 				blobify(d, *p, &e->mode, &e->h);
 			else
 				e->name = nil;
-			free(d);
 		}
+		free(d);
 	}
 	if(nent == 0){
 		werrstr("%.*s: empty directory", off, *path);
 		goto err;
 	}
-
 	r = writetree(ent, nent, h);
 err:
 	free(sub);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-05  6:48 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:44 [9front] git/save: allow files to become dirs 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).