git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Sep 19, 2008, 09:55 UTC
Message-ID
<1221818101-14333-2-git-send-email-bert.wesarg@googlemail.com>
In-Reply-To
<1221818101-14333-1-git-send-email-bert.wesarg@googlemail.com>

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@googlemail.com>
---
 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)
Previous: Bert WesargNext: Petr Baudis
Message 2 of 9 in “prev/next/tsort: commands to explore dependencies”
  1. prev/next/tsort: commands to explore dependenciesBert Wesarg, Sep 19, 2008
  2. tg-patch: add From/Date: line to header and print to fileBert Wesarg, Sep 19, 2008
  3. Petr BaudisSep 22, 2008
  4. Bert WesargSep 22, 2008
  5. Petr BaudisSep 22, 2008
  6. Bert WesargSep 22, 2008
  7. Uwe Kleine-KönigSep 22, 2008
  8. Bert WesargSep 22, 2008
  9. Petr BaudisSep 24, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.