ref: a08453bf28d8178919b62d01b73e56c209f5b4d1
parent: 5d65bc0372824b98d8f909d8de3e5ee2c4c08668
author: kvik <[email protected]>
date: Thu Nov 14 22:04:31 EST 2019
Instead of each script defining their own ad-hoc usage function we define a generic handler in /bin/git/common.rc and have each script fill the $usage variable with a message that will get displayed on standard error output before exiting the program. This patch also makes an initial and weak attempt at cleaning up the usage messages to match the current implementation. Rest of the work, along with cleaning up the unused code paths will be done after further basic cleanups. Move usage handling to common.rc; update all scripts.
--- a/add
+++ b/add
@@ -1,11 +1,11 @@
#!/bin/rc -e
rfork ne
+. /bin/git/common.rc
-fn usage {
- echo usage: $0 '[-r] file ...
- -r: remove instead of adding' >[1=2]
- exit usage
-}
+usage='
+ git/add [-r] file ...
+ -r remove file
+'
add='tracked'
del='removed'
--- a/branch
+++ b/branch
@@ -1,15 +1,13 @@
#!/bin/rc -e
-
rfork en
+. /bin/git/common.rc
-fn usage{
- echo usage: $0 '[-b base] [-o origin] new
- -b base: use "base" for branch (default: current branch)
- -o origin: use "origin" for remote branch
- -u: update branch if it exists
- new: name of new branch' >[1=2]
- exit usage
-}
+usage='
+ git/branch [-cdsu] [-b base] [new]
+ -b base base new branch on "base" (default: current branch)
+ -d delete a branch
+ -s create a branch but stay on current one
+'
if(! cd `{git/conf -r}){
exit 'not in git repository'
--- a/clone
+++ b/clone
@@ -1,6 +1,11 @@
#!/bin/rc -e
-
rfork en
+. /bin/git/common.rc
+
+usage='
+ git/clone remote [local]
+'
+
nl='
'
@@ -7,10 +12,8 @@
remote=$1
local=$2
-if(~ $#remote 0){
- echo usage: $0 'remote [local]' >[1=2]
- exit usage
-}
+if(~ $#remote 0)
+ usage
if(~ $#local 0)
local=`{basename $remote .git}
--- a/commit
+++ b/commit
@@ -1,6 +1,10 @@
#!/bin/rc
-
rfork ne
+. /bin/git/common.rc
+
+usage='
+ git/commit
+'
nl='
'
--- /dev/null
+++ b/common.rc
@@ -1,0 +1,4 @@
+fn usage{
+ >[2=1] echo -n 'usage:' $usage
+ exit 'usage'
+}
--- a/diff
+++ b/diff
@@ -1,11 +1,11 @@
#!/bin/rc
-
rfork ne
+. /bin/git/common.rc
-fn usage{
- echo usage: $0 '[-b branch] [file ...]' >[1=2]
- exit usage
-}
+usage='
+ git/diff [-b branch] [file ...]
+ -b diff relative to branch "branch"
+'
if(! cd `{git/conf -r}){
echo 'not a git repository' >[1=2]
--- a/export
+++ b/export
@@ -1,6 +1,10 @@
#!/bin/rc
-
rfork ne
+. /bin/git/common.rc
+
+usage='
+ git/export [query]
+'
nl='
'
--- a/import
+++ b/import
@@ -1,6 +1,10 @@
#!/bin/rc
-
rfork ne
+. /bin/git/common.rc
+
+usage='
+ git/import [file ...]
+'
nl='
'
--- a/init
+++ b/init
@@ -1,12 +1,12 @@
#!/bin/rc
+rfork ne
+. /bin/git/common.rc
-rfork e
-
-fn usage{
- echo $0 '[-b] [-u upstream] name
- -b: init bare repository' >[1=2]
- exit usage
-}
+usage='
+ git/init [-b] [-u upstream] name
+ -b init bare repository
+ -u set remote "origin" to upstream
+'
sub='/.git'
upstream=()
--- a/log
+++ b/log
@@ -1,15 +1,13 @@
#!/bin/rc -e
-
rfork en
+. /bin/git/common.rc
-nl='
+usage='
+ git/log [-q query] [file ...]
'
-fn usage {
- echo usage: $0 '[-b branch] [file ...]' >[1=2]
- exit usage
-}
-
+nl='
+'
base=/mnt/git/object/
git/fs
--- a/merge
+++ b/merge
@@ -1,7 +1,11 @@
#!/bin/rc -e
-
rfork ne
+. /bin/git/common.rc
+usage='
+ git/merge theirs
+'
+
fn merge{
ourbr=$1/tree
basebr=$2/tree
@@ -19,11 +23,6 @@
if(! ape/diff3 -m $ourbr/$f $basebr/$f $theirbr/$f > $f)
echo merge needed: $f
}
-}
-
-fn usage{
- echo usage: $0 theirs >[1=2]
- exit usage
}
if(! ~ $#* 1)
--- a/mkfile
+++ b/mkfile
@@ -15,6 +15,7 @@
branch\
clone\
commit\
+ common.rc\
diff\
export\
import\
--- a/pull
+++ b/pull
@@ -1,7 +1,15 @@
#!/bin/rc -e
-
rfork en
+. /bin/git/common.rc
+usage='
+ git/pull [-u upstream] [-b branch]
+ -b work with branch "branch"
+ -f fetch updates without checking out
+ -i display incoming commits
+ -u pull from "upstream" (default "origin")
+'
+
nl='
'
@@ -31,14 +39,6 @@
}
'
}
-
-fn usage{
- 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
-}
-
if(! cd `{git/conf -r}){
echo 'not in git repository' >[1=2]
--- a/push
+++ b/push
@@ -1,7 +1,15 @@
#!/bin/rc
-
rfork en
+. /bin/git/common.rc
+usage='
+ git/push [-a] [-u upstream] [-b branch] [-r branch]
+ -a push all branches
+ -b push branch "branch" (default: current branch)
+ -r delete branch "branch" from upstream
+ -u push to remote "upstream" (default: origin)
+'
+
nl='
'
@@ -9,13 +17,6 @@
exit 'not in git repository'
git/fs
-fn usage {
- 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
-}
remote=()
sendall=''
--- a/revert
+++ b/revert
@@ -1,5 +1,12 @@
#!/bin/rc
+rfork e
+. /bin/git/common.rc
+usage='
+ git/revert [-c query] file [...]
+ -c revert to commit "query" (default: HEAD)
+'
+
commit=/mnt/git/HEAD
nl='
'
@@ -10,8 +17,7 @@
commit=`{git/query -p $2};
shift
case *;
- echo usage: $0 [-c commit] files...
- exit usage
+ usage
}
shift
}