{"thread":{"id":"27184","subject":"[PATCH/RFC 1/2] notes/pretty: allow callers to set the notes format from struct rev_info","startedAt":"2011-04-26T08:54:28Z","lastAt":"2011-04-27T06:37:51Z","messageCount":6,"participants":["Michael J Gruber","Johan Herland","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"166364","messageId":"cb2af8d1ef663a68ea96dbb916dcfa0aee71abcb.1303808057.git.git@drmicha.warpmail.net","threadId":"27184","inReplyTo":null,"subject":"[PATCH/RFC 1/2] notes/pretty: allow callers to set the notes format from struct rev_info","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-26T08:54:28Z","receivedAt":"2011-04-26T08:54:28Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"The notes display format is customisable, but this possibility is hidden\nfrom callers which go through struct rev_info's show_notes member and the\npretty-machinery.\n\nChange the show_notes member to an int which determines the format, and\nset it to NOTES_DEFAULT (which is NOTES_SHOW_HEADER | NOTES_INDENT)\nwhere we set it to 1 before. This allows callers to choose a different\nform.\n\nThe only form which cannot be chosen that way is \"bare\" (no indent, no\nheader) because \"0\" means \"do not show notes\" for this code path. But\ncurrent callers which need that (e.g. \"%N\" processing) call the notes\nformatters directly instead. And for future callers which need to\nrequest \"bare\" through rev_info's show_notes we can always introduce\nanother notes format flag NOTES_BARE when we need it.\n\nNo functional change with this commit.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n builtin/log.c |    2 +-\n notes.h       |    1 +\n pretty.c      |    2 +-\n revision.c    |    4 ++--\n revision.h    |    2 +-\n 5 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 9db43ed..5e71caa 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -81,7 +81,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,\n \tuserformat_find_requirements(NULL, &w);\n \n \tif (!rev->show_notes_given && (!rev->pretty_given || w.notes))\n-\t\trev->show_notes = 1;\n+\t\trev->show_notes = NOTES_DEFAULT;\n \tif (rev->show_notes)\n \t\tinit_display_notes(&rev->notes_opt);\n \ndiff --git a/notes.h b/notes.h\nindex 83bd6e0..81d16e3 100644\n--- a/notes.h\n+++ b/notes.h\n@@ -238,6 +238,7 @@ void free_notes(struct notes_tree *t);\n /* Flags controlling how notes are formatted */\n #define NOTES_SHOW_HEADER 1\n #define NOTES_INDENT 2\n+#define NOTES_DEFAULT (NOTES_SHOW_HEADER | NOTES_INDENT)\n \n /*\n  * Fill the given strbuf with the notes associated with the given object.\ndiff --git a/pretty.c b/pretty.c\nindex e1d8a8f..dc371a4 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1271,7 +1271,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \n \tif (context->show_notes)\n \t\tformat_display_notes(commit->object.sha1, sb, encoding,\n-\t\t\t\t     NOTES_SHOW_HEADER | NOTES_INDENT);\n+\t\t\t\t     context->show_notes);\n \n \tfree(reencoded);\n }\ndiff --git a/revision.c b/revision.c\nindex 0f38364..f24ffb8 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1366,11 +1366,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\trevs->pretty_given = 1;\n \t\tget_commit_format(arg+9, revs);\n \t} else if (!strcmp(arg, \"--show-notes\")) {\n-\t\trevs->show_notes = 1;\n+\t\trevs->show_notes = NOTES_DEFAULT;\n \t\trevs->show_notes_given = 1;\n \t} else if (!prefixcmp(arg, \"--show-notes=\")) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n-\t\trevs->show_notes = 1;\n+\t\trevs->show_notes = NOTES_DEFAULT;\n \t\trevs->show_notes_given = 1;\n \t\tif (!revs->notes_opt.extra_notes_refs)\n \t\t\trevs->notes_opt.extra_notes_refs = xcalloc(1, sizeof(struct string_list));\ndiff --git a/revision.h b/revision.h\nindex 9fd8f30..e50eb49 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -84,9 +84,9 @@ struct rev_info {\n \t\t\talways_show_header:1;\n \n \t/* Format info */\n+\tunsigned int\tshow_notes;\n \tunsigned int\tshown_one:1,\n \t\t\tshow_merge:1,\n-\t\t\tshow_notes:1,\n \t\t\tshow_notes_given:1,\n \t\t\tpretty_given:1,\n \t\t\tabbrev_commit:1,\n-- \n1.7.5.270.gafca7\n"},{"id":"166365","messageId":"826def15eb7204ee30fc4c358f72103ec75b4e42.1303808057.git.git@drmicha.warpmail.net","threadId":"27184","inReplyTo":"cb2af8d1ef663a68ea96dbb916dcfa0aee71abcb.1303808057.git.git@drmicha.warpmail.net","subject":"[PATCH/RFC 2/2] format-patch: show notes as message after the ---","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-26T08:54:29Z","receivedAt":"2011-04-26T08:54:29Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"When requesting notes with \"--notes\", \"format-patch\" produces notes\nwithin the commit message which \"am\" misunderstands as being part of the\nmessage.\n\nChange this so that notes are displayed after an additional \"---\". Any\n\"am\" (old or new) will ignore that, so that it is a safe place for\nadditional comments:\n\nLog message\n\"---\"\nnotes\n\"---\"\ndiffstat\npatch\n\n(The first \"---\" appears only when there is a note, of course.)\n\nLater on (say with \"--format-notes\") the output format can be changed\neasily to accomodate a future \"am\" which knows how to create notes from\nsuch patches.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\nReducing the output format to one \"---\" only is not only complicated (the notes\nseparator is generated in a quite different place from the patch separator)\nbut also unnecessary (am reads the patch anyways) and not even preferable (to\ngive a clear separation of the parts).\n---\n builtin/log.c |    4 +++-\n notes.c       |    2 ++\n notes.h       |    3 +++\n 3 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 5e71caa..67aed94 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1159,8 +1159,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tif (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)\n \t\tDIFF_OPT_SET(&rev.diffopt, BINARY);\n \n-\tif (rev.show_notes)\n+\tif (rev.show_notes) {\n \t\tinit_display_notes(&rev.notes_opt);\n+\t\trev.show_notes = NOTES_DASH;\n+\t}\n \n \tif (!use_stdout)\n \t\toutput_directory = set_outdir(prefix, output_directory);\ndiff --git a/notes.c b/notes.c\nindex a013c1b..b8b737e 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -1233,6 +1233,8 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,\n \tif (msglen && msg[msglen - 1] == '\\n')\n \t\tmsglen--;\n \n+\tif (flags & NOTES_DASH)\n+\t\tstrbuf_addstr(sb, \"---\\n\");\n \tif (flags & NOTES_SHOW_HEADER) {\n \t\tconst char *ref = t->ref;\n \t\tif (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {\ndiff --git a/notes.h b/notes.h\nindex 81d16e3..17150d5 100644\n--- a/notes.h\n+++ b/notes.h\n@@ -238,6 +238,7 @@ void free_notes(struct notes_tree *t);\n /* Flags controlling how notes are formatted */\n #define NOTES_SHOW_HEADER 1\n #define NOTES_INDENT 2\n+#define NOTES_DASH 4\n #define NOTES_DEFAULT (NOTES_SHOW_HEADER | NOTES_INDENT)\n \n /*\n@@ -284,6 +285,8 @@ void init_display_notes(struct display_notes_opt *opt);\n  *\n  * - NOTES_INDENT: indent the notes by 4 places\n  *\n+ * - NOTES_DASH: prepend a \"---\" line\n+ *\n  * You *must* call init_display_notes() before using this function.\n  */\n void format_display_notes(const unsigned char *object_sha1,\n-- \n1.7.5.270.gafca7\n"},{"id":"166367","messageId":"201104261128.58527.johan@herland.net","threadId":"27184","inReplyTo":"826def15eb7204ee30fc4c358f72103ec75b4e42.1303808057.git.git@drmicha.warpmail.net","subject":"Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2011-04-26T09:28:58Z","receivedAt":"2011-04-26T09:28:58Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Tuesday 26 April 2011, Michael J Gruber wrote:\n> When requesting notes with \"--notes\", \"format-patch\" produces notes\n> within the commit message which \"am\" misunderstands as being part of\n> the message.\n>\n> Change this so that notes are displayed after an additional \"---\".\n> Any \"am\" (old or new) will ignore that, so that it is a safe place\n> for additional comments:\n>\n> Log message\n> \"---\"\n> notes\n> \"---\"\n> diffstat\n> patch\n>\n> (The first \"---\" appears only when there is a note, of course.)\n>\n> Later on (say with \"--format-notes\") the output format can be changed\n> easily to accomodate a future \"am\" which knows how to create notes\n> from such patches.\n>\n> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n\nAcked-by: Johan Herland <johan@herland.net>\n\n(goes for 1/2 as well)\n\n\n/me likes :)\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"166368","messageId":"4DB693F5.4090803@drmicha.warpmail.net","threadId":"27184","inReplyTo":"201104261128.58527.johan@herland.net","subject":"Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-26T09:44:21Z","receivedAt":"2011-04-26T09:44:21Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Johan Herland venit, vidit, dixit 26.04.2011 11:28:\n> On Tuesday 26 April 2011, Michael J Gruber wrote:\n>> When requesting notes with \"--notes\", \"format-patch\" produces notes\n>> within the commit message which \"am\" misunderstands as being part of\n>> the message.\n>>\n>> Change this so that notes are displayed after an additional \"---\".\n>> Any \"am\" (old or new) will ignore that, so that it is a safe place\n>> for additional comments:\n>>\n>> Log message\n>> \"---\"\n>> notes\n>> \"---\"\n>> diffstat\n>> patch\n>>\n>> (The first \"---\" appears only when there is a note, of course.)\n>>\n>> Later on (say with \"--format-notes\") the output format can be changed\n>> easily to accomodate a future \"am\" which knows how to create notes\n>> from such patches.\n>>\n>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n> \n> Acked-by: Johan Herland <johan@herland.net>\n> \n> (goes for 1/2 as well)\n> \n> \n> /me likes :)\n\nThanks :)\n\nBTW: Just before hitting \"send-mail\", I thought of quoting the \"---\" in\nmy commit message where I describe the format. I wonder what would have\nhappened else when am-ing that message...\n\nMichael\n"},{"id":"166402","messageId":"7vsjt4ewsy.fsf@alter.siamese.dyndns.org","threadId":"27184","inReplyTo":"826def15eb7204ee30fc4c358f72103ec75b4e42.1303808057.git.git@drmicha.warpmail.net","subject":"Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-26T17:39:57Z","receivedAt":"2011-04-26T17:39:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> When requesting notes with \"--notes\", \"format-patch\" produces notes\n> within the commit message which \"am\" misunderstands as being part of the\n> message.\n>\n> Change this so that notes are displayed after an additional \"---\". Any\n> \"am\" (old or new) will ignore that, so that it is a safe place for\n> additional comments:\n>\n> Log message\n> \"---\"\n> notes\n> \"---\"\n> diffstat\n> patch\n>\n> (The first \"---\" appears only when there is a note, of course.)\n>\n> Later on (say with \"--format-notes\") the output format can be changed\n> easily to accomodate a future \"am\" which knows how to create notes from\n> such patches.\n>\n> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n> ---\n> Reducing the output format to one \"---\" only is not only complicated (the notes\n> separator is generated in a quite different place from the patch separator)\n> but also unnecessary (am reads the patch anyways) and not even preferable (to\n> give a clear separation of the parts).\n> ---\n\nIf you show more than one note, separating them with \"---\" in between\nwould be a good idea so that reader can tell where each note ends, but I'd\nrather not to see the \"---\" after the last note.  Put just a blank line\nhere instead.\n"},{"id":"166461","messageId":"4DB7B9BF.6000009@drmicha.warpmail.net","threadId":"27184","inReplyTo":"7vsjt4ewsy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-04-27T06:37:51Z","receivedAt":"2011-04-27T06:37:51Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 26.04.2011 19:39:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> When requesting notes with \"--notes\", \"format-patch\" produces notes\n>> within the commit message which \"am\" misunderstands as being part of the\n>> message.\n>>\n>> Change this so that notes are displayed after an additional \"---\". Any\n>> \"am\" (old or new) will ignore that, so that it is a safe place for\n>> additional comments:\n>>\n>> Log message\n>> \"---\"\n>> notes\n>> \"---\"\n>> diffstat\n>> patch\n>>\n>> (The first \"---\" appears only when there is a note, of course.)\n>>\n>> Later on (say with \"--format-notes\") the output format can be changed\n>> easily to accomodate a future \"am\" which knows how to create notes from\n>> such patches.\n>>\n>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n>> ---\n>> Reducing the output format to one \"---\" only is not only complicated (the notes\n>> separator is generated in a quite different place from the patch separator)\n>> but also unnecessary (am reads the patch anyways) and not even preferable (to\n>> give a clear separation of the parts).\n>> ---\n> \n> If you show more than one note, separating them with \"---\" in between\n> would be a good idea so that reader can tell where each note ends, but I'd\n\nIt does that already. More precisely, each note is preceded by a \"---\\n\".\n\n> rather not to see the \"---\" after the last note.  Put just a blank line\n> here instead.\n\nWell, in the note which you snipped, I tried to explain that that is\ncomplicated (the note code would need to set a flag \"dash_output\" which\nthe log-tree code would need to look at) and may not even be preferable,\nbecause the \"---\" gives a clear separation between the note and the\ndiffstat. I'll check whether there's an easy way (and provide a test).\n\nMichael\n"}]}