diff --git a/commit b/commit new file mode 100755 index 0000000..90ae53b --- /dev/null +++ b/commit @@ -0,0 +1,10 @@ +#!/bin/bash -e + +# TODO unless this is the initial commit +parents='-p HEAD' +echo '# write a commit message' > .zit/COMMIT_EDITMSG +vi .zit/COMMIT_EDITMSG +tree=$(./write-tree) +commit=$(grep -v '^#' .zit/COMMIT_EDITMSG | ./commit-tree $tree $parents) +./update-ref HEAD $commit +rm -f .zit/COMMIT_EDITMSG diff --git a/commit-tree b/commit-tree index b102b4b..3551f62 100755 --- a/commit-tree +++ b/commit-tree @@ -3,7 +3,8 @@ echo tree $1 > .zit/commit.tmp shift while [[ $1 == -p ]]; do - echo parent $2 >> .zit/commit.tmp + parent=$(./rev-parse $2) + echo parent $parent >> .zit/commit.tmp shift; shift done echo author "Joe Mou $(date +'%s %z')" >> .zit/commit.tmp diff --git a/rev-parse b/rev-parse new file mode 100755 index 0000000..11ff61f --- /dev/null +++ b/rev-parse @@ -0,0 +1,13 @@ +#!/bin/bash -e +# only implements --verify + +# sha1_name.c:get_sha1 + +if [[ ${#1} -eq 40 ]]; then + echo $1 +else + cat .zit/$(./symbolic-ref $1) 2> /dev/null || \ + cat .zit/$(./symbolic-ref refs/$1) 2> /dev/null || \ + cat .zit/$(./symbolic-ref refs/tags/$1) 2> /dev/null || \ + cat .zit/$(./symbolic-ref refs/heads/$1) +fi diff --git a/symbolic-ref b/symbolic-ref new file mode 100755 index 0000000..9a72285 --- /dev/null +++ b/symbolic-ref @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# refs.c:resolve_ref +path=.zit/$1 +while grep -q '^ref: ' $path 2> /dev/null; do + path=.zit/$(cut -d' ' -f2 < $path) +done +echo $path | cut -d/ -f2- diff --git a/update-ref b/update-ref new file mode 100755 index 0000000..c217c1b --- /dev/null +++ b/update-ref @@ -0,0 +1,7 @@ +#!/bin/bash -e + +path=.zit/$(./symbolic-ref $1) +sha1=$(./rev-parse $2) +# TODO initialize directory structure instead? +mkdir -p $(dirname $path) +echo $sha1 > $path