{"thread":{"id":"4218","subject":"[PATCH] fmt-patch: Support --attach","startedAt":"2006-05-20T13:40:29Z","lastAt":"2006-05-20T20:23:04Z","messageCount":7,"participants":["Johannes Schindelin","Jakub Narebski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"20322","messageId":"Pine.LNX.4.63.0605201537290.17869@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4218","inReplyTo":null,"subject":"[PATCH] fmt-patch: Support --attach","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-20T13:40:29Z","receivedAt":"2006-05-20T13:40:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis patch touches a couple of files, because it adds options to print a \ncustom text just after the subject of a commit, and just after the \ndiffstat.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n\tMaybe it would be a good idea to store the options to \n\tpretty_print_commit() in a struct...\n\n\tAlso, I realized that it might be necessary to check the commit\n\tmessage for a single \".\" in a line, since that has special meaning\n\tin emails.\n\n builtin-log.c      |   13 ++++++++++---\n builtin-rev-list.c |    2 +-\n commit.c           |   10 +++++++++-\n commit.h           |    2 +-\n diff.c             |    5 ++++-\n diff.h             |    1 +\n log-tree.c         |   35 +++++++++++++++++++++++++++++++----\n revision.h         |    1 +\n show-branch.c      |    2 +-\n 9 files changed, 59 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 12a6d19..a30e974 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -183,7 +183,9 @@ int cmd_format_patch(int argc, const cha\n \t\t\t\t\t\targv[i + 1]);\n \t\t\toutput_directory = strdup(argv[i + 1]);\n \t\t\ti++;\n-\t\t} else\n+\t\t} else if (!strcmp(argv[i], \"--attach\"))\n+\t\t\trev.mime_boundary = \"050802040500080604070107\";\n+\t\telse\n \t\t\targv[j++] = argv[i];\n \t}\n \targc = j;\n@@ -224,8 +226,13 @@ int cmd_format_patch(int argc, const cha\n \t\tshown = log_tree_commit(&rev, commit);\n \t\tfree(commit->buffer);\n \t\tcommit->buffer = NULL;\n-\t\tif (shown)\n-\t\t\tprintf(\"-- \\n%s\\n\\n\", git_version_string);\n+\t\tif (shown) {\n+\t\t\tif (rev.mime_boundary)\n+\t\t\t\tprintf(\"\\n--------------%s--\\n\\n\\n\",\n+\t\t\t\t\t\trev.mime_boundary);\n+\t\t\telse\n+\t\t\t\tprintf(\"-- \\n%s\\n\\n\", git_version_string);\n+\t\t}\n \t\tif (!use_stdout)\n \t\t\tfclose(stdout);\n \t}\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 6a2e874..78b9c23 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -84,7 +84,7 @@ static void show_commit(struct commit *c\n \t\tstatic char pretty_header[16384];\n \t\tpretty_print_commit(revs.commit_format, commit, ~0,\n \t\t\t\t    pretty_header, sizeof(pretty_header),\n-\t\t\t\t    revs.abbrev, NULL);\n+\t\t\t\t    revs.abbrev, NULL, NULL);\n \t\tprintf(\"%s%c\", pretty_header, hdr_termination);\n \t}\n \tfflush(stdout);\ndiff --git a/commit.c b/commit.c\nindex 84558ba..0b163d4 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -498,7 +498,7 @@ static int add_merge_info(enum cmit_fmt \n \treturn offset;\n }\n \n-unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject)\n+unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject)\n {\n \tint hdr = 1, body = 0;\n \tunsigned long offset = 0;\n@@ -591,6 +591,14 @@ unsigned long pretty_print_commit(enum c\n \t\tbuf[offset++] = '\\n';\n \t\tif (fmt == CMIT_FMT_ONELINE)\n \t\t\tbreak;\n+\t\tif (after_subject) {\n+\t\t\tint slen = strlen(after_subject);\n+\t\t\tif (slen > space - offset - 1)\n+\t\t\t\tslen = space - offset - 1;\n+\t\t\tmemcpy(buf + offset, after_subject, slen);\n+\t\t\toffset += slen;\n+\t\t\tafter_subject = NULL;\n+\t\t}\n \t\tsubject = NULL;\n \t}\n \twhile (offset && isspace(buf[offset-1]))\ndiff --git a/commit.h b/commit.h\nindex 8d7514c..c9de167 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -51,7 +51,7 @@ enum cmit_fmt {\n };\n \n extern enum cmit_fmt get_commit_format(const char *arg);\n-extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject);\n+extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject);\n \n /** Removes the first commit from a list sorted by date, and adds all\n  * of its parents.\ndiff --git a/diff.c b/diff.c\nindex e16e0bf..3e2828b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1867,7 +1867,10 @@ void diff_flush(struct diff_options *opt\n \t\tshow_stats(diffstat);\n \t\tfree(diffstat);\n \t\tdiffstat = NULL;\n-\t\tputchar(options->line_termination);\n+\t\tif (options->stat_sep)\n+\t\t\tfputs(options->stat_sep, stdout);\n+\t\telse\n+\t\t\tputchar(options->line_termination);\n \t}\n \tfor (i = 0; i < q->nr; i++) {\n \t\tstruct diff_filepair *p = q->queue[i];\ndiff --git a/diff.h b/diff.h\nindex 7410607..83619eb 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -44,6 +44,7 @@ struct diff_options {\n \tint rename_limit;\n \tint setup;\n \tint abbrev;\n+\tconst char *stat_sep;\n \n \tint nr_paths;\n \tconst char **paths;\ndiff --git a/log-tree.c b/log-tree.c\nindex 526d578..7f0f54b 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -20,7 +20,7 @@ void show_log(struct rev_info *opt, stru\n \tint abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;\n \tconst char *extra;\n \tint len;\n-\tchar* subject = NULL;\n+\tchar *subject = NULL, *after_subject = NULL;\n \n \topt->loginfo = NULL;\n \tif (!opt->verbose_header) {\n@@ -52,6 +52,7 @@ void show_log(struct rev_info *opt, stru\n \t */\n \n \tif (opt->commit_format == CMIT_FMT_EMAIL) {\n+\t\tchar *sha1 = sha1_to_hex(commit->object.sha1);\n \t\tif (opt->total > 0) {\n \t\t\tstatic char buffer[64];\n \t\t\tsnprintf(buffer, sizeof(buffer),\n@@ -63,8 +64,34 @@ void show_log(struct rev_info *opt, stru\n \t\telse\n \t\t\tsubject = \"Subject: \";\n \n-\t\tprintf(\"From %s  Thu Apr 7 15:13:13 2005\\n\",\n-\t\t       sha1_to_hex(commit->object.sha1));\n+\t\tprintf(\"From %s Mon Sep 17 00:00:00 2001\\n\", sha1);\n+\t\tif (opt->mime_boundary) {\n+\t\t\tstatic char subject_buffer[1024];\n+\t\t\tstatic char buffer[1024];\n+\t\t\tsnprintf(subject_buffer, sizeof(subject_buffer) - 1,\n+\t\t\t\t\t\"MIME-Version: 1.0\\n\"\n+\t\t\t\t\t\"Content-Type: multipart/mixed;\\n\"\n+\t\t\t\t\t\" boundary=\\\"------------%s\\\"\\n\"\n+\t\t\t\t\t\"\\n\"\n+\t\t\t\t\t\"This is a multi-part message in MIME \"\n+\t\t\t\t\t\"format.\\n\"\n+\t\t\t\t\t\"--------------%s\\n\"\n+\t\t\t\t\t\"Content-Type: text/plain; \"\n+\t\t\t\t\t\"charset=UTF-8; format=fixed\\n\"\n+\t\t\t\t\t\"Content-Transfer-Encoding: 8bit\\n\\n\",\n+\t\t\t\t\topt->mime_boundary, opt->mime_boundary);\n+\t\t\tafter_subject = subject_buffer;\n+\n+\t\t\tsnprintf(buffer, sizeof(buffer) - 1,\n+\t\t\t\t\t\"--------------%s\\n\"\n+\t\t\t\t\t\"Content-Type: text/x-patch;\\n\"\n+\t\t\t\t\t\" name=\\\"%s.diff\\\"\\n\"\n+\t\t\t\t\t\"Content-Transfer-Encoding: 8bit\\n\"\n+\t\t\t\t\t\"Content-Disposition: inline;\\n\"\n+\t\t\t\t\t\" filename=\\\"%s.diff\\\"\\n\\n\",\n+\t\t\t\topt->mime_boundary, sha1, sha1);\n+\t\t\topt->diffopt.stat_sep = buffer;\n+\t\t}\n \t} else {\n \t\tprintf(\"%s%s\",\n \t\t       opt->commit_format == CMIT_FMT_ONELINE ? \"\" : \"commit \",\n@@ -81,7 +108,7 @@ void show_log(struct rev_info *opt, stru\n \t/*\n \t * And then the pretty-printed message itself\n \t */\n-\tlen = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject);\n+\tlen = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject);\n \tprintf(\"%s%s%s\", this_header, extra, sep);\n }\n \ndiff --git a/revision.h b/revision.h\nindex 62759f7..bdbdd23 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -59,6 +59,7 @@ struct rev_info {\n \tenum cmit_fmt\tcommit_format;\n \tstruct log_info *loginfo;\n \tint\t\tnr, total;\n+\tconst char\t*mime_boundary;\n \n \t/* special limits */\n \tint max_count;\ndiff --git a/show-branch.c b/show-branch.c\nindex bbe26c2..684ffd1 100644\n--- a/show-branch.c\n+++ b/show-branch.c\n@@ -259,7 +259,7 @@ static void show_one_commit(struct commi\n \tstruct commit_name *name = commit->object.util;\n \tif (commit->object.parsed)\n \t\tpretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,\n-\t\t\t\t    pretty, sizeof(pretty), 0, NULL);\n+\t\t\t\t    pretty, sizeof(pretty), 0, NULL, NULL);\n \telse\n \t\tstrcpy(pretty, \"(unavailable)\");\n \tif (!strncmp(pretty, \"[PATCH] \", 8))\n-- \n1.3.3.gea94-dirty\n"},{"id":"20323","messageId":"e4n8b3$ari$1@sea.gmane.org","threadId":"4218","inReplyTo":"Pine.LNX.4.63.0605201537290.17869@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fmt-patch: Support --attach","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-05-20T14:16:22Z","receivedAt":"2006-05-20T14:16:22Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Johannes Schindelin wrote:\n\n> -             printf(\"From %s  Thu Apr 7 15:13:13 2005\\n\",\n> -                    sha1_to_hex(commit->object.sha1));\n> +             printf(\"From %s Mon Sep 17 00:00:00 2001\\n\", sha1);\n\nWhat's with the date?\n\n-- \nJakub Narebski\nWarsaw, Poland\n"},{"id":"20328","messageId":"Pine.LNX.4.63.0605201904320.31887@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4218","inReplyTo":"e4n8b3$ari$1@sea.gmane.org","subject":"Re: [PATCH] fmt-patch: Support --attach","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-20T17:10:02Z","receivedAt":"2006-05-20T17:10:02Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 20 May 2006, Jakub Narebski wrote:\n\n> Johannes Schindelin wrote:\n> \n> > -             printf(\"From %s  Thu Apr 7 15:13:13 2005\\n\",\n> > -                    sha1_to_hex(commit->object.sha1));\n> > +             printf(\"From %s Mon Sep 17 00:00:00 2001\\n\", sha1);\n> \n> What's with the date?\n\nDoes not matter. This is not part of the mail header (the date is \ndisplayed as a \"Date:\" line).\n\nI only changed the \"From \" line (note the missing \":\") to match the output \nfrom git-format-patch.sh.\n\nCiao,\nDscho\n"},{"id":"20330","messageId":"7v4pzk3831.fsf@assigned-by-dhcp.cox.net","threadId":"4218","inReplyTo":"Pine.LNX.4.63.0605201904320.31887@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fmt-patch: Support --attach","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-20T17:43:46Z","receivedAt":"2006-05-20T17:43:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> I only changed the \"From \" line (note the missing \":\") to match the output \n> from git-format-patch.sh.\n\nNot a big deal, but I was hoping you would keep the inception\ndate of git (April one) in the final version ;-).  The September\ndate is totally a random date and does not have any\nsignificance.\n\nAnyway, with this change (and a lot of testing ;-) I think we\ncan replace the script with built-in.  Thanks.\n"},{"id":"20332","messageId":"Pine.LNX.4.63.0605201945110.32590@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4218","inReplyTo":"7v4pzk3831.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] fmt-patch: Support --attach","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-20T17:51:26Z","receivedAt":"2006-05-20T17:51:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 20 May 2006, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > I only changed the \"From \" line (note the missing \":\") to match the output \n> > from git-format-patch.sh.\n> \n> Not a big deal, but I was hoping you would keep the inception\n> date of git (April one) in the final version ;-).  The September\n> date is totally a random date and does not have any\n> significance.\n\nActually, I just tested something: pine seems to be confused when parsing \na \"From \" line where the day of month is only one digit without two \nleading digits. I don't care.\n\n> Anyway, with this change (and a lot of testing ;-) I think we\n> can replace the script with built-in.  Thanks.\n\nThere are two options missing: --signoff and --check.\n\n--signoff is my fault: it is probably a good thing to drop it from \nformat-patch, and only leave it in applymbox.\n\nAs for --check: how about having yet another diff \"format\": \nDIFF_FORMAT_CHECK? Instead of showing the diff, it only shows the line(s) \nwhich are offending.\n\nCiao,\nDscho\n"},{"id":"20333","messageId":"7vu07k1sr8.fsf@assigned-by-dhcp.cox.net","threadId":"4218","inReplyTo":"Pine.LNX.4.63.0605201945110.32590@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] fmt-patch: Support --attach","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-20T18:00:11Z","receivedAt":"2006-05-20T18:00:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Sat, 20 May 2006, Junio C Hamano wrote:\n>\n>> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> There are two options missing: --signoff and --check.\n>\n> --signoff is my fault: it is probably a good thing to drop it from \n> format-patch, and only leave it in applymbox.\n\nI think that is fine.  format-patch only formats existing\ncommits, and if you are signing off something you could already\nhave done that when you made the commits anyway, so that flag\nwas redundant.\n\n> As for --check: how about having yet another diff \"format\": \n> DIFF_FORMAT_CHECK? Instead of showing the diff, it only shows the line(s) \n> which are offending.\n\nNever thought of that but I think it makes sense.  \n\nI liked the way Sean did the --summary; I am wondering if we\ncould clean up the --with-* stuff in a similar way.  We\ncurrently do \"if DIFF_FORMAT_XYZ or with_xyz then do this\" which\nis quite honestly disgusting (my fault).\n"},{"id":"20336","messageId":"Pine.LNX.4.63.0605202214430.634@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4218","inReplyTo":"7vu07k1sr8.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] fmt-patch: Support --attach","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-05-20T20:23:04Z","receivedAt":"2006-05-20T20:23:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 20 May 2006, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > On Sat, 20 May 2006, Junio C Hamano wrote:\n> >\n> > As for --check: how about having yet another diff \"format\": \n> > DIFF_FORMAT_CHECK? Instead of showing the diff, it only shows the line(s) \n> > which are offending.\n> \n> Never thought of that but I think it makes sense.  \n> \n> I liked the way Sean did the --summary; I am wondering if we\n> could clean up the --with-* stuff in a similar way.  We\n> currently do \"if DIFF_FORMAT_XYZ or with_xyz then do this\" which\n> is quite honestly disgusting (my fault).\n\nI do not think the --with-* stuff can be done in a similar way. If I do \n\"git log --summary -p\", I do not get a summary. The only way to \"clean it \nup\" would be to add a linked list of diff_formats (to preserve the order). \n\nBut frankly, I think that is overkill. After all, how often have you \ndreamt about showing first the patch, then the summary, and maybe a \ndiffstat, and after that the patch again, for each commit?\n\nCiao,\nDscho\n"}]}