From 77e2597f005c620651e9713ab7ff278630271876 Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Fri, 19 Apr 2019 14:25:50 -0400 Subject: [PATCH] zit launch script --- add | 2 +- branch | 6 +++--- checkout | 10 +++++----- checkout-index | 2 +- commit | 6 +++--- commit-tree | 4 ++-- get-sha1-basic | 8 ++++---- read-tree | 2 +- rev-parse | 2 +- update-ref | 4 ++-- write-tree | 2 +- zit | 4 ++++ 12 files changed, 28 insertions(+), 24 deletions(-) create mode 100755 zit diff --git a/add b/add index 5e6a615..81ed505 100755 --- a/add +++ b/add @@ -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() diff --git a/branch b/branch index d908108..854a723 100755 --- a/branch +++ b/branch @@ -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 diff --git a/checkout b/checkout index cfe6f3c..a2a97c9 100755 --- a/checkout +++ b/checkout @@ -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 diff --git a/checkout-index b/checkout-index index edd4fb6..3c0836a 100755 --- a/checkout-index +++ b/checkout-index @@ -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')) diff --git a/commit b/commit index 90ae53b..0703122 100755 --- a/commit +++ b/commit @@ -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 diff --git a/commit-tree b/commit-tree index 3551f62..b5f3b2e 100755 --- a/commit-tree +++ b/commit-tree @@ -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 @@ -12,4 +12,4 @@ echo committer "Joe Mou $(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 diff --git a/get-sha1-basic b/get-sha1-basic index 901c84d..1b17ebf 100755 --- a/get-sha1-basic +++ b/get-sha1-basic @@ -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 diff --git a/read-tree b/read-tree index 5a5b228..2b1955a 100755 --- a/read-tree +++ b/read-tree @@ -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) diff --git a/rev-parse b/rev-parse index 3f72497..33ac383 100755 --- a/rev-parse +++ b/rev-parse @@ -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) diff --git a/update-ref b/update-ref index c217c1b..605639d 100755 --- a/update-ref +++ b/update-ref @@ -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 diff --git a/write-tree b/write-tree index 17af112..63f6ac7 100755 --- a/write-tree +++ b/write-tree @@ -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']) diff --git a/zit b/zit new file mode 100755 index 0000000..8fd538e --- /dev/null +++ b/zit @@ -0,0 +1,4 @@ +#!/bin/bash -e + +export PATH="${BASH_SOURCE%/*}:$PATH" +exec "$@"