Skip to content

Commit

Permalink
scripts: use full path to git binaries
Browse files Browse the repository at this point in the history
This prepares us for the git/compat script, which will
bind itself over /bin/git, as a way of providing a
compatibility script for tools like go.

Because /bin/git will be replaced, when in the compat
environment, we will not be able to invoke git/foo.
  • Loading branch information
oridb committed Sep 4, 2020
1 parent 1fe21fe commit 777e9c6
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 65 deletions.
18 changes: 9 additions & 9 deletions branch
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ if not
new=refs/heads/$branch
if (~ $#baseref 1)
base=`{git/query $baseref} || exit 'bad base'
base=`{/$cputype/bin/git/query $baseref} || exit 'bad base'
if not if(test -e .git/$new)
base=`{git/query $new}
base=`{/$cputype/bin/git/query $new}
if not
base=`{git/query HEAD}
base=`{/$cputype/bin/git/query HEAD}
modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
modified=`$nl{/$cputype/bin/git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
deleted=`$nl{/$cputype/bin/git/query -c HEAD $base | grep '^-' | subst '^..'}
if(! ~ $#modified 0 || ! ~ $#deleted 0){
if(! git/walk -q $modified $deleted){
git/walk -fRMA $modified $deleted
if(! /$cputype/bin/git/walk -q $modified $deleted){
/$cputype/bin/git/walk -fRMA $modified $deleted
die 'uncommited changes would be clobbered'
}
}
Expand All @@ -56,7 +56,7 @@ if(~ $#newbr 0){
if(! ~ $#baseref 0)
die update would clobber $branch with $baseref
}
commit=`{git/query $base} || die 'branch does not exist:' $base
commit=`{/$cputype/bin/git/query $base} || die 'branch does not exist:' $base
echo updating $new to $commit
echo $commit > .git/$new
Expand All @@ -65,7 +65,7 @@ if(! ~ $#stay 0)
exit
if(! ~ $#modified 0){
basedir=`{git/query -p $base}
basedir=`{/$cputype/bin/git/query -p $base}
for(m in $modified){
d=`{basename -d $m}
mkdir -p $d
Expand Down
6 changes: 3 additions & 3 deletions clone
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn clone{
echo ' url='$remote
echo ' fetch=+refs/heads/*:refs/remotes/origin/*'
}
{git/fetch $remote >[2=3] | awk '
{/$cputype/bin/git/fetch $remote >[2=3] | awk '
/^remote/{
if($2=="HEAD"){
headhash=$3
Expand Down Expand Up @@ -64,12 +64,12 @@ fn clone{
'} |[3] tr '\x0d' '\x0a' || die 'could not clone repository'
tree=/mnt/git/HEAD/tree
lbranch=`{git/branch}
lbranch=`{/$cputype/bin/git/branch}
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
/$cputype/bin/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'/*'}){
Expand Down
16 changes: 8 additions & 8 deletions commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ rfork ne
. /sys/lib/git/common.rc

fn whoami{
name=`{git/conf user.name}
email=`{git/conf user.email}
name=`{/$cputype/bin/git/conf user.name}
email=`{/$cputype/bin/git/conf user.email}
if(test -f /adm/keys.who){
if(~ $name '')
name=`{awk -F'|' '$1=="'$user'" {x=$3} END{print x}' </adm/keys.who}
Expand All @@ -18,7 +18,7 @@ fn whoami{
}

fn findbranch{
branch=`{git/branch}
branch=`{/$cputype/bin/git/branch}
if(test -e /mnt/git/branch/$branch/tree){
refpath=.git/refs/$branch
initial=false
Expand Down Expand Up @@ -58,11 +58,11 @@ fn editmsg{
echo '#'
for(p in $parents)
echo '# parent:' $p
git/walk -fAMR $files | subst -g '^' '# '
/$cputype/bin/git/walk -fAMR $files | subst -g '^' '# '
echo '#'
echo '# Commit message:'
}
giteditor=`{git/conf core.editor}
giteditor=`{/$cputype/bin/git/conf core.editor}
if(~ $#editor 0)
editor=$giteditor
if(~ $#editor 0)
Expand All @@ -80,14 +80,14 @@ fn parents{
if not if(~ $initial true)
parents=()
if not
parents=`{git/query $branch}
parents=`{/$cputype/bin/git/query $branch}
}
fn commit{
msg=`"{cat $msgfile}
if(! ~ $#parents 0)
pflags='-p'^$parents
hash=`{git/save -n $"name -e $"email -m $"msg $pflags $files || die $status}
hash=`{/$cputype/bin/git/save -n $"name -e $"email -m $"msg $pflags $files || die $status}
rm -f .git/index9/merge-parents
}
Expand Down Expand Up @@ -125,7 +125,7 @@ msgfile=/tmp/git-msg.$pid
if(~ $#msg 1)
echo $msg >$msgfile.tmp
files=`{git/walk -c `{cleanname $gitrel/$*}}
files=`{/$cputype/bin/git/walk -c `{cleanname $gitrel/$*}}
if(~ $status '' || ~ $#files 0 && ! test -f .git/index9/merge-parents)
die 'nothing to commit' $status
@{
Expand Down
4 changes: 2 additions & 2 deletions common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn subst{
}

fn gitup{
gitroot=`{git/conf -r >[2]/dev/null}
gitroot=`{/$cputype/bin/git/conf -r >[2]/dev/null}
if(~ $#gitroot 0)
die 'not a git repository'
gitrel=`{pwd | subst '^'$"gitroot'/?'}
Expand All @@ -44,7 +44,7 @@ fn gitup{
if(! grep -s '^repo '$gitroot'$' /mnt/git/ctl >[2]/dev/null)
startfs=true
if(~ $#startfs 1)
git/fs
/$cputype/bin/git/fs
if not
status=''
}
8 changes: 4 additions & 4 deletions diff
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ if(~ $#commit 0)
files=()
if(! ~ $#* 0)
files=`{cleanname $gitrel/$*}
branch=`{git/query -p $commit}
branch=`{/$cputype/bin/git/query -p $commit}
if(~ $summarize 1){
git/walk -fMAR $files
/$cputype/bin/git/walk -fMAR $files
exit
}
dirty=`$nl{git/walk -c -fRMA $files}
dirty=`$nl{/$cputype/bin/git/walk -c -fRMA $files}
if(! ~ $commit HEAD)
dirty=($dirty `$nl{git/query -c $commit HEAD | subst '^..'})
dirty=($dirty `$nl{/$cputype/bin/git/query -c $commit HEAD | subst '^..'})
for(f in $dirty){
orig=$branch/tree/$f
if(! test -f $orig)
Expand Down
6 changes: 3 additions & 3 deletions export
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ if(~ $#patchdir 1 && ! test -d $patchdir)
q=$*
if(~ $#q 0)
q=HEAD
commits=`{git/query $q || die $status}
commits=`{/$cputype/bin/git/query $q || die $status}
n=1
m=$#commits
mntgen /mnt/scratch
for(c in $commits){
cp=`{git/query -p $c}
pp=`{git/query -p $c'^'}
cp=`{/$cputype/bin/git/query -p $c}
pp=`{/$cputype/bin/git/query -p $c'^'}

@{
rfork n
Expand Down
14 changes: 7 additions & 7 deletions import
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ fn sigexit {
}

fn apply @{
git/fs
/$cputype/bin/git/fs
email=''
name=''
msg=''
parents='-p'^`{git/query HEAD}
branch=`{git/branch}
parents='-p'^`{/$cputype/bin/git/query HEAD}
branch=`{/$cputypeb/in/git/branch}
if(test -e /mnt/git/branch/$branch/tree)
refpath=.git/refs/$branch
if not if(test -e /mnt/git/object/$branch/tree)
Expand Down Expand Up @@ -77,12 +77,12 @@ fn apply @{
files=`$nl{ape/patch -Ep1 < $diffpath | sed ''s/^patching file `(.*)''''/\1/''}
for(f in $files){
if(test -e $f)
git/add $f
/$cputype/bin/git/add $f
if not
git/add -r $f
/$cputype/bin/git/add -r $f
}
git/walk -fRMA $files
hash=`{git/save -n $name -e $email -m $msg -d $date $parents $files}
/$cputype/bin/git/walk -fRMA $files
hash=`{/$cputype/bin/git/save -n $name -e $email -m $msg -d $date $parents $files}
echo $hash > $refpath
'
}
Expand Down
8 changes: 4 additions & 4 deletions log
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ eval `''{aux/getflags $*} || exec aux/usage
base=/mnt/git/object/
if(~ $#branch 0)
branch=`{git/branch}
branch=`{/$cputype/bin/git/branch}
if(~ $#expr 0)
commits=`{git/query $branch}
commits=`{/$cputype/bin/git/query $branch}
if not
commits=`{git/query $expr}
commits=`{/$cputype/bin/git/query $expr}
files=()
if(! ~ $#* 0)
Expand All @@ -24,7 +24,7 @@ while(! ~ $#commits 0){
show=()
c=$commits(1)
if(! ~ $#files 0){
ncomm=`{comm -12 /env/files <{git/query -c $c~ $c | subst '^..' | sort} | wc -l}
ncomm=`{comm -12 /env/files <{/$cputype/bin/git/query -c $c~ $c | subst '^..' | sort} | wc -l}
if(! ~ $ncomm 0)
show=true
}
Expand Down
16 changes: 8 additions & 8 deletions merge
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fn merge{
echo merge needed: $f
if(test -f $f)
git/add $f
/$cputype/bin/git/add $f
if not
git/rm $f
/$cputype/bin/git/rm $f
}
}
Expand All @@ -37,18 +37,18 @@ eval `''{aux/getflags $*} || exec aux/usage
if(! ~ $#* 1)
exec aux/usage
theirs=`{git/query $1}
ours=`{git/query HEAD}
base=`{git/query $theirs ^ ' ' ^ $ours ^ '@'}
theirs=`{/$cputytpe/bin/git/query $1}
ours=`{/$cputype/bin/git/query HEAD}
base=`{/$cputype/bin/git/query $theirs ^ ' ' ^ $ours ^ '@'}
if(~ $base $theirs)
die 'nothing to merge, doofus'
if(! git/walk -q)
if(! /$cputype/bin/git/walk -q)
die 'dirty work tree, refusing to merge'
if(~ $base $ours){
>[1=2] echo 'fast forwarding...'
echo $theirs > .git/refs/`{git/branch}
git/revert .
echo $theirs > .git/refs/`{/$cputype/bin/git/branch}
/$cputype/bin/git/revert .
exit ''
}
echo $ours >> .git/index9/merge-parents
Expand Down
1 change: 1 addition & 0 deletions mkfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RC=\
branch\
clone\
commit\
compat\
diff\
export\
import\
Expand Down
26 changes: 13 additions & 13 deletions pull
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn update{
bflag=()
if(! ~ $branch '')
bflag=(-b $branch)
{git/fetch $bflag -u $upstream $url >[2=3] || die $status} | awk '
{/$cputype/bin/git/fetch $bflag -u $upstream $url >[2=3] || die $status} | awk '
/^remote/{
if($2=="HEAD")
next
Expand All @@ -33,45 +33,45 @@ args=''
eval `''{aux/getflags $*} || exec aux/usage
if(~ $#branch 0)
branch=refs/`{git/branch}
branch=refs/`{/$cputype/bin/git/branch}
if(~ $allbranch 1)
branch=''

if(~ $#upstream 0)
upstream=origin
remote=`{git/conf 'remote "'$upstream'".url'}
remote=`{/$cputype/bin/git/conf 'remote "'$upstream'".url'}
if(~ $#remote 0)
die 'no remote to pull from'
update $branch $upstream $remote
if (~ $fetchonly 1)
exit
local=`{git/branch}
remote=`{git/branch | subst '^(refs/)?heads' 'remotes/'$upstream}
local=`{//$cputype/bin/git/branch}
remote=`{/$cputype/bin/git/branch | subst '^(refs/)?heads' 'remotes/'$upstream}
# we have local commits, but the remote hasn't changed.
# in this case, we want to keep the local commits untouched.
if(~ `{git/query HEAD $remote @} `{git/query $remote}){
if(~ `{/$cputype/bin/git/query HEAD $remote @} `{/$cputype/bin/git/query $remote}){
echo 'up to date' >[1=2]
exit
}
# The remote repository and our HEAD have diverged: we
# need to merge.
if(! ~ `{git/query HEAD $remote @} `{git/query HEAD}){
if(! ~ `{/$cputype/bin/git/query HEAD $remote @} `{/$cputype/bin/git/query HEAD}){
>[1=2]{
echo ours: `{git/query HEAD}
echo theirs: `{git/query $remote}
echo common: `{git/query HEAD $remote @}
echo ours: `{/$cputype/bin/git/query HEAD}
echo theirs: `{/$cputype/bin/git/query $remote}
echo common: `{/$cputype/bin/git/query HEAD $remote @}
echo git/merge $remote
}
exit diverged
}
# 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]
/$cputype/bin/git/log -s -e $local'..'$remote >[1=2]
echo
echo $remote':' `{git/query $local} '=>' `{git/query $remote} >[1=2]
git/branch -n -b $remote $local
echo $remote':' `{/$cputype/bin/git/query $local} '=>' `{/$cputype/bin/git/query $remote} >[1=2]
/$cputype/bin/git/branch -n -b $remote $local
exit ''
6 changes: 3 additions & 3 deletions push
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if(! ~ $#* 0)
if(~ $pushall 1)
branch=`$nl{cd .git/refs/heads && walk -f}
if(~ $#branch 0)
branch=`{git/branch}
branch=`{/$cputype/bin/git/branch}
if(~ $#branch 0)
die 'no branches'
if(~ $force 1)
Expand All @@ -24,13 +24,13 @@ if(~ $debug 1)
if(~ $#upstream 0)
upstream=origin
remote=`{git/conf 'remote "'$upstream'".url'}
remote=`{/$cputype/bin/git/conf 'remote "'$upstream'".url'}
if(~ $#remote 0)
remote=$upstream
branch=-b^$branch
if(! ~ $#remove 0)
remove=-r^$remove
updates=`$nl{git/send $debug $force $branch $remove $remote || die $status}
updates=`$nl{/$cputype/bin/git/send $debug $force $branch $remove $remote || die $status}
for(ln in $updates){
u=`{echo $ln}
refpath=`{echo $u(2) | subst '^refs/heads/' '.git/refs/remotes/'$upstream'/'}
Expand Down
2 changes: 1 addition & 1 deletion rm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/rc -e

exec git/add -r $*
exec /$cputype/bin/git/add -r $*

0 comments on commit 777e9c6

Please sign in to comment.