{"thread":{"id":"26491","subject":"[PATCH] guilt: improve patch header handling","startedAt":"2011-02-14T04:55:03Z","lastAt":"2011-02-14T04:55:03Z","messageCount":1,"participants":["Mike Galbraith"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"161024","messageId":"1297659303.7999.28.camel@marge.simson.net","threadId":"26491","inReplyTo":null,"subject":"[PATCH] guilt: improve patch header handling","fromName":"Mike Galbraith","fromEmail":"mgalbraith@suse.de","sentAt":"2011-02-14T04:55:03Z","receivedAt":"2011-02-14T04:55:03Z","isPatch":true,"sender":{"key":"mgalbraith@suse.de","avatar":null},"body":"Greetings,\n\nBelow is a hacklet which made guilt more useful for my workflow.\nEntirely disposable, just sharing.\n\n\t-Mike\n\nTeach guilt to handle patch header Date Author AuthorDate etc lines,\nto deal properly with git commits and tip-bot patches.  Previously,\na Date line in the patch header was emitted into the commit message\nbody, which seems to confuse git format-patch.\n\nWith this applied, git log emits..\n   commit 40298016b331950394a4d6e12909506afc3cf54b\n   Author: Mike Galbraith <efault@gmx.de>\n   Date:   Sun Feb 13 07:16:35 2011 +0100\n..and gitk\n   Author: Mike Galbraith <efault@gmx.de>  2011-02-13 07:16:35\n   Committer: Mike Galbraith <mgalbraith@suse.de>  2011-02-14 05:09:05\n..and git format-patch\n   From 40298016b331950394a4d6e12909506afc3cf54b Mon Sep 17 00:00:00 2001\n   From: Mike Galbraith <efault@gmx.de>\n   Date: Sun, 13 Feb 2011 07:16:35 +0100\n   Subject: [PATCH] guilt: improve patch header handling\n\nWhereas previously, git log emitted..\n   commit 19e82183944cb645bb8f1f4c2fbcd3ee99698b05\n   Author: Mike Galbraith <efault@gmx.de>\n   Date:   Mon Feb 14 05:24:10 2011 +0100  <== commit date\n\n   guilt: improve patch header handling\n   Date: Sun Feb 13 07:16:35 CET 2011  <== lands between subject and body\nand gitk...\n   Author: Mike Galbraith <efault@gmx.de>  2011-02-14 05:24:10  <== authordate wrong\n   Committer: Mike Galbraith <mgalbraith@suse.de>  2011-02-14 05:24:10\nand git format-patch\n   From 19e82183944cb645bb8f1f4c2fbcd3ee99698b05 Mon Sep 17 00:00:00 2001\n   From: Mike Galbraith <efault@gmx.de>\n   Date: Mon, 14 Feb 2011 05:24:10 +0100\n   Subject: [PATCH] guilt: improve patch header handling\n    Date: Sun Feb 13 07:16:35 CET 2011  <== lands in subject when imported into evolution\n\nSigned-off-by: Mike Galbraith <efault@gmx.de>\nCc: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>\n---\n guilt |   54 +++++++++++++++++++++++++++++++++++++++---------------\n 1 files changed, 39 insertions(+), 15 deletions(-)\n\ndiff --git a/guilt b/guilt\nindex ec4fb04..875fc06 100755\n--- a/guilt\n+++ b/guilt\n@@ -342,17 +342,24 @@ BEGIN{}\n # usage: do_get_header patchfile\n do_get_header()\n {\n-\t# The complexity arises from the fact that we want to ignore the\n-\t# From line and the empty line after it if it exists\n-\n-\t# 2nd line skips the From line\n-\t# 3rd line skips the empty line right after a From line\n-\t# 4th line terminates execution when we encounter the diff\n+\t# The complexity arises from the fact that we want to ignore all\n+\t# but the Subject line of the header, and any empty lines after it,\n+\t# if these exist, and inject only the Subject line as the first\n+\t# line of the commit message.\n+\n+\t# 1st line prints first encountered Subject line plus empty line.\n+\t# 2nd line skips standard email/git patch header lines.\n+\t# 3rd line skips tip's additional header lines.\n+\t# 4th line skips any empty lines thereafter.\n+\t# 5th line turns off empty line skip upon seeing a non-empty line.\n+\t# 6th line terminates execution when we encounter the diff\n \tcat \"$1\" | awk '\n-BEGIN{skip=0}\n-/^Subject:/ && (NR==1){print substr($0, 10); next}\n-/^From:/{skip=1; next}\n-/^[ \\t\\f\\n\\r\\v]*$/ && (skip==1){skip=0; next}\n+BEGIN{body=0; subj=0}\n+/^Subject:/ && (body == 0 && subj == 0){subj=1; print substr($0, 10) \"\\n\"; next}\n+/^(Subject:|From:|Author:|Date:|commit)/ && (body == 0){next}\n+/^(Commit-ID:|Gitweb:|AuthorDate:|Committer:CommitDate:)/ && (body == 0){next}\n+/^[ \\t\\f\\n\\r\\v]*$/ && (body==0){next}\n+/^.*$/ && (body==0){body=1}\n /^(diff |---$|--- )/{exit}\n {print $0}\n END{}\n@@ -526,13 +533,26 @@ commit()\n \t\t# make a default commit message if patch doesn't contain one\n \t\t[ ! -s \"$TMP_MSG\" ] && echo \"patch $pname\" > \"$TMP_MSG\"\n \n-\t\t# extract a From line from the patch header, and set\n-\t\t# GIT_AUTHOR_{NAME,EMAIL}\n-\t\tauthor_str=`sed -n -e '/^From:/ { s/^From: //; p; q; }; /^(diff |---$|--- )/ q' \"$p\"`\n+\t\t# extract author and date lines from the patch header, and set\n+\t\t# GIT_AUTHOR_{NAME,EMAIL,DATE}\n+\t\t# prefering Author/AuthorDate lines if available.\n+\t\tauthor_str=`sed -n -e '/^Author:/ { s/^Author: //; p; q; }; /^(diff |---$|--- )/ q' \"$p\"`\n+\t\tif [ -z \"$author_str\" ]; then\n+\t\t\tauthor_str=`sed -n -e '/^From:/ { s/^From: //; p; q; }; /^(diff |---$|--- )/ q' \"$p\"`\n+\t\tfi\n+\n \t\tif [ ! -z \"$author_str\" ]; then\n \t\t\tGIT_AUTHOR_NAME=`echo $author_str | sed -e 's/ *<.*$//'`\n \t\t\texport GIT_AUTHOR_NAME=\"${GIT_AUTHOR_NAME:-\" \"}\"\n                         export GIT_AUTHOR_EMAIL=\"`echo $author_str | sed -e 's/[^<]*//'`\"\n+\n+\t\t\tauthor_date_str=`sed -n -e '/^AuthorDate:/ { s/^AuthorDate: //; p; q; }; /^(diff |---$|--- )/ q' \"$p\"`\n+\t\t\tif [ -z \"$author_date_str\" ]; then\n+\t\t\t\tauthor_date_str=`sed -n -e '/^Date:/ { s/^Date: //; p; q; }; /^(diff |---$|--- )/ q' \"$p\"`\n+\t\t\tfi\n+\t\t\tif [ ! -z \"$author_date_str\" ]; then\n+\t\t\t\texport GIT_AUTHOR_DATE=`echo $author_date_str`\n+\t\t\tfi\n \t\tfi\n \n \t\tct=`git log -1 --pretty=%ct`\n@@ -549,9 +569,13 @@ commit()\n \t\t# confused, and makes up strange timestamps from the past\n \t\t# (chances are it decides to interpret it as a unix\n \t\t# timestamp).\n-\t\texport GIT_AUTHOR_DATE=\"`stat -c %y \"$p\" | sed -e '\n+\t\texport GIT_COMMITTER_DATE=\"`stat -c %y \"$p\" | sed -e '\n s/^\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\.[0-9]* \\(.*\\)$/\\1-\\2-\\3 \\4:\\5:\\6 \\7/'`\"\n-\t\texport GIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\"\n+\n+\t\t# export GIT_AUTHOR_DATE only if a Date line was unavailable\n+\t\tif [ -z \"$author_date_str\" ]; then\n+\t\t\texport GIT_AUTHOR_DATE=\"$GIT_COMMITTER_DATE\"\n+\t\tfi\n \n \t\t# commit\n \t\ttreeish=`git write-tree`\n-- \n1.7.4\n"}]}