9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] git/save: allow files to become dirs
Date: Mon, 05 Aug 2024 02:44:29 -0400	[thread overview]
Message-ID: <47FCF56C2AE1929317E1F73F7D248F97@eigenstate.org> (raw)

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);


                 reply	other threads:[~2024-08-05  6:48 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=47FCF56C2AE1929317E1F73F7D248F97@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).