Skip to content

Commit

Permalink
git: sync with 9front
Browse files Browse the repository at this point in the history
  • Loading branch information
oridb committed Nov 28, 2022
1 parent c65ded4 commit 72ba278
Show file tree
Hide file tree
Showing 28 changed files with 845 additions and 673 deletions.
6 changes: 3 additions & 3 deletions add
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ if(~ $remove 1){
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/*){
Expand Down
22 changes: 11 additions & 11 deletions branch
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if not
orig=`{git/query HEAD}
if (~ $#baseref 1)
base=`{git/query $baseref} || exit 'bad base'
if not if(test -e .git/$new)
if not if(~ $#newbr 0)
base=`{git/query $new}
if not
base=`{git/query HEAD}
Expand All @@ -41,17 +41,19 @@ if(~ $#newbr 0){
if(! ~ $#baseref 0)
die update would clobber $branch with $baseref
baseref=`$nl{echo -n $new | sed s@refs/heads/@refs/remotes/origin/@}
echo $baseref
if(! test -e .git/$new)
if(! base=`{git/query $baseref})
die could not find branch $branch
}
modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
if(! ~ $#modified 0 || ! ~ $#deleted 0 && ~ $#merge 0){
git/walk -fRMA $modified $deleted ||
die 'uncommited changes would be clobbered'
# if we're not merging, don't clobber existing changes.
if(~ $#merge 0){
if(! ~ $#modified 0 || ! ~ $#deleted 0){
git/walk -fRMA $modified $deleted ||
die 'uncommitted changes would be clobbered'
}
}
if(~ $delete 1){
rm -f .git/$new
Expand All @@ -67,8 +69,6 @@ if(! ~ $#stay 0){
}
basedir=`{git/query -p $base}
dirtypaths=()
if(! ~ $#modified 0 || ! ~ $#deleted 0)
dirtypaths=`$nl{git/walk -cfRMA $modified $deleted}
if(! ~ $#modified 0 || ! ~ $#deleted 0)
dirtypaths=`$nl{git/walk -cfRMA $modified $deleted}
if(~ $#dirtypaths 0)
Expand Down Expand Up @@ -100,10 +100,9 @@ for(m in $cleanpaths){
rm -rf .git/index9/tracked/$m
}
if(~ $b file){
if(cp -x -- $basedir/tree/$m $m)
walk -eq $m > .git/index9/tracked/$m
if not
echo -n > .git/index9/tracked/$m
cp -x -- $basedir/tree/$m $m
walk -eq $m > .git/index9/tracked/$m
touch $m
}
}
Expand All @@ -119,4 +118,5 @@ if(! ~ $#deleted 0){
}
echo ref: $new > .git/HEAD
echo $new: `{git/query $new}
exit ''
16 changes: 7 additions & 9 deletions clone
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ eval `''{aux/getflags $*} || exec aux/usage
if(~ $debug 1)
debug=(-d)
remote=`{echo $1 | subst -g '/*$'}
remote=`{echo $1 | sed 's@/*$@@'}
local=$2

if(~ $#remote 0)
Expand All @@ -33,7 +33,7 @@ fn clone{
echo '[remote "origin"]'
echo ' url='$remote
}
{git/fetch $debug $branchflag $remote >[2=3] | awk '
{git/get $debug $branchflag $remote >[2=3] | awk '
BEGIN{
headref=""
if(ENVIRON["branch"] != "")
Expand Down Expand Up @@ -79,19 +79,17 @@ fn clone{
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{
Expand Down
22 changes: 4 additions & 18 deletions commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
rfork ne
. /sys/lib/git/common.rc

fn whoami{
name=`{git/conf user.name}
email=`{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}
if(~ $email '')
email=`{awk -F'|' '$1=="'$user'" {x=$5} END{print x}' </adm/keys.who}
}
if(~ $name '')
name=glenda
if(~ $email '')
[email protected]
}

fn findbranch{
branch=`{git/branch}
if(test -e $gitfs/branch/$branch/tree){
Expand Down Expand Up @@ -58,7 +43,7 @@ fn editmsg{
echo '#'
for(p in $parents)
echo '# parent:' $p
git/walk -fAMR $files | subst -g '^' '# '
git/walk -fAMR $files | subst '^' '# '
echo '#'
echo '# Commit message:'
}
Expand Down Expand Up @@ -92,7 +77,7 @@ 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=`{git/save -n $"name -e $"email -m $"msg $pflags $files || die $status}
rm -f .git/index9/merge-parents
}
Expand All @@ -116,7 +101,8 @@ fn update{
}
fn sigexit{
rm -f $msgfile $msgfile.tmp
if(! ~ $#msgfile 0)
rm -f $msgfile $msgfile.tmp
}
gitup
Expand Down
72 changes: 49 additions & 23 deletions common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,60 @@ fn usage{
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 {
fn mergeperm {
if(~ $1 /dev/null && cmp $2 $3>/dev/null)
status=gone
if not if (~ $3 /dev/null && cmp $1 $2>/dev/null)
status=gone
if not
if not {
mergedperms='-x'
if(test -x $2){
if(test -x $1 -a -x $3)
mergedperms='+x'
}
if not{
if(test -x $1 -o -x $3)
mergedperms='+x'
}
status=()
}
}

fn whoami{
name=`$nl{git/conf user.name}
email=`$nl{git/conf user.email}
if(test -f /adm/keys.who){
if(~ $name '')
name=`$nl{awk -F'|' '$1=="'$user'" {x=$3} END{print x}' </adm/keys.who}
if(~ $email '')
email=`$nl{awk -F'|' '$1=="'$user'" {x=$5} END{print x}' </adm/keys.who}
}
if(~ $name '')
name=$user
if(~ $email '')
email=$user@$sysname
status=''
}

# merge1 out theirs base ours
# merge1 out ours base theirs
fn merge1 {@{
rfork e
n=$pid
Expand All @@ -62,9 +87,10 @@ fn merge1 {@{
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]

if(present $ours $base $theirs){
if(mergeperm $ours $base $theirs){
mv $tmp $out
git/add $out
chmod $mergedperms $out
}
if not {
rm -f $tmp $out
Expand All @@ -77,13 +103,13 @@ fn gitup{
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(! cd $gitroot)
die cd $gitroot: no repo there
startfs=()
if(! test -d $gitfs)
mkdir -p $gitfs
mkdir -p $gitfs
if(! test -e $gitfs/ctl)
startfs=true
if(! grep -s '^repo '$gitroot'$' $gitfs/ctl >[2]/dev/null)
Expand Down
Loading

0 comments on commit 72ba278

Please sign in to comment.