{"thread":{"id":"12786","subject":"[PATCH v2] pretty.c: add %z specifier.","startedAt":"2008-03-21T02:30:35Z","lastAt":"2008-03-21T02:30:35Z","messageCount":1,"participants":["Govind Salinas"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"72552","messageId":"5d46db230803201930r66d1331dw571aec7114f5fd51@mail.gmail.com","threadId":"12786","inReplyTo":null,"subject":"[PATCH v2] pretty.c: add %z specifier.","fromName":"Govind Salinas","fromEmail":"blix@sophiasuchtig.com","sentAt":"2008-03-21T02:30:35Z","receivedAt":"2008-03-21T02:30:35Z","isPatch":true,"sender":{"key":"blix@sophiasuchtig.com","avatar":null},"body":"This adds a %z format which prints out a null character.  This allows for\neasier machine parsing of multiline data.  It is also necessary to use fwrite\nto print out the data since printf will terminate at a null.\n\nSigned-off-by: Govind Salinas <blix@sophiasuchtig.com>\n---\n Documentation/pretty-formats.txt |    1 +\n log-tree.c                       |    6 ++++--\n pretty.c                         |    3 +++\n 3 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 0193c3c..f4b3134 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -123,3 +123,4 @@ The placeholders are:\n - '%Creset': reset color\n - '%m': left, right or boundary mark\n - '%n': newline\n+- '%z': null character\ndiff --git a/log-tree.c b/log-tree.c\nindex 608f697..3bb6e49 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -308,8 +308,10 @@ void show_log(struct rev_info *opt, const char *sep)\n \tif (opt->show_log_size)\n \t\tprintf(\"log size %i\\n\", (int)msgbuf.len);\n\n-\tif (msgbuf.len)\n-\t\tprintf(\"%s%s%s\", msgbuf.buf, extra, sep);\n+\tif (msgbuf.len) {\n+\t\tfwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);\n+\t\tprintf(\"%s%s\", extra, sep);\n+\t}\n \tstrbuf_release(&msgbuf);\n }\n\ndiff --git a/pretty.c b/pretty.c\nindex 703f521..fd155ec 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -478,6 +478,9 @@ static size_t format_commit_item(struct strbuf\n*sb, const char *placeholder,\n \tcase 'n':\t\t/* newline */\n \t\tstrbuf_addch(sb, '\\n');\n \t\treturn 1;\n+\tcase 'z':\t\t/* null */\n+\t\tstrbuf_addch(sb, '\\0');\n+\t\treturn 1;\n \t}\n\n \t/* these depend on the commit */\n-- \n1.5.4.4.552.g1d39e.dirty\n"}]}