[TopGit PATCH] tg-patch: add From/Date: line to header and print to file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To make this more similar to git format-patch, I added a 'From' and
a 'Date:' header and let 'tg patch' print to a file (which is shown as output).

Regards
Bert

Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx>

---
 tg-patch.sh |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/tg-patch.sh b/tg-patch.sh
index 7a24718..5fc5cfd 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -24,7 +24,26 @@ done
 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit-controlled branch"
 
-git cat-file blob "$name:.topmsg"
+subject="$(git cat-file blob "$name:.topmsg" | grep '^Subject: ' | sed -e 's/^Subject: //' -e 's/\[.*\] //')"
+file_name="$(echo "$subject" | tr -c '[[:alnum:]_.]' '_').patch"
+rev="$(git rev-parse --verify "refs/heads/$name" 2>/dev/null)"
+
+echo "$file_name"
+exec 3>&1
+exec 1>"$file_name"
+
+printf "From %s Mon Sep 17 00:00:00 2001\n" "$rev"
+now="$(date --rfc-2822)"
+git cat-file blob "$name:.topmsg" |
+	awk '
+		{
+			print
+			if (/^From:/ && !date_printed) {
+				printf "Date: %s\n", "'"$now"'"
+				date_printed = 1
+			}
+		}
+	'
 echo
 [ -n "$(git grep '^[-]--' "$name" -- ".topmsg")" ] || echo '---'
 
@@ -42,5 +61,9 @@ rm "$git_is_stupid"
 
 echo '-- '
 echo "tg: ($base_rev..) $name (depends on: $(git cat-file blob "$name:.topdeps" | paste -s -d' '))"
+
+exec 1>&3
+exec 3>&-
+
 branch_contains "$name" "$base_rev" ||
 	echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."
-- 
tg: (7ec3927..) t/patch (depends on: t/queue-movement)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux