shithub: git9

Download patch

ref: 4eda12bdbcc8fe7acc4a2a81499ff853e64b1c4a
parent: 0f064279e7a15c16894fb3527d96f78b0aa0f550
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Oct 22 15:16:53 EDT 2019

Make git/query more specific about what changed between commits.

--- a/branch
+++ b/branch
@@ -22,6 +22,7 @@
 stay=()
 create=()
 update=()
+delete=()
 base=`{awk '$1=="branch"{print $2}' < /mnt/git/ctl}
 while(~ $1 -* && ! ~ $1 --){
 	switch($1){
@@ -29,6 +30,7 @@
 	case -s; stay=true
 	case -b; shift; base=$1
 	case -u; update=true
+	case -d; delete=true
 	case *
 		usage
 	}
@@ -50,7 +52,12 @@
 if not
 	new=refs/heads/$1
 
-if(! git/walk -q `{git/query -c HEAD $base | sed 's/^..//g'}){
+if(! ~ $#delete 0){
+	rm -f .git/$new
+	exit
+}
+
+if(! git/walk -q `{git/query -c HEAD $base | sed 's/^..//'}){
 	echo remote changes would clobber local changes >[1=2]
 	exit dirty
 }
@@ -68,21 +75,20 @@
 	}
 	branched=()
 	remotes=`$nl{cd .git/refs/remotes && ls}
-	candidates=(.git/refs/$base .git/refs/heads/$base .git/refs/remotes/$base .git/refs/remotes/$remotes/$base)
-	for(br in $candidates){
-		if(~ $#branched 0 && test -f $br){
-			cp $br .git/$new
-			branched=true
-		}
-	}
-	if(~ $#branched 0){
-		echo 'could not find branch '$base >[1=2]
+	commit=`{git/query $base}
+	st=$status
+	if(! ~ $st ''){
+		echo could not find branch $base':' $st >[1=2]
 		exit notfound
-	}
+	}	
+	echo $commit > .git/$new
 }
 
-modified=`$nl{git/query -c $new $base | grep '^[+~]' | sed 's/^..//'}
-deleted=`$nl{git/query -c $new $base | grep '^-' | sed 's/^..//'}
+
+modified=`$nl{git/query -c HEAD $new | grep '^[+!@]' | sed 's/^..//'}
+deleted=`$nl{git/query -c HEAD $new | grep '^-' | sed 's/^..//'}
+
+echo $deleted
 
 if(! ~ $#stay 0)
 	exit
--- a/query.c
+++ b/query.c
@@ -44,19 +44,26 @@
 		bp = b->tree->ent;
 		be = bp + b->tree->nent;
 		while(ap != ae && bp != be){
+			print("cmp %s %s\n", ap->name, bp->name);
 			c = strcmp(ap->name, bp->name);
 			if(c == 0){
-				if(ap->mode != bp->mode || !hasheq(&ap->h, &bp->h)) {
-					if(!(ap->mode & DMDIR) || !(bp->mode & DMDIR))
-						print("~ %P%s\n", ap->name);
-					if(ap->mode & DMDIR || bp->mode & DMDIR){
-						if(npath >= nelem(path))
+				if(ap->mode == bp->mode && hasheq(&ap->h, &bp->h))
+					goto next;
+
+				if(ap->mode != bp->mode){
+					print("mode: %o -> %o\n", ap->mode, bp->mode);
+					print("! %P%s\n", ap->name);
+				}
+				else if(!(ap->mode & DMDIR) || !(bp->mode & DMDIR))
+					print("@ %P%s\n", ap->name);
+				if((ap->mode & DMDIR) && (bp->mode & DMDIR)){
+					if(npath >= nelem(path))
 						sysfatal("path too deep");
-						path[npath++] = ap->name;
-						difftrees(ap->h, bp->h);
-						npath--;
-					}
+					path[npath++] = ap->name;
+					difftrees(ap->h, bp->h);
+					npath--;
 				}
+next:
 				ap++;
 				bp++;
 			}else if(c < 0){