Skip to content

Commit

Permalink
zit launch script
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Mou committed Apr 19, 2019
1 parent 52b1d99 commit 77e2597
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion add
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for _ in range(num_entries):

_, filename = sys.argv
# TODO handle deleted files?
sha1 = subprocess.check_output(['./hash-object', 'blob', filename]).strip()
sha1 = subprocess.check_output(['hash-object', 'blob', filename]).strip()
# TODO canonicalize filename?
entries.append((filename, sha1))
entries.sort()
Expand Down
6 changes: 3 additions & 3 deletions branch
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash -e

if [[ $# -eq 0 ]]; then
headref=$(./symbolic-ref HEAD | sed -e 's|^refs/heads/||')
headref=$(symbolic-ref HEAD | sed -e 's|^refs/heads/||')
echo "*$headref"
cd .zit/refs/heads
ls | grep -vxF $headref
else
branchname=$1
startpoint=${2-HEAD}
rev=$(./rev-parse $startpoint)
./update-ref refs/heads/$branchname $rev
rev=$(rev-parse $startpoint)
update-ref refs/heads/$branchname $rev
fi
10 changes: 5 additions & 5 deletions checkout
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash -e

if [[ $1 == -b ]]; then
./branch $2
branch $2
shift
fi
revision=$1
tree=$(./rev-parse $revision^{tree})
./read-tree $tree
./checkout-index
tree=$(rev-parse $revision^{tree})
read-tree $tree
checkout-index
if [[ -f .zit/refs/heads/$revision ]]; then
./symbolic-ref HEAD refs/heads/$revision
symbolic-ref HEAD refs/heads/$revision
else
echo "You are in 'detached HEAD' state." >&2
fi
2 changes: 1 addition & 1 deletion checkout-index
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ for filename, sha1 in entries:
os.unlink(filename)
subprocess.check_call(['mkdir', '-p', './' + os.path.dirname(filename)])
# TODO git 1.0 doesn't seem to unlink deleted files
subprocess.check_call(['./cat-file', 'blob', sha1], stdout=open(filename, 'w'))
subprocess.check_call(['cat-file', 'blob', sha1], stdout=open(filename, 'w'))
6 changes: 3 additions & 3 deletions commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
tree=$(write-tree)
commit=$(grep -v '^#' .zit/COMMIT_EDITMSG | commit-tree $tree $parents)
update-ref HEAD $commit
rm -f .zit/COMMIT_EDITMSG
4 changes: 2 additions & 2 deletions commit-tree
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
echo tree $1 > .zit/commit.tmp
shift
while [[ $1 == -p ]]; do
parent=$(./rev-parse $2)
parent=$(rev-parse $2)
echo parent $parent >> .zit/commit.tmp
shift; shift
done
Expand All @@ -12,4 +12,4 @@ echo committer "Joe Mou <[email protected]> $(date +'%s %z')" >> .zit/commit.tmp
echo >> .zit/commit.tmp
cat >> .zit/commit.tmp

./hash-object commit .zit/commit.tmp
hash-object commit .zit/commit.tmp
8 changes: 4 additions & 4 deletions get-sha1-basic
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
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)
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
2 changes: 1 addition & 1 deletion read-tree
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import subprocess
import sys

_, tree_sha1 = sys.argv
tree = subprocess.check_output(['./cat-file', 'tree', tree_sha1])
tree = subprocess.check_output(['cat-file', 'tree', tree_sha1])
entries = []
while tree:
header, rest = tree.split('\0', 1)
Expand Down
2 changes: 1 addition & 1 deletion rev-parse
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_sha1(name):
else:
raise Exception('wrong type')
else:
return subprocess.check_output(['./get-sha1-basic', name])[:-1]
return subprocess.check_output(['get-sha1-basic', name])[:-1]

_, name = sys.argv
print get_sha1(name)
4 changes: 2 additions & 2 deletions update-ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

path=.zit/$(./symbolic-ref $1)
sha1=$(./rev-parse $2)
path=.zit/$(symbolic-ref $1)
sha1=$(rev-parse $2)
# TODO initialize directory structure instead?
mkdir -p $(dirname $path)
echo $sha1 > $path
2 changes: 1 addition & 1 deletion write-tree
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ for filename, sha1 in entries:
f.write(bytearray.fromhex(sha1))
f.close()

subprocess.check_call(['./hash-object', 'tree', '.zit/tree.tmp'])
subprocess.check_call(['hash-object', 'tree', '.zit/tree.tmp'])
4 changes: 4 additions & 0 deletions zit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

export PATH="${BASH_SOURCE%/*}:$PATH"
exec "$@"

0 comments on commit 77e2597

Please sign in to comment.