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 May 27, 2024
1 parent 45001b2 commit 4fecf55
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 148 deletions.
29 changes: 5 additions & 24 deletions add
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,13 @@ gitup
flagfmt='r:remove'; args='file ...'
eval `''{aux/getflags $*} || exec aux/usage
add='tracked'
del='removed'
if(~ $remove 1){
add='removed'
del='tracked'
}
s=A
if(~ $remove 1)
s=R
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
}
}
walk -f ./$paths | grep -v '^(./)?.git/' | \
sed 's/^/'$s' NOQID 0 /' >> .git/INDEX9
exit ''
20 changes: 12 additions & 8 deletions branch
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rfork en

gitup

flagfmt='a:listall, b:baseref ref, d:delete, n:newbr, s:stay, m:merge'
flagfmt='a:listall, b:baseref ref, d:delete, n:newbr, s:stay, m:merge, M:nomod'
args='[branch]'
eval `''{aux/getflags $*} || exec aux/usage
Expand Down Expand Up @@ -48,8 +48,11 @@ if(~ $#newbr 0){
modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
# if we delete the current branch without switching, bad things happen
if(~ $delete 1 && ~ `{git/query HEAD} `{git/query $branch})
die 'cannot delete current branch'
# if we're not merging, don't clobber existing changes.
if(~ $#merge 0){
if(~ $#merge 0 && ~ $#delete 0){
if(! ~ $#modified 0 || ! ~ $#deleted 0){
git/walk -fRMA $modified $deleted ||
die 'uncommitted changes would be clobbered'
Expand Down Expand Up @@ -84,7 +87,6 @@ echo $commit > .git/$new
for(m in $cleanpaths){
d=`$nl{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
Expand All @@ -97,11 +99,11 @@ for(m in $cleanpaths){
b=file
if(! ~ $a $b){
rm -rf $m
rm -rf .git/index9/tracked/$m
echo R NOQID 0 $m >> .git/INDEX9
}
if(~ $b file){
cp -x -- $basedir/tree/$m $m
walk -eq $m > .git/index9/tracked/$m
echo T NOQID 0 $m >> .git/INDEX9
touch $m
}
}
Expand All @@ -112,9 +114,11 @@ for(ours in $dirtypaths){
merge1 $ours $ours $common $theirs
}
if(! ~ $#deleted 0){
rm -f $deleted
rm -f .git/index9/tracked/$deleted
for(d in $deleted){
if(! test -d $d){
rm -f $d
echo R NOQID 0 $d >> .git/INDEX9
}
}
echo ref: $new > .git/HEAD
Expand Down
16 changes: 8 additions & 8 deletions clone
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ if(~ $#local 0)
if(~ $#branch 1)
branchflag=(-b $branch)
if(test -e $local)
die 'repository already exists:' $local
if(test -e $local && ~ `{ls $local | sed 1q | wc -l} 1)
die 'destination already exists:' $local
fn clone{
flag +e
Expand Down Expand Up @@ -67,7 +67,7 @@ fn clone{
refdir = headref;
gsub("/?[^/]*/?$", "", refdir)
gsub("^refs/remotes/origin", "refs/heads", headref)
system("mkdir -p .git/"refdir);
system("mkdir -p `{basename -d .git/"headref"}");
system("cp .git/" remote " .git/" headref)
print "ref: " headref > ".git/HEAD"
}else if(headhash != ""){
Expand All @@ -82,15 +82,13 @@ fn clone{
rbranch=`{echo $lbranch | subst 'heads' 'remotes/origin'}
echo checking out repository...
if(test -f .git/refs/$rbranch){
mkdir -p `{basename -d .git/refs/$lbranch}
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 | drop $tree}){
idx=.git/index9/tracked/$f
mkdir -p `$nl{basename -d $idx}
walk -eq ./$f > $idx
}
{for(f in `$nl{cd $tree && walk -f})
echo 'T NOQID 0 '$f} > .git/INDEX9
}
if not{
echo no default branch >[1=2]
Expand All @@ -100,6 +98,7 @@ fn clone{
fn sigint {
echo cancelled clone $remote: cleaning $local >[1=2]
unmount $local/.git/fs >[2]/dev/null
rm -rf $local
exit interrupted
}
Expand All @@ -108,6 +107,7 @@ fn sigint {
st=$status
if(! ~ $st ''){
echo failed to clone $remote: cleaning $local >[1=2]
unmount $local/.git/fs >[2]/dev/null
rm -rf $local
exit $st
}
Expand Down
26 changes: 12 additions & 14 deletions commit
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fn editmsg{
fn parents{
if(! ~ $#revise 0)
parents=`{cat $gitfs/HEAD/parent}
if not if(test -f .git/index9/merge-parents)
parents=`{cat .git/index9/merge-parents | sort | uniq}
if not if(test -f .git/merge-parents)
parents=`{cat .git/merge-parents | sort | uniq}
if not if(~ $initial true)
parents=()
if not
Expand All @@ -78,7 +78,7 @@ fn commit{
if(! ~ $#parents 0)
pflags='-p'^$parents
hash=`{git/save -n $"name -e $"email -m $"msg $pflags $files || die $status}
rm -f .git/index9/merge-parents
rm -f .git/merge-parents
}
fn update{
Expand All @@ -89,14 +89,10 @@ fn update{
echo $branch: $hash
echo $hash > $refpath
for(f in $files){
if(test -e .git/index9/removed/$f || ! test -e $f){
rm -f .git/index9/removed/$f
rm -f .git/index9/tracked/$f
}
if not{
mkdir -p `{basename -d $f}
walk -eq $f > .git/index9/tracked/$f
}
if(! test -e $f && ! test -e .git/object/$hash/tree/$f)
echo R NOQID 0 $f >> .git/INDEX9
if not
echo T NOQID 0 $f >> .git/INDEX9
}
}
Expand All @@ -120,10 +116,12 @@ if not if(~ $#revise 1){
}
files=()
if(test -f .git/merge-parents)
files=`$nl{git/query -c `{cat .git/merge-parents} | sed 's/^..//'}
if(! ~ $#* 0)
files=`$nl{git/walk -c `$nl{cleanname -d $gitrel $*}}
if(~ $status '' || ~ $#files 0 && ! test -f .git/index9/merge-parents && ~ $#revise 0)
die 'nothing to commit' $status
files=($files `$nl{git/walk -c `$nl{cleanname -d $gitrel $*}})
if(~ $status '' || ~ $#files 0 && ! test -f .git/merge-parents && ~ $#revise 0)
die 'nothing to commit'
@{
flag e +
whoami
Expand Down
12 changes: 9 additions & 3 deletions common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ fn merge1 {@{
base=/dev/null
if(! test -f $theirs)
theirs=/dev/null
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]

if(mergeperm $ours $base $theirs){
mkdir -p `{basename -d $tmp}
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]
mv $tmp $out
git/add $out
chmod $mergedperms $out
Expand All @@ -99,9 +100,14 @@ fn merge1 {@{
}}

fn gitup{
gitroot=`{git/conf -r >[2]/dev/null}
gitroot=`$nl{git/conf -r >[2]/dev/null}
if(~ $#gitroot 0)
die 'not a git repository'
gitwork=`$nl{git/conf work.dir}
if(~ $#gitwork 1)
bind -c $gitwork/objects $gitroot/.git/objects
if(~ $#workdir 1)
bind $workdir .git/objects
gitfs=$gitroot/.git/fs
gitrel=`{pwd | drop $gitroot | sed 's@^/@@'}
if(~ $#gitrel 0)
Expand Down
21 changes: 10 additions & 11 deletions diff
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@ rfork ne

gitup

flagfmt='c:commit branch, s:summarize'; args='[file ...]'
flagfmt='c:commit branch, s:summarize, u:uncommitted'; args='[file ...]'
eval `''{aux/getflags $*} || exec aux/usage
if(~ $#commit 0)
if(~ $#commit 0){
commit=HEAD
cparam=()
}
files=()
filt=MAR
if(~ $#uncommitted 1)
filt=MARU
if(! ~ $#* 0)
files=`{cleanname -d $gitrel $*}

branch=`{git/query -p $commit}
if(~ $summarize 1){
git/walk -fMAR $files
if(~ $summarize 1 || ~ $uncommitted 1){
git/walk -f$filt $cparam $files
exit
}
fn lsdirty {
git/walk -c -fRMA $files
if(! ~ $commit HEAD)
git/query -c $commit HEAD | subst '^..'
}
showed=()
mntgen /mnt/scratch
bind $branch/tree/ /mnt/scratch/a
bind . /mnt/scratch/b
for(f in `$nl{lsdirty | sort | uniq}){
for(f in `$nl{git/walk -c -f$filt $cparam $files}){
if(~ $#showed 0){
echo diff `{git/query $commit} uncommitted
showed=1
Expand Down
2 changes: 0 additions & 2 deletions get.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ fetchpack(Conn *c)
return -1;
if(n == 0)
break;
if(strncmp(buf, "ERR ", 4) == 0)
sysfatal("%s", buf + 4);

if(first && n > strlen(buf))
handlecaps(buf + strlen(buf) + 1);
Expand Down
14 changes: 0 additions & 14 deletions git.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef struct Hash Hash;
typedef struct Delta Delta;
typedef struct Cinfo Cinfo;
typedef struct Tinfo Tinfo;
typedef struct Ginfo Ginfo;
typedef struct Object Object;
typedef struct Objset Objset;
typedef struct Pack Pack;
Expand Down Expand Up @@ -130,7 +129,6 @@ struct Object {
union {
Cinfo *commit;
Tinfo *tree;
Ginfo *tag;
};
};

Expand All @@ -153,18 +151,6 @@ struct Cinfo {
vlong mtime;
};

struct Ginfo {
/* Tag */
Hash object;
char *tagger;
char *type;
char *tag;
char *msg;
int nmsg;
vlong ctime;
vlong mtime;
};

struct Objset {
Object **obj;
int nobj;
Expand Down
3 changes: 2 additions & 1 deletion import
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fn apply @{
if(~ $#nocommit 0){
if(hash=`{git/save -n $aname -e $amail -N $name -E $email -m $msg -d $date $parents $files}){
echo $hash > $refpath
rm -f .git/index9/removed/$files
for(f in $files)
echo T NOQID 0 $f >> .git/INDEX9
}
}
status=''''
Expand Down
2 changes: 1 addition & 1 deletion init
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mkdir -p $dir/.git/^(fs objects)
echo '[branch "'$branch'"]'
echo ' remote = origin'
}
>$dir/.git/INDEX9
>$dir/.git/HEAD {
echo ref: refs/heads/$branch
}
Expand Down
4 changes: 2 additions & 2 deletions merge
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ if(~ $base $ours){
git/revert .
exit ''
}
echo $ours >> .git/index9/merge-parents
echo $theirs >> .git/index9/merge-parents
echo $ours >> .git/merge-parents
echo $theirs >> .git/merge-parents

merge $ours $base $theirs
>[1=2] echo 'merge complete: remember to commit'
Expand Down
Loading

0 comments on commit 4fecf55

Please sign in to comment.