shithub: git9

Download patch

ref: da89a1d5963d37af44d6355cfa3bc38b9d8c38d3
parent: 01c7906a01cf127cf0721ca16908421dbe8ce736
author: Ori Bernstein <[email protected]>
date: Sun May 30 20:34:23 EDT 2021

git/branch: reduce execs to sync working dir

We were execing a lot to copy the data -- do less of it.

--- a/branch
+++ b/branch
@@ -63,10 +63,10 @@
 echo $commit > .git/$new
 if(! ~ $#stay 0)
 	exit
-
 basedir=`{git/query -p $base}
 dirtypaths=()
 cleanpaths=($modified $deleted)
+cleandirs=`$nl{echo $nl^$cleanpaths | sed 's@/[^/]+/?$@@' | uniq}
 if(! ~ $#modified 0 || ! ~ $#deleted 0)
 	dirtypaths=`$nl{git/walk -cfRMA $modified $deleted}
 if(! ~ $#dirtypaths 0){
@@ -73,22 +73,28 @@
 	x=$nl^$cleanpaths
 	y=$nl^$dirtypaths
 	cleanpaths=`$nl{echo $"x$nl$"y | sort | uniq -u}
+	cleandirs=`$nl{echo $nl^$cleanpaths | sed 's@/[^/]+/?$@@' | uniq}
 }
+if(! ~ $#cleandirs 0){
+	mkdir -p $cleandirs
+	mkdir -p .git/index9/tracked/$cleandirs
+}
 for(m in $cleanpaths){
-	d=`{basename -d $m}
-	mkdir -p $d
-	mkdir -p .git/index9/tracked/$d
 	# Modifications can turn a file into
 	# a directory, or vice versa, so we
 	# need to delete and copy the files
 	# over.
-	a=`{test -f $m && echo file || echo dir}
-	b=`{test -f $basedir/tree/$m && echo file || echo dir}
+	a=dir
+	b=dir
+	if(test -f $m)
+		a=file
+	if(test -f $basedir/tree/$m)
+		a=file
 	if(! ~ $a $b){
 		rm -rf $m
 		rm -rf .git/index9/tracked/$m
 	}
-	if(test -f $basedir/tree/$m){
+	if(~ $b file){
 		cp  $basedir/tree/$m $m
 		walk -eq $m > .git/index9/tracked/$m
 	}