shithub: git9

Download patch

ref: 22a4ca0f360a36a4a0927844e4d41e0845614826
parent: 9bcfa173b66507cf728023aedc39f73ec23d246a
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Feb 7 12:57:03 EST 2020

removing tracked should implicitly untrack them.

--- a/commit
+++ b/commit
@@ -80,7 +80,7 @@
 	echo $branch: $hash
 	echo $hash > $refpath
 	for(f in $files){
-		if(test -e .git/index9/removed/$f){
+		if(test -e .git/index9/removed/$f || ! test -e $f){
 			rm -f .git/index9/removed/$f
 			rm -f .git/index9/tracked/$f
 		}
--- a/save.c
+++ b/save.c
@@ -160,14 +160,11 @@
 }
 
 void
-blobify(char *path, int *mode, Hash *bh)
+blobify(Dir *d, char *path, int *mode, Hash *bh)
 {
 	char h[64], *buf;
 	int f, nh;
-	Dir *d;
 
-	if((d = dirstat(path)) == nil)
-		sysfatal("could not stat %s: %r", path);
 	if((d->mode & DMDIR) != 0)
 		sysfatal("not file: %s", path);
 	*mode = d->mode;
@@ -179,15 +176,14 @@
 		sysfatal("could not read blob %s: %r", path);
 	writeobj(bh, h, nh, buf, d->length);
 	free(buf);
-	free(d);
 	close(f);
 }
 
 int
-tracked(char *path, int *explicit)
+tracked(char *path)
 {
-	Dir *d;
 	char ipath[256];
+	Dir *d;
 
 	/* Explicitly removed. */
 	snprint(ipath, sizeof(ipath), ".git/index9/removed/%s", path);
@@ -206,8 +202,6 @@
 	if(access(ipath, AEXIST) == 0)
 		return 1;
 
-	/* unknown */
-	*explicit = 0;
 	return 0;
 }
 
@@ -244,11 +238,12 @@
 int
 treeify(Object *t, char **path, char **epath, int off, Hash *h)
 {
-	int r, ne, nsub, nent, isdir, untrack;
+	int r, ne, nsub, nent, isdir;
 	char **p, **ep;
 	char elt[256];
 	Object **sub;
 	Dirent *e, *ent;
+	Dir *d;
 
 	r = -1;
 	nsub = 0;
@@ -273,12 +268,12 @@
 			if(treeify(sub[nsub], p, ep, off + ne + 1, &e->h) == -1)
 				goto err;
 		}else{
-			if(tracked(*p, &untrack))
-				blobify(*p, &e->mode, &e->h);
-			else if(untrack)
-				e->name = nil;
+			d = dirstat(*p);
+			if(d != nil && tracked(*p))
+				blobify(d, *p, &e->mode, &e->h);
 			else
-				sysfatal("untracked file %s", *p);
+				e->name = nil;
+			free(d);
 		}
 	}
 	if(nent == 0){
--- a/walk.c
+++ b/walk.c
@@ -295,8 +295,8 @@
 		rpath = smprint(RDIR"/%s", p);
 		tpath = smprint(TDIR"/%s", p);
 		bpath = smprint(HDIR"/%s", p);
-		if(access(rpath, AEXIST) == 0){
-			dirty |= Mflg;
+		if(d == nil || access(rpath, AEXIST) == 0){
+			dirty |= Rflg;
 			if(!quiet && (printflg & Rflg))
 				print("%s%s\n", rstr, p);
 		}else if(access(bpath, AEXIST) == -1) {