ref: 38cdc76a8e5d190b90ccea94ab42d08d55e73dde
parent: 5b4249105002f51a84e02d29f1678ad52cf2e96b
author: kvik <[email protected]>
date: Thu Apr 9 17:48:44 EDT 2020
Implement patch directory output for git/export If `-o directory` parameter is given the commits being exported are diverted into respective patch files underneath the directory, which is created if necessary.
--- a/export
+++ b/export
@@ -3,11 +3,27 @@
. /sys/lib/git/common.rc
usage='
- git/export [query]
+ git/export [-o patchdir] [query]
'
gitup
+ramfs
+stdout='true'
+patchdir='.'
+while(~ $1 -* && ! ~ $1 --){
+ switch($1){
+ case -o
+ stdout='false'
+ shift; patchdir=$1
+ if(! test -d $patchdir)
+ mkdir -p $patchdir
+ }
+ shift
+}
+if(~ $1 --)
+ shift
+
q=$*
if(~ $#q 0)
q=HEAD
@@ -39,14 +55,22 @@
patch = "[PATCH]"
printf "Subject: %s", patch
for(i = 1; i <= NF; i++)
- printf " %s", $i
- printf "\n\n"
+ msg = msg " " $i
+ printf "%s\n\n", msg
+
+ gsub("^[ ]|[ ]$", "", msg)
+ gsub("[/ ]", "-", msg)
+ printf "%.4d-%s.patch", n, msg >"/tmp/patchname"
next
}
{print; printf "\n"}'
ape/diff -urN a b
+ } >/tmp/patchfile
+ if(~ $stdout true){
+ cat /tmp/patchfile
+ ! ~ $n $m && echo
}
- if(! ~ $n $m)
- echo
+ if not
+ mv /tmp/patchfile $patchdir/`{cat /tmp/patchname}
n=`{echo $n + 1 | bc}
}