![Ori Bernstein](/assets/img/avatar_default.png)
Git currently gets a bit confused if you try to manipulate files by absolute path. There were also a number of places where user-controlled file paths ended up getting passed to regex interpretation, which could confuse things. This change mainly does 2 things: - Adds a 'drop' function which drops a non-regex prefix from a string, and uses that to manipulate paths, simplifies 'subst', and removes 'subst -g', which was only used with fixed regexes; sed does this job fine. - When getting a path from a user, we make it absolute and then strip out the head Along the way it cleans up a couple of stupids: - 'for(f in $list) if(! ~ $#f 0) use $f: $f can't be a nil list because of list flattening. - removes a useless substitution here: all=`$nl{{git/query -c $1 $2; git/query -c $2 $3} | sed 's/^..//' | \ gsubst '^('$ourbr'|'$basebr'|'$theirbr')/*' | sort | uniq} where git/query -c doesn't produce paths prefixed with the query.
39 lines
749 B
Bash
Executable file
39 lines
749 B
Bash
Executable file
#!/bin/rc -e
|
|
rfork ne
|
|
. /sys/lib/git/common.rc
|
|
|
|
gitup
|
|
|
|
flagfmt='r:remove'; args='file ...'
|
|
eval `''{aux/getflags $*} || exec aux/usage
|
|
|
|
add='tracked'
|
|
del='removed'
|
|
if(~ $remove 1){
|
|
add='removed'
|
|
del='tracked'
|
|
}
|
|
if(~ $#* 0)
|
|
exec aux/usage
|
|
|
|
paths=`$nl{cleanname -d $gitrel $* | drop $gitroot}
|
|
if(~ $add tracked)
|
|
files=`$nl{walk -f ./$paths}
|
|
if not
|
|
files=`$nl{cd .git/index9/tracked/ && walk -f ./$paths}
|
|
|
|
for(f in $files){
|
|
if(! ~ `$nl{cleanname $f} .git/*){
|
|
addpath=.git/index9/$add/$f
|
|
delpath=.git/index9/$del/$f
|
|
mkdir -p `$nl{basename -d $addpath}
|
|
mkdir -p `$nl{basename -d $delpath}
|
|
# We don't want a matching qid, so that
|
|
# git/walk doesn't think this came from
|
|
# a checkout.
|
|
echo -n > $addpath
|
|
rm -f $delpath
|
|
}
|
|
}
|
|
exit ''
|