shithub: git9

Download patch

ref: abb40d07ea989f78c521e08378db9707d76c8c0f
parent: 8f939a705d3ff09c59da394110bba9c5b4c3393f
author: Ori Bernstein <[email protected]>
date: Fri Apr 17 14:20:03 EDT 2020

Shuffle flags for consistency.

-q => quiet, changing git/log to use -e for query expressions
-c => commit, changing git/branch to use -n for new branches
-a => show all available branches in git/branch
git/pull -i=> git/pull; the old behavior is git/pull -q
and a few other small tweaks.

--- a/branch
+++ b/branch
@@ -5,7 +5,7 @@
 usage='
 	git/branch [-cdsu] [-b base] [branch]
 		-b base   base new branch on "base" (default: current branch)
-		-c        clobber or create branch
+		-n        create new branch, or overwrite existing branch
 		-d        delete branch
 		-s        create branch but stay on current one
 '
@@ -13,18 +13,20 @@
 gitup
 
 stay=()
-create=()
+newbr=()
 delete=()
 baseref=()
 modified=()
 deleted=()
+listall=()
 
 while(~ $1 -* && ! ~ $1 --){
 	switch($1){
-	case -c; create=true
+	case -n; newbr=true
 	case -s; stay=true
 	case -b; baseref=$2; shift
 	case -d; delete=true
+	case -a; listall=true
 	case *
 		usage
 	}
@@ -34,7 +36,10 @@
 	shift
 
 if(~ $#* 0){
-	awk '$1=="branch"{print $2}' < /mnt/git/ctl
+	if(~ $#listall 0)
+		awk '$1=="branch"{print $2}' < /mnt/git/ctl
+	if not
+		cd .git/refs/ && walk -f heads remotes
 	exit
 }
 if(! ~ $#* 1)
@@ -46,8 +51,11 @@
 	new=refs/$1
 if not
 	new=refs/heads/$1
-if (~ $#baseref 1)
+if (~ $#baseref 1){
 	base=`{git/query $baseref}
+	if(! ~ $status '')
+		exit badbase
+}
 if not if(test -e .git/$new)
 	base=`{git/query $new}
 if not
@@ -66,7 +74,7 @@
 	rm -f .git/$new
 	exit
 }
-if(~ $#create 0){
+if(~ $#newbr 0){
 	if(! test -e .git/$new)
 		die could not find branch $1
 	if(! ~ $#baseref 0)
--- a/git.1
+++ b/git.1
@@ -14,6 +14,9 @@
 .PP
 .B git/branch
 [
+.B -a
+]
+[
 .B -b
 .I base
 ]
@@ -49,6 +52,9 @@
 .I branch
 ]
 [
+.B -a
+]
+[
 .B -s
 ]
 [
@@ -106,6 +112,12 @@
 .B -f
 ]
 [
+.B -q
+]
+[
+.B -a
+]
+[
 .B -u
 .I upstream
 ]
@@ -245,22 +257,10 @@
 
 
 .PP
-Git/fs serves the following directories:
+Git/fs serves a file system on /mnt/git.
+For full documentation, see
+.I gitfs(4)
 
-.TP
-/mnt/git/object
-The objects in the repo.
-.TP
-/mnt/git/branch
-The branches and tags in the repo.
-.TP
-/mnt/git/ctl
-A file showing the status of the repo.
-Currently, it only shows the current branch.
-.TP
-/mnt/git/HEAD
-An alias for the currently checked out commit directory.
-
 .PP
 .B Git/add
 adds a file to the list of tracked files. When passed the
@@ -274,7 +274,12 @@
 
 .PP
 .B Git/branch
-is used to switch between branches.
+is used to list or switch branches.
+When invoked with no arguments, it lists the current branch.
+To list all branches, pass the
+.I -a
+option.
+To switch between branches, pass a branch name.
 When passed the
 .I -c
 option, the branch will be created if it does not yet exist.
@@ -300,9 +305,9 @@
 .I -s
 option shows a summary of the commit, instead of the full message.
 The
-.I -q query
-option shows commits matching the query provided. The query
-is specified using the syntax of
+.I -e expr
+option shows commits matching the query expression provided.
+The expression is in the syntax of
 .B git/query.
 
 .PP
--- a/log
+++ b/log
@@ -3,7 +3,7 @@
 . /sys/lib/git/common.rc
 
 usage='
-	git/log [-q query|-c commit] [-s] [file ...]
+	git/log [-e expr|-c commit] [-s] [file ...]
 '
 
 gitup
@@ -10,7 +10,7 @@
 
 base=/mnt/git/object/
 branch=`{git/branch}
-query=()
+expr=()
 short=()
 files=()
 while(~ $1 -* && ! ~ $1 --){
@@ -18,8 +18,8 @@
 	case -c
 		base=$2
 		shift
-	case -q
-		query=$2
+	case -e
+		expr=$2
 		shift
 	case -s
 		short=true
@@ -30,10 +30,10 @@
 }
 if(~ $1 --)
 	shift
-if(~ $#query 0)
+if(~ $#expr 0)
 	commits=`{git/query $branch}
 if not
-	commits=`{git/query $query}
+	commits=`{git/query $expr}
 
 if(! ~ $#* 0)
 	files=`"{walk -f $gitrel/^$* | subst '^\./' | sort}
@@ -48,7 +48,7 @@
 			show=true
 	}
 	commits=$commits(2-)
-	if(~ $#query 0)
+	if(~ $#expr 0)
 		commits=($commits `{cat $base/$c/parent >[2]/dev/null})
 	if(! ~ $#commits 0)
 		commits=`$nl{walk -emp -n0 $base^$commits | sort -rn | uniq | awk -F/ '{print $NF}'}
--- a/pull
+++ b/pull
@@ -37,7 +37,7 @@
 
 branch=refs/`{git/branch}
 remote=()
-incoming=()
+incoming=true
 checkout='true'
 upstream=origin
 
@@ -58,8 +58,8 @@
 		branch=''
 	case -f
 		checkout=()
-	case -i
-		incoming=true
+	case -q
+		incoming=()
 	case *
 		usage
 	}
@@ -99,7 +99,8 @@
 }
 # The remote is directly ahead of the local, and we have
 # no local commits that need merging.
-echo $remote':' `{git/query $local} '=>' `{git/query $remote}  >[1=2]
 if(! ~ $#incoming 0)
-	git/log -q $local'..'$remote
-git/branch -c -b $remote $local
+	git/log -s -e $local'..'$remote >[1=2]
+echo
+echo $remote':' `{git/query $local} '=>' `{git/query $remote}  >[1=2]
+git/branch -n -b $remote $local