Skip to content

Commit

Permalink
commit, update-ref, rev-parse, symbolic-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Mou committed Apr 17, 2019
1 parent ee58d42 commit 51ca764
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions commit
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion commit-tree
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> $(date +'%s %z')" >> .zit/commit.tmp
Expand Down
13 changes: 13 additions & 0 deletions rev-parse
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions symbolic-ref
Original file line number Diff line number Diff line change
@@ -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-
7 changes: 7 additions & 0 deletions update-ref
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 51ca764

Please sign in to comment.