code: plan9front

Download patch

ref: 126cc163e20e0dca5851151d901f6d9eac5745b9
parent: 21aac62c1f0fa565a860d4880ec56b84eb9dd8dd
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jul 3 00:25:08 EDT 2022

git/compat: expand to cover go bootstrap

go bootstrap uses more of git than we supported, so
stub in enough that we can bootstrap go.

--- a/sys/src/cmd/git/compat
+++ b/sys/src/cmd/git/compat
@@ -94,7 +94,7 @@
 			echo `{dcmd git9/branch | sed s@^heads/@@g}
 			shift
 		case *
-			dprint option $opt
+			die unknown option $opt
 		}
 		shift
 	}
@@ -112,6 +112,15 @@
 		echo `{cat $gitroot/.git/refs/$b} refs/$b 
 }
 
+fn cmd_rev-parse{
+	switch($1){
+	case --git-dir
+		echo `{git/conf -r}^/.git
+	case *
+		die 'unknown rev-parse '$*
+	}
+}
+
 fn cmd_remote{
 	if({! ~ $#* 3 && ! ~ $#* 4} || ! ~ $1 add)
 		die unimplemented remote cmd $*
@@ -125,6 +134,44 @@
 	}
 }
 
+fn cmd_log{
+	count=()
+	format=''
+	while(~ $1 -*){
+		switch($1){
+		case --format
+			format=$2
+			shift
+		case '--format='*
+			format=`{echo $1 | sed 's/--format=//g'}
+		case -n
+			count=-n$2
+			shift
+		case -n*
+			count=$1
+		case *
+			dprint option $opt
+		}
+		shift
+	}
+	@{cd $gitroot && git/fs}
+	switch($format){
+	case ''
+		git/log $count
+	case '%H:%ct'
+		for(c in `{git/log -s $count| awk '{print $1}'})
+			echo $c:`{mtime $gitroot/.git/fs/object/$c/msg}
+	case '%h %cd'
+		for(c in `{git/log -s $count| awk '{print $1}'})
+			echo $c `{date `{mtime $gitroot/.git/fs/object/$c/msg}}
+	}
+
+}
+
+fn cmd_show{
+	cmd_log -n1 $*
+}
+
 fn cmd_ls-remote{
 	if(~ $1 -q)
 		shift
@@ -138,6 +185,9 @@
 	echo git version 2.2.0
 }
 
+fn cmd_status{
+	echo
+}
 
 fn usage{
 	echo 'git <command> <args>' >[1=2]
@@ -158,11 +208,20 @@
 	exec rc
 }
 
+if(~ $#gitcompatdebug 1)
+	echo running  $* >>/tmp/gitlog
+
+if(~ $1 -c)
+	shift 2
+if(~ $1 -c*)
+	shift 1
 if(! test -f '/env/fn#cmd_'$1)
 	die git $1: commmand not implemented
 if(! ~ $1 init && ! ~ $1 clone)
 	gitroot=`{git/conf -r} || die repo
 
-echo $* >/tmp/gitlog
-cmd_$1 $*(2-)
+if(~ $#gitcompatdebug 1)
+	cmd_$1 $*(2-) | tee >>/tmp/gitlog
+if not
+	cmd_$1 $*(2-)
 exit ''