exit 'usage'
}
-# subst [-g] this [that]
-fn subst{
- awk 'BEGIN{
- global = 0
- for(i = 1; ARGV[i] ~ /^-/; i++){
- if(ARGV[i] == "-g")
- global = 1
- ARGC--
- }
- this = ARGV[i++]; ARGC--
- that = ARGV[i++]; ARGC--
- }
+fn subst {
+ awk '
+ BEGIN{ARGC=0}
+ {sub(ARGV[1], ARGV[2]); print}
+ ' $*
+}
+
+fn drop {
+ awk '
+ BEGIN{ARGC=0}
{
- if(global) gsub(this, that)
- else sub(this, that)
+ if(index($0, ARGV[1]) == 1)
+ $0=substr($0, length(ARGV[1])+1)
print
- }' $*
+ }
+ ' $*
}
fn present {
if(~ $#gitroot 0)
die 'not a git repository'
gitfs=$gitroot/.git/fs
- gitrel=`{pwd | subst '^'$"gitroot'/?'}
+ gitrel=`{pwd | drop $gitroot | sed 's@^/@@'}
if(~ $#gitrel 0)
gitrel='.'
cd $gitroot
if(~ $#* 0)
exec aux/usage
-paths=`$nl{cleanname -d $gitrel $*}
+paths=`$nl{cleanname -d $gitrel $* | drop $gitroot}
if(~ $add tracked)
- files=`$nl{walk -f $paths}
+ files=`$nl{walk -f ./$paths}
if not
- files=`$nl{cd .git/index9/tracked/ && walk -f $paths}
+ files=`$nl{cd .git/index9/tracked/ && walk -f ./$paths}
for(f in $files){
if(! ~ `$nl{cleanname $f} .git/*){
if(~ $debug 1)
debug=(-d)
-remote=`{echo $1 | subst -g '/*$'}
+remote=`{echo $1 | sed 's@/*$@@'}
local=$2
if(~ $#remote 0)
tree=.git/fs/HEAD/tree
lbranch=`{git/branch}
- rbranch=`{echo $lbranch | subst '^heads' 'remotes/origin'}
+ rbranch=`{echo $lbranch | subst 'heads' 'remotes/origin'}
echo checking out repository...
if(test -f .git/refs/$rbranch){
cp .git/refs/$rbranch .git/refs/$lbranch
git/fs
@ {builtin cd $tree && tar cif /fd/1 .} | @ {tar xf /fd/0} \
|| die 'checkout failed:' $status
- for(f in `$nl{walk -f $tree | subst '^'$tree'/*'}){
- if(! ~ $#f 0){
- idx=.git/index9/tracked/$f
- mkdir -p `$nl{basename -d $idx}
- walk -eq $f > $idx
- }
+ for(f in `$nl{walk -f $tree | drop $tree}){
+ idx=.git/index9/tracked/$f
+ mkdir -p `$nl{basename -d $idx}
+ walk -eq ./$f > $idx
}
}
if not{
basebr=$gitfs/object/$2/tree
theirbr=$gitfs/object/$3/tree
- all=`$nl{{git/query -c $1 $2; git/query -c $2 $3} | sed 's/^..//' | \
- subst -g '^('$ourbr'|'$basebr'|'$theirbr')/*' | sort | uniq}
+ all=`$nl{{git/query -c $1 $2; git/query -c $2 $3} | sed 's/^..//' | sort | uniq}
for(f in $all){
ours=$ourbr/$f
base=$basebr/$f
theirs=$theirbr/$f
- merge1 $f $theirs $base $ours
+ merge1 ./$f $theirs $base $ours
}
}
# The remote is directly ahead of the local, and we have
# no local commits that need merging.
if(~ $#quiet 0)
- git/log -s -e $local'..'$remote >[1=2]
+ git/log -s -e $local'..'$remote
echo
-echo $remote':' `{git/query $local} '=>' `{git/query $remote} >[1=2]
+echo $remote':' `{git/query $local} '=>' `{git/query $remote}
git/branch -mnb $remote $local
exit ''
if(~ $#query 1)
commit=`{git/query -p $query}
-files=`$nl{cleanname -d $gitrel $*}
-for(f in `$nl{cd $commit/tree/ && walk -f $files}){
+files=`$nl{cleanname -d $gitrel $* | drop $gitroot}
+for(f in `$nl{cd $commit/tree/ && walk -f ./$files}){
mkdir -p `{basename -d $f}
cp -x -- $commit/tree/$f $f
git/add $f