{"thread":{"id":"1299","subject":"[PATCH] git-format-patch-script and mailinfo updates.","startedAt":"2005-07-22T23:04:34Z","lastAt":"2005-07-22T23:04:34Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6341","messageId":"7vackeigsd.fsf@assigned-by-dhcp.cox.net","threadId":"1299","inReplyTo":null,"subject":"[PATCH] git-format-patch-script and mailinfo updates.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-22T23:04:34Z","receivedAt":"2005-07-22T23:04:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\n - avoid duplicating [PATCH] in the commit message body if the\n   original commit has it already (happens for commits done from\n   mails via applymbox).\n\n - check if the commit author is different from the one who is\n   running the script, and emit an appropriate \"From:\" and\n   \"Date: \" lines to the output.\n\n - with '--date', emit \"Date: \" line to preserve the original\n   author date even for the user's own commit.\n\n - teach mailinfo to grok not just \"From: \" but \"Date: \".\n\nThe patch e-mail output by format-patch starts with the first\nline from the original commit message, prefixed with [PATCH],\nand optionally a From: line if you are reformatting a patch\nobtained from somebody else, a Date: line from the original\ncommit if (1) --date is specified or (2) for somebody else's\npatch, and the rest of the commit message body.\n\nExpected use of this is to move the title line from the commit\nto Subject: when sending it via an e-mail, and leave the From:\nand the Date: lines as the first lines of your message.\n\nThe mailinfo command has been changed to read Date: (in addition\nto From: it already understands) and do sensible things when\nrunning applymbox.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n git-format-patch-script |   38 +++++++++++++++++++++++++++++++-------\n tools/mailinfo.c        |   10 +++++++++-\n 2 files changed, 40 insertions(+), 8 deletions(-)\n\n70e9ebdaa9951183d2e4f9b569dafbc50012d8ec\ndiff --git a/git-format-patch-script b/git-format-patch-script\n--- a/git-format-patch-script\n+++ b/git-format-patch-script\n@@ -30,6 +30,8 @@ outdir=./\n while case \"$#\" in 0) break;; esac\n do\n     case \"$1\" in\n+    -d|--d|--da|--dat|--date)\n+    date=t ;;\n     -n|--n|--nu|--num|--numb|--numbe|--number|--numbere|--numbered)\n     numbered=t ;;\n     -o=*|--o=*|--ou=*|--out=*|--outp=*|--outpu=*|--output=*|--output-=*|\\\n@@ -56,6 +58,8 @@ esac\n junio=`git-rev-parse --verify \"$junio\"`\n linus=`git-rev-parse --verify \"$linus\"`\n \n+me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`\n+\n case \"$outdir\" in\n */) ;;\n *) outdir=\"$outdir/\" ;;\n@@ -66,6 +70,7 @@ tmp=.tmp-series$$\n trap 'rm -f $tmp-*' 0 1 2 3 15\n \n series=$tmp-series\n+commsg=$tmp-commsg\n \n titleScript='\n \t/./d\n@@ -82,6 +87,12 @@ titleScript='\n \tq\n '\n \n+whosepatchScript='\n+/^author /{\n+\ts/author \\(.*>\\) \\(.*\\)$/au='\\''\\1'\\'' ad='\\''\\2'\\''/p\n+\tq\n+}'\n+\n _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\n _x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n stripCommitHead='/^'\"$_x40\"' (from '\"$_x40\"')$/d'\n@@ -91,9 +102,8 @@ total=`wc -l <$series`\n i=$total\n while read commit\n do\n-    title=`git-cat-file commit \"$commit\" |\n-    git-stripspace |\n-    sed -ne \"$titleScript\"`\n+    git-cat-file commit \"$commit\" | git-stripspace >$commsg\n+    title=`sed -ne \"$titleScript\" <$commsg`\n     case \"$numbered\" in\n     '') num= ;;\n     *)\n@@ -102,6 +112,7 @@ do\n \t*) num=' '`printf \"%d/%d\" $i $total` ;;\n \tesac\n     esac\n+\n     file=`printf '%04d-%stxt' $i \"$title\"`\n     i=`expr \"$i\" - 1`\n     echo \"$file\"\n@@ -109,15 +120,28 @@ do\n \tmailScript='\n \t/./d\n \t/^$/n\n-\ts|^|[PATCH'\"$num\"'] |\n+\ts|^\\[PATCH[^]]*\\] *||\n+\ts|^|[PATCH'\"$num\"'] |'\n+\n+\teval \"$(sed -ne \"$whosepatchScript\" $commsg)\"\n+\ttest \"$au\" = \"$me\" || {\n+\t\tmailScript=\"$mailScript\"'\n+\ta\\\n+From: '\"$au\"\n+\t}\n+\ttest \"$date,$au\" = \",$me\" || {\n+\t\tmailScript=\"$mailScript\"'\n+\ta\\\n+Date: '\"$ad\"\n+\t}\n+\n+\tmailScript=\"$mailScript\"'\n \t: body\n \tp\n \tn\n \tb body'\n \n-\tgit-cat-file commit \"$commit\" |\n-\tgit-stripspace |\n-\tsed -ne \"$mailScript\"\n+\tsed -ne \"$mailScript\" <$commsg\n \techo '---'\n \techo\n \tgit-diff-tree -p $diff_opts \"$commit\" | git-apply --stat --summary\ndiff --git a/tools/mailinfo.c b/tools/mailinfo.c\n--- a/tools/mailinfo.c\n+++ b/tools/mailinfo.c\n@@ -220,8 +220,9 @@ static int eatspace(char *line)\n static void handle_body(void)\n {\n \tint has_from = 0;\n+\tint has_date = 0;\n \n-\t/* First line of body can be a From: */\n+\t/* First lines of body can have From: and Date: */\n \twhile (fgets(line, sizeof(line), stdin) != NULL) {\n \t\tint len = eatspace(line);\n \t\tif (!len)\n@@ -232,6 +233,13 @@ static void handle_body(void)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t}\n+\t\tif (!memcmp(\"Date:\", line, 5) && isspace(line[5])) {\n+\t\t\tif (!has_date) {\n+\t\t\t\thandle_date(line+6);\n+\t\t\t\thas_date = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t}\n \t\tline[len] = '\\n';\n \t\thandle_rest();\n \t\tbreak;\n"}]}