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

[RFC PATCH 1/1] am: add gitk patch format

From
Chris Packham <judge.packham@gmail.com>
Date
Sep 3, 2014, 09:35 UTC
Message-ID
<1409736919-22341-2-git-send-email-judge.packham@gmail.com>
In-Reply-To
<1409736919-22341-1-git-send-email-judge.packham@gmail.com>

Patches created using gitk's "write commit to file" functionality (which uses 'git diff-tree -p --pretty' under the hood) need some massaging in order to apply cleanly. This consists of dropping the 'commit' line automatically determining the subject and removing leading whitespace.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
 Documentation/git-am.txt |    3 ++-
 git-am.sh                |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 9adce37..b59d2b3 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -101,7 +101,8 @@ default.   You can use `--no-utf8` to override this.
 	By default the command will try to detect the patch format
 	automatically. This option allows the user to bypass the automatic
 	detection and specify the patch format that the patch(es) should be
-	interpreted as. Valid formats are mbox, stgit, stgit-series and hg.
+	interpreted as. Valid formats are mbox, stgit, stgit-series, hg and
+	gitk.
 
 -i::
 --interactive::
diff --git a/git-am.sh b/git-am.sh
index ee61a77..73b0a86 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -227,6 +227,9 @@ check_patch_format () {
 		"# HG changeset patch")
 			patch_format=hg
 			;;
+		'commit '*)
+			patch_format=gitk
+			;;
 		*)
 			# if the second line is empty and the third is
 			# a From, Author or Date entry, this is very
@@ -357,6 +360,38 @@ split_patches () {
 		this=
 		msgnum=
 		;;
+	gitk)
+		# These patches are generates with 'git diff-tree -p --pretty'
+		# we discard the 'commit' line, after that the first line not
+		# starting with 'Author:' or 'Date:' is the subject. We also
+		# need to strip leading whitespace from the message body.
+		this=0
+		for gitk in "$@"
+		do
+			this=$(expr "$this" + 1)
+			msgnum=$(printf "%0${prec}d" $this)
+			@@PERL@@ -ne 'BEGIN { $subject = 0 }
+				s/^    // ;
+				if ($subject > 1) { print ; }
+				elsif (/^commit\s.*$/) { next ; }
+				elsif (/^\s+$/) { next ; }
+				elsif (/^Author:/) { s/Author/From/ ; print ;}
+				elsif (/^Date:/) { print ;}
+				elsif ($subject) {
+					$subject = 2 ;
+					print "\n" ;
+					print ;
+				} else {
+					print "Subject: ", $_ ;
+					$subject = 1;
+				}
+			' <"$gitk" >"$dotest/$msgnum" || clean_abort
+
+		done
+		echo "$this" >"$dotest/last"
+		this=
+		msgnum=
+		;;
 	*)
 		if test -n "$patch_format"
 		then
-- 
1.7.9.5
Previous: Chris PackhamNext: Chris Packham
Message 2 of 14 in “am: bug report and new patch format support”
  1. 0/1 am: bug report and new patch format supportChris Packham, Sep 3, 2014
  2. 1/1 am: add gitk patch formatChris Packham, Sep 3, 2014
  3. Chris PackhamSep 3, 2014
  4. Chris PackhamSep 3, 2014
  5. 0/2 am: bug fix and new patch format supportChris Packham, Sep 3, 2014
  6. 1/2 am: add gitk patch formatChris Packham, Sep 3, 2014
  7. Junio C HamanoSep 3, 2014
  8. Chris PackhamSep 4, 2014
  9. Junio C HamanoSep 4, 2014
  10. Chris PackhamSep 4, 2014
  11. 2/2 am: avoid re-directing stdin twiceChris Packham, Sep 3, 2014
  12. Chris PackhamSep 5, 2014
  13. Junio C HamanoSep 5, 2014
  14. Chris PackhamSep 5, 2014

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.