shithub: git9

Download patch

ref: e2232a8ce3e56bd8bc0d6a83d82c28e49beacfec
parent: 511f40667c666de4d861e60b3bf089c3abcefd1b
author: glenda <[email protected]>
date: Wed Aug 28 21:26:49 EDT 2019

Implement 'git/export' to export commits.

--- /dev/null
+++ b/export
@@ -1,0 +1,45 @@
+#!/bin/rc
+
+rfork ne
+
+nl='
+'
+if(! cd `{git/conf -r})
+	exit 'not in git repository'
+git/fs
+q=$*
+if(~ $#q 0)
+	q=HEAD
+commits=`{git/query $q}
+x=$status
+if(! ~ $x ''){
+	echo 'could not find commits: '$x
+	exit $x
+}
+
+scratch=/tmp/gitexport.$pid
+mkdir -p $scratch
+for(c in $commits){
+	cp=`{git/query -p $c}
+	pp=`{git/query -p $c'^'}
+
+	@{
+		rfork n
+		cd $scratch
+		mkdir a
+		mkdir b
+		bind $pp/tree a
+		bind $cp/tree b
+		
+		echo From $c
+		echo From: `{cat $cp/author}
+		echo Date: `{date -t `{mtime $cp/author}}
+		echo Subject: [PATCH] `{sed 1q $cp/msg}
+		echo
+		sed '1d' $cp/msg
+
+		ape/diff -urN a b
+	}
+}
+rm $scratch/a $scratch/b
+rm $scratch
--- a/mkfile
+++ b/mkfile
@@ -16,6 +16,7 @@
 	clone\
 	commit\
 	diff\
+	export\
 	init\
 	log\
 	merge\