code: plan9front

Download patch

ref: 31fc689ad948b897c459505479a08494120c344a
parent: 12e952e684d149628360b6fcdb583be86052f944
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 30 15:06:01 EDT 2021

git/branch: reduce execs to sync working dir

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

--- a/sys/src/cmd/git/branch
+++ b/sys/src/cmd/git/branch
@@ -63,32 +63,42 @@
 echo $commit > .git/$new
 if(! ~ $#stay 0)
 	exit
-
 basedir=`{git/query -p $base}
 dirtypaths=()
 cleanpaths=($modified $deleted)
-if(! ~ $#modified 0 || ! ~ $#deleted 0)
+if(! ~ $#modified 0 || ! ~ $#deleted 0){
+	echo WUT
 	dirtypaths=`$nl{git/walk -cfRMA $modified $deleted}
+}
 if(! ~ $#dirtypaths 0){
 	x=$nl^$cleanpaths
 	y=$nl^$dirtypaths
 	cleanpaths=`$nl{echo $"x$nl$"y | sort | uniq -u}
 }
+if(! ~ $#cleanpaths 0)
+	cleandirs=`$nl{echo $nl^$cleanpaths | sed 's@/[^/]+/?$@@' | uniq}
+if(! ~ $#cleandirs 0){
+	mkdir -p $cleandirs
+	mkdir -p .git/index9/tracked/$cleandirs
+}
+echo clean: $#clean
+echo dirty: $#dirty
 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)
+		b=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
 	}