summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2021-05-17 13:46:44 -0700
committerOri Bernstein <ori@eigenstate.org>2021-05-17 13:46:44 -0700
commit54cafd210657a38e7960de21fb092506659d69a0 (patch)
treeda3d113ebb3d55efcc8831355bfccfb2055f89c1
parent2321062d2f73709afa85f002a6a0c7917ac307d4 (diff)
downloadplan9front-54cafd210657a38e7960de21fb092506659d69a0.tar.xz
git: add missing file
Forgot to add common.rc in the initial commit.
-rw-r--r--sys/lib/git/common.rc91
1 files changed, 91 insertions, 0 deletions
diff --git a/sys/lib/git/common.rc b/sys/lib/git/common.rc
new file mode 100644
index 000000000..573612712
--- /dev/null
+++ b/sys/lib/git/common.rc
@@ -0,0 +1,91 @@
+nl='
+'
+
+fn die{
+ >[1=2] echo $0: $*
+ exit $"*
+}
+
+fn usage{
+ >[1=2] echo -n 'usage:' $usage
+ exit 'usage'
+}
+
+# subst [-g] this [that]
+fn subst{
+ awk 'BEGIN{
+ global = 0
+ for(i = 1; ARGV[i] ~ /^-/; i++){
+ if(ARGV[i] == "-g")
+ global = 1
+ ARGC--
+ }
+ this = ARGV[i++]; ARGC--
+ that = ARGV[i++]; ARGC--
+ }
+ {
+ if(global) gsub(this, that)
+ else sub(this, that)
+ print
+ }' $*
+}
+
+fn present {
+ if(~ $1 /dev/null && cmp $2 $3>/dev/null)
+ status=gone
+ if not if (~ $3 /dev/null && cmp $1 $2>/dev/null)
+ status=gone
+ if not
+ status=()
+}
+
+# merge1 out theirs base ours
+fn merge1 {
+ n=$pid
+ out=$1
+ theirs=$2
+ base=$3
+ ours=$4
+ tmp=$out.tmp
+ while(test -f $tmp){
+ tmp=$tmp.$n
+ n=`{echo $n + 1 | hoc}
+ }
+
+ if(! test -f $ours)
+ ours=/dev/null
+ if(! test -f $base)
+ base=/dev/null
+ if(! test -f $theirs)
+ theirs=/dev/null
+ if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
+ echo merge needed: $out
+
+ if(present $ours $base $theirs){
+ mv $tmp $out
+ git/add $out
+ }
+ if not {
+ rm -f $tmp $out
+ git/rm $out
+ }
+}
+
+fn gitup{
+ gitroot=`{git/conf -r >[2]/dev/null}
+ if(~ $#gitroot 0)
+ die 'not a git repository'
+ gitrel=`{pwd | subst '^'$"gitroot'/?'}
+ if(~ $#gitrel 0)
+ gitrel='.'
+ cd $gitroot
+ startfs=()
+ if(! test -e /mnt/git/ctl)
+ startfs=true
+ if(! grep -s '^repo '$gitroot'$' /mnt/git/ctl >[2]/dev/null)
+ startfs=true
+ if(~ $#startfs 1)
+ git/fs
+ if not
+ status=''
+}