shithub: git9

Download patch

ref: c44adda7a7ce4f2ee4babf384dc9d321d21e34ad
parent: 8bb01b6811d2e247e1dbbae1cc9b9543b31778fc
author: kvik <kvik@a-b.xyz>
date: Thu Apr 9 15:46:39 EDT 2020

Implement [PATCH n/m] patch numbers in git/export

--- a/export
+++ b/export
@@ -16,6 +16,8 @@
 scratch=/tmp/gitexport.$pid
 mkdir -p $scratch
 mkdir $scratch/a $scratch/b
+n=1
+m=$#commits
 for(c in $commits){
 	cp=`{git/query -p $c}
 	pp=`{git/query -p $c'^'}
@@ -29,12 +31,27 @@
 		echo From $c
 		echo From: `{cat $cp/author}
 		echo Date: `{date -m `{mtime $cp/author | awk '{print $1}'}}
-		echo Subject: [PATCH] `{sed 1q $cp/msg}
-		echo
-		sed '1d' $cp/msg
-
+		<$cp/msg awk '
+		BEGIN {RS = ""; FS = "\n"}
+		NR == 1 {
+			n = ENVIRON["n"]
+			m = ENVIRON["m"]
+			if(m > 1)
+				patch = sprintf("[PATCH %d/%d]", n, m)
+			else
+				patch = "[PATCH]"
+			printf "Subject: %s", patch
+			for(i = 1; i <= NF; i++)
+				printf " %s", $i
+			printf "\n\n"
+			next
+		}
+		{print; printf "\n"}'
 		ape/diff -urN a b
 	}
+	if(! ~ $n $m)
+		echo
+	n=`{echo $n + 1 | bc}
 }
 rm $scratch/a $scratch/b
 rm $scratch