ref: abcaf09f9017a32492796142bf7d2d53f9c260d6
parent: 4748f215582e6af9a8cab49a597b3b9c7ccce5a9
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Aug 20 21:09:47 EDT 2019
Fix some rc bugs (thanks BurnZeZ)
--- a/add
+++ b/add
@@ -1,31 +1,33 @@
#!/bin/rc -e
-
rfork ne
fn usage {
- echo 'usage: '$argv0' [-r] files..' >[1=2]
- echo ' -r: remove instead of adding' >[1=2]
+ echo usage: $0 '[-r] file ...
+ -r: remove instead of adding' >[1=2]
+ exit usage
}
add='tracked'
del='removed'
-while(~ $1 -*){
+while(~ $1 -* && ! ~ $1 --){
switch($1){
case -r
add='removed'
del='tracked'
- case --
- break
- case *; usage
+ case *
+ usage
}
shift
}
+if(~ $1 --)
+ shift
dir=`{pwd}
base=`{git/conf -r}
-if(! ~ $status ''){
- echo 'not in git repository' `{pwd} >[1=2]
- exit notrepo
+x=$status
+if(! ~ $x ''){
+ echo git/conf: $x `{pwd} >[1=2]
+ exit $x
}
cd $base
--- a/branch
+++ b/branch
@@ -3,10 +3,10 @@
rfork en
fn usage{
- echo usage: $argv0 [-b base] [-o origin] new >[2=1]
- echo ' '-b base: use "base" for branch (default: current branch) >[2=1]
- echo ' '-o origin: use "origin" for remote branch >[2=1]
- echo ' 'new: name of new branch
+ echo usage: $0 '[-b base] [-o origin] new
+ -b base: use "base" for branch (default: current branch)
+ -o origin: use "origin" for remote branch
+ new: name of new branch' >[1=2]
exit usage
}
@@ -26,7 +26,8 @@
case -c; create=true
case -s; stay=true
case -o; origin=$1
- case *; usage
+ case *
+ usage
}
shift
}
--- a/clone
+++ b/clone
@@ -1,21 +1,18 @@
-#!/bin/rc
+#!/bin/rc -e
rfork en
nl='
'
-if(~ $#* 1){
- remote=$1
- local=`{basename $1 .git}
-}
-if not if(~ $#* 2){
- remote=$1
- local=$2
-}
-if not{
- echo usage: git/clone remote [local] >[1=2]
+remote=$1
+local=$2
+
+if(~ $#remote 0){
+ echo usage: $0 'remote [local]' >[1=2]
exit usage
}
+if(~ $#local 0)
+ local=`{basename $remote .git}
if(test -e $local){
echo $local already exists >[1=2]
@@ -61,8 +58,9 @@
}
}
'} |[3] tr '\x0d' '\x0a'
- if(! ~ $status '|')
- exit 'clone:'^$status
+ x=$status
+ if(! ~ $x '|')
+ exit $0:^' '^$"x
tree=/mnt/git/branch/heads/master/tree
echo checking out repository...
@@ -70,8 +68,9 @@
cp .git/refs/remotes/origin/master .git/refs/heads/master
git/fs
@ {builtin cd $tree && tar cif /fd/1 .} | @ {tar xf /fd/0}
- if(! ~ $status '')
- exit 'checkout:' $status
+ x=$status
+ if(! ~ $x '')
+ exit 'checkout: '^$"x
for(f in `$nl{walk -f $tree | sed 's@^'$tree'/*@@'}){
if(! ~ $#f 0){
idx=.git/index9/tracked/$f
@@ -86,13 +85,4 @@
}
}
-@{clone}
-st=$status
-if(~ $st ''){
- echo done.
-}
-if not{
- echo clone failed. >[2=1]
- echo cleaning up $local >[2=1]
- rm -rf $local
-}
+clone
--- a/commit
+++ b/commit
@@ -110,8 +110,8 @@
update
cleanup
}
-st=$status
-if(! ~ $status ''){
- echo 'could not commit:' $st >[1=2]
- exit $st
+x=$status
+if(! ~ $x ''){
+ echo 'could not commit:' $x >[1=2]
+ exit $x
}
--- a/diff
+++ b/diff
@@ -3,7 +3,7 @@
rfork e
fn usage{
- echo git/diff '[-b branch] [file ...]' >[2=1]
+ echo usage: $0 '[-b branch] [file ...]' >[1=2]
exit usage
}
@@ -13,7 +13,7 @@
}
git/fs
-while(~ $1 -*){
+while(~ $1 -* && ! ~ $1 --){
switch($1){
case -b; branch=`{git/query $2}; shift
case *; usage
@@ -20,6 +20,7 @@
}
shift
}
+if(~ $1 --) shift
if(~ $#branch 0)
branch=`{git/branch}
--- a/init
+++ b/init
@@ -3,28 +3,27 @@
rfork e
fn usage{
- echo git/init [-b] name >[1=2]
- echo ' -b init bare repository' >[1=2]
+ echo $0 '[-b] [-u upstream] name
+ -b: init bare repository' >[1=2]
exit usage
}
sub='/.git'
upstream=()
-while(~ $1 -*){
+while(~ $1 -* && ! ~ $1 --){
switch($1){
- case '-b';
+ case -b
sub=''
- case '-u';
+ case -u
+ upstream=$2
shift
- if(~ $#* 0)
- usage
- upstream=$1
- shift
- case *;
+ case *
usage
}
shift
}
+if(~ $1 --)
+ shift
if (~ $#* 0)
dir=.
--- a/log
+++ b/log
@@ -2,34 +2,40 @@
rfork en
+nl='
+'
+
+fn usage {
+ echo usage: $0 '[-b branch] [file ...]' >[1=2]
+ exit usage
+}
+
+
base=/mnt/git/object/
-branch=master
git/fs
+branch=master
while(~ $1 -* && ! ~ $1 --){
switch($1){
- case -b;
+ case -b
+ branch=$2
shift
- branch=$1
- case -*;
- exit usage
+ case *
+ usage
}
shift
}
-commits=(`{git/query $branch})
-
-# Logging a directory needs a recursive list.
+if(~ $1 --)
+ shift
+commits=`{git/query $branch}
files=()
-for(f in $*){
- if(test -d $f)
- files=($files `{walk -f $f})
- if not
- files=($files $f)
-}
+if(! ~ $#* 0)
+ files=`$nl{walk -f $*}
if(! ~ $#files 0)
nids=`{sha1sum $base/$commits(1)^/tree/$files | awk '{print $1}' >[2]/dev/null}
-while(! ~$#commits 0){
+
+while(! ~ $#commits 0){
ids=$nids
c=$commits(1)
if(! ~ $#files 0)
@@ -37,16 +43,11 @@
commits=($commits(2-) `{cat $base/$c/parent >[2]/dev/null})
if(! ~ $#commits 0)
- commits=`{mtime $base^$commits |
- sort -rn | uniq |
- awk -F/ '{print $NF}'}
+ commits=`$nl{walk -emp -n0 $base^$commits | sort -rn | uniq | awk -F/ '{print $NF}'}
if(~ $#files 0 || ! ~ $"ids $"nids || ~ $#commits 0){
- echo 'Hash: ' `{cat $base/$c/hash}
- echo 'Author: ' `{cat $base/$c/author}
- cat $base/$c/msg | sed 's/^/ /g'
- echo ''
+ echo 'Hash: '^`''{cat $base/$c/hash}^'Author: '^`''{cat $base/$c/author}
+ sed 's/^/ /g' $base/$c/msg
+ echo
}
-
-
}
--- a/merge
+++ b/merge
@@ -22,7 +22,7 @@
}
fn usage{
- echo usage: $argv0 theirs
+ echo usage: $0 theirs >[1=2]
exit usage
}
--- a/pull
+++ b/pull
@@ -34,9 +34,9 @@
}
fn usage{
- echo 'usage: $argv0 [-a] [-u upstream] [-b branch]' >[1=2]
- echo ' -u up: pull from upstream "up" (default: origin)' >[1=2]
- echo ' -f: fetch without updating working copy' >[1=2]
+ echo usage: $0 '[-a] [-u upstream] [-b branch]
+ -u up: pull from upstream "up" (default: origin)
+ -f: fetch without updating working copy' >[1=2]
exit usage
}
@@ -47,23 +47,23 @@
upstream=origin
while(~ $1 -*){
switch($1){
- case -u;
- shift
- remote=$1
+ case -u
upstream=SOMEONE
- case -b:
+ remote=$2
shift
- branch=$1
- case -f;
+ case -b
+ branch=$2
+ shift
+ case -f
update=''
- case *;
+ case *
usage
}
shift
}
-
if(! ~ $#* 0)
usage
+
if(~ $#remote 0)
remote=`{git/conf 'remote "'$upstream'".url'}
if(~ $#remote 0){
@@ -77,7 +77,7 @@
dir=/mnt/git/branch/$branch/tree
if(! git/walk -q){
echo $status
- echo 'repository is dirty: commit before pulling' >[1=2]
+ echo 'repository is dirty; commit before pulling' >[1=2]
exit 'dirty'
}
oldfiles=`$nl{git/walk -cfT}
--- a/push
+++ b/push
@@ -10,10 +10,10 @@
git/fs
fn usage {
- echo 'usage: git/push [-a] [-u upstream] [-b branch] [-r rmbranch]' >[1=2]
- echo ' -a: push all' >[1=2]
- echo ' -u upstream: push to repo "upstream" (default: origin)' >[1=2]
- echo ' -b branch: push branch "branch" (default: current branch)' >[1=2]
+ echo usage: $0 '[-a] [-u upstream] [-b branch] [-r rmbranch]
+ -a: push all
+ -u upstream: push to repo "upstream" (default: origin)
+ -b branch: push branch "branch" (default: current branch)' >[1=2]
exit usage
}
@@ -23,22 +23,23 @@
force=()
upstream='origin'
branch=`{awk '$1=="branch"{print $2}' < /mnt/git/ctl}
-while(~ $1 -* && ! ~ $1 --){
+while(~ $1 -*){
switch($1){
- case -u;
+ case -u
shift
upstream=$1
- case -a;
+ case -a
sendall=true
- case -b;
+ case -b
shift
branch=$1
- case -r;
+ case -r
shift
remove=(-r$1 $remove);
- case -f;
+ case -f
force=-f
- case *; usage
+ case *
+ usage
}
shift
}
@@ -57,8 +58,9 @@
updates=`$nl{git/send $force -b $branch $remove $remote}
if not
updates=`$nl{git/send $force $remove -a $remote}
-if(! ~ $status '')
- exit $status
+x=$status
+if(! ~ $x '')
+ exit $x
for(ln in $updates){
u=`{echo $ln}