{"thread":{"id":"26607","subject":"[PATCH/RFC 0/5] status, commit: separate \"# \" from the translatable part of output","startedAt":"2011-02-26T05:07:23Z","lastAt":"2011-02-27T09:50:37Z","messageCount":8,"participants":["Jonathan Nieder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"162284","messageId":"20110226050723.GA27864@elie","threadId":"26607","inReplyTo":null,"subject":"[PATCH/RFC 0/5] status, commit: separate \"# \" from the translatable part of output","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-26T05:07:23Z","receivedAt":"2011-02-26T05:07:23Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nThis series makes wt-status and builtin-commit code a little\nless explicit about the '#' signs they produce in their output.\nThe main goal is to make messages like\n\n\t\t\"\\n\"\n\t\t\"It looks like you may be committing a MERGE.\\n\"\n\t\t\"If this is not correct, please remove the file\\n\"\n\t\t\"\t%s\\n\"\n\t\t\"and try again.\\n\"\n\t\t\"\"\n\nsafe to translate by getting rid of the functionally important initial\n# signs; a nice side effect is to make the source code a little easier\n# to read and change (for example if we want to use some other kind\nof formatting some day for \"git status\" output).\n\nThe first two patches (va_copy, strbuf_vaddf) are stolen from Jeff's\nGIT_TRACE_FACET series.\n\nThanks for your help and patience so far.  I hope the series can be\nuseful.\n\nJeff King (2):\n  compat: provide a fallback va_copy definition\n  strbuf: add strbuf_vaddf\n\nJonathan Nieder (3):\n  wt-status: add helpers for printing wt-status lines\n  commit: refer to commit template as s->fp\n  commit, status: use status_printf{,_ln,_more} helpers\n\n builtin/commit.c  |   58 ++++++++++----------\n color.c           |    9 +++\n color.h           |    3 +\n compat/msvc.h     |    1 -\n fsck.c            |   14 +----\n git-compat-util.h |    4 +\n merge-recursive.c |   15 +-----\n strbuf.c          |   27 +++++----\n strbuf.h          |    2 +\n trace.c           |   32 ++---------\n wt-status.c       |  160 ++++++++++++++++++++++++++++++++++++++--------------\n wt-status.h       |    7 ++\n 12 files changed, 195 insertions(+), 137 deletions(-)\n"},{"id":"162285","messageId":"20110226050825.GA27887@elie","threadId":"26607","inReplyTo":"20110226050723.GA27864@elie","subject":"[PATCH 1/5] compat: provide a fallback va_copy definition","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-26T05:08:25Z","receivedAt":"2011-02-26T05:08:25Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nva_copy is C99.  We have avoided using va_copy many times in the past,\nwhich has led to a bunch of cut-and-paste.  From everything I found\nsearching the web, implementations have historically either provided\nva_copy or just let your code assume that simple assignment of worked.\n\nSo my guess is that this will be sufficient, though we won't really\nknow for sure until somebody reports a problem.\n\nSigned-off-by: Jeff King <peff@peff.net>\nImproved-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n compat/msvc.h     |    1 -\n git-compat-util.h |    4 ++++\n 2 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/compat/msvc.h b/compat/msvc.h\nindex 023aba0..a33b01c 100644\n--- a/compat/msvc.h\n+++ b/compat/msvc.h\n@@ -9,7 +9,6 @@\n #define inline __inline\n #define __inline__ __inline\n #define __attribute__(x)\n-#define va_copy(dst, src)     ((dst) = (src))\n #define strncasecmp  _strnicmp\n #define ftruncate    _chsize\n \ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9c23622..00d41e4 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -535,6 +535,10 @@ void git_qsort(void *base, size_t nmemb, size_t size,\n #define fstat_is_reliable() 1\n #endif\n \n+#ifndef va_copy\n+#define va_copy(dst,src) (dst) = (src)\n+#endif\n+\n /*\n  * Preserves errno, prints a message, but gives no warning for ENOENT.\n  * Always returns the return value of unlink(2).\n-- \n1.7.4.1\n"},{"id":"162286","messageId":"20110226050853.GB27887@elie","threadId":"26607","inReplyTo":"20110226050723.GA27864@elie","subject":"[PATCH 2/5] strbuf: add strbuf_vaddf","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-26T05:08:53Z","receivedAt":"2011-02-26T05:08:53Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nIn a variable-args function, the code for writing into a strbuf is\nnon-trivial. We ended up cutting and pasting it in several places\nbecause there was no vprintf-style function for strbufs (which in turn\nwas held up by a lack of va_copy).\n\nNow that we have a fallback va_copy, we can add strbuf_vaddf, the\nstrbuf equivalent of vsprintf. And we can clean up the cut and paste\nmess.\n\nSigned-off-by: Jeff King <peff@peff.net>\nImproved-by: Christian Couder <christian.couder@gmail.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n fsck.c            |   14 +-------------\n merge-recursive.c |   15 +--------------\n strbuf.c          |   27 ++++++++++++++++-----------\n strbuf.h          |    2 ++\n trace.c           |   32 ++++++--------------------------\n 5 files changed, 26 insertions(+), 64 deletions(-)\n\ndiff --git a/fsck.c b/fsck.c\nindex 3d05d4a..6f266c1 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -347,26 +347,14 @@ int fsck_object(struct object *obj, int strict, fsck_error error_func)\n int fsck_error_function(struct object *obj, int type, const char *fmt, ...)\n {\n \tva_list ap;\n-\tint len;\n \tstruct strbuf sb = STRBUF_INIT;\n \n \tstrbuf_addf(&sb, \"object %s:\", obj->sha1?sha1_to_hex(obj->sha1):\"(null)\");\n \n \tva_start(ap, fmt);\n-\tlen = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap);\n+\tstrbuf_vaddf(&sb, fmt, ap);\n \tva_end(ap);\n \n-\tif (len < 0)\n-\t\tlen = 0;\n-\tif (len >= strbuf_avail(&sb)) {\n-\t\tstrbuf_grow(&sb, len + 2);\n-\t\tva_start(ap, fmt);\n-\t\tlen = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap);\n-\t\tva_end(ap);\n-\t\tif (len >= strbuf_avail(&sb))\n-\t\t\tdie(\"this should not happen, your snprintf is broken\");\n-\t}\n-\n \terror(\"%s\", sb.buf);\n \tstrbuf_release(&sb);\n \treturn 1;\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 16c2dbe..2a4f739 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -137,7 +137,6 @@ static void flush_output(struct merge_options *o)\n __attribute__((format (printf, 3, 4)))\n static void output(struct merge_options *o, int v, const char *fmt, ...)\n {\n-\tint len;\n \tva_list ap;\n \n \tif (!show(o, v))\n@@ -148,21 +147,9 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)\n \tstrbuf_setlen(&o->obuf, o->obuf.len + o->call_depth * 2);\n \n \tva_start(ap, fmt);\n-\tlen = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);\n+\tstrbuf_vaddf(&o->obuf, fmt, ap);\n \tva_end(ap);\n \n-\tif (len < 0)\n-\t\tlen = 0;\n-\tif (len >= strbuf_avail(&o->obuf)) {\n-\t\tstrbuf_grow(&o->obuf, len + 2);\n-\t\tva_start(ap, fmt);\n-\t\tlen = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);\n-\t\tva_end(ap);\n-\t\tif (len >= strbuf_avail(&o->obuf)) {\n-\t\t\tdie(\"this should not happen, your snprintf is broken\");\n-\t\t}\n-\t}\n-\tstrbuf_setlen(&o->obuf, o->obuf.len + len);\n \tstrbuf_add(&o->obuf, \"\\n\", 1);\n \tif (!o->buffer_output)\n \t\tflush_output(o);\ndiff --git a/strbuf.c b/strbuf.c\nindex 07e8883..77444a9 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -195,24 +195,29 @@ void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)\n \n void strbuf_addf(struct strbuf *sb, const char *fmt, ...)\n {\n-\tint len;\n \tva_list ap;\n-\n-\tif (!strbuf_avail(sb))\n-\t\tstrbuf_grow(sb, 64);\n \tva_start(ap, fmt);\n-\tlen = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);\n+\tstrbuf_vaddf(sb, fmt, ap);\n \tva_end(ap);\n+}\n+\n+void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)\n+{\n+\tint len;\n+\tva_list cp;\n+\n+\tif (!strbuf_avail(sb))\n+\t\tstrbuf_grow(sb, 64);\n+\tva_copy(cp, ap);\n+\tlen = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, cp);\n+\tva_end(cp);\n \tif (len < 0)\n-\t\tdie(\"your vsnprintf is broken\");\n+\t\tdie(\"BUG: your vsnprintf is broken (returned %d)\", len);\n \tif (len > strbuf_avail(sb)) {\n \t\tstrbuf_grow(sb, len);\n-\t\tva_start(ap, fmt);\n \t\tlen = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);\n-\t\tva_end(ap);\n-\t\tif (len > strbuf_avail(sb)) {\n-\t\t\tdie(\"this should not happen, your snprintf is broken\");\n-\t\t}\n+\t\tif (len > strbuf_avail(sb))\n+\t\t\tdie(\"BUG: your vsnprintf is broken (insatiable)\");\n \t}\n \tstrbuf_setlen(sb, sb->len + len);\n }\ndiff --git a/strbuf.h b/strbuf.h\nindex 675a91f..f722331 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -120,6 +120,8 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *\n \n __attribute__((format (printf,2,3)))\n extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);\n+__attribute__((format (printf,2,0)))\n+extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);\n \n extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);\n /* XXX: if read fails, any partial read is undone */\ndiff --git a/trace.c b/trace.c\nindex 35d388d..eda3f6d 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -64,28 +64,18 @@ static const char err_msg[] = \"Could not trace into fd given by \"\n \n void trace_printf(const char *fmt, ...)\n {\n-\tstruct strbuf buf;\n+\tstruct strbuf buf = STRBUF_INIT;\n \tva_list ap;\n-\tint fd, len, need_close = 0;\n+\tint fd, need_close = 0;\n \n \tfd = get_trace_fd(&need_close);\n \tif (!fd)\n \t\treturn;\n \n \tset_try_to_free_routine(NULL);\t/* is never reset */\n-\tstrbuf_init(&buf, 64);\n \tva_start(ap, fmt);\n-\tlen = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);\n+\tstrbuf_vaddf(&buf, fmt, ap);\n \tva_end(ap);\n-\tif (len >= strbuf_avail(&buf)) {\n-\t\tstrbuf_grow(&buf, len - strbuf_avail(&buf) + 128);\n-\t\tva_start(ap, fmt);\n-\t\tlen = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);\n-\t\tva_end(ap);\n-\t\tif (len >= strbuf_avail(&buf))\n-\t\t\tdie(\"broken vsnprintf\");\n-\t}\n-\tstrbuf_setlen(&buf, len);\n \n \twrite_or_whine_pipe(fd, buf.buf, buf.len, err_msg);\n \tstrbuf_release(&buf);\n@@ -96,28 +86,18 @@ void trace_printf(const char *fmt, ...)\n \n void trace_argv_printf(const char **argv, const char *fmt, ...)\n {\n-\tstruct strbuf buf;\n+\tstruct strbuf buf = STRBUF_INIT;\n \tva_list ap;\n-\tint fd, len, need_close = 0;\n+\tint fd, need_close = 0;\n \n \tfd = get_trace_fd(&need_close);\n \tif (!fd)\n \t\treturn;\n \n \tset_try_to_free_routine(NULL);\t/* is never reset */\n-\tstrbuf_init(&buf, 64);\n \tva_start(ap, fmt);\n-\tlen = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);\n+\tstrbuf_vaddf(&buf, fmt, ap);\n \tva_end(ap);\n-\tif (len >= strbuf_avail(&buf)) {\n-\t\tstrbuf_grow(&buf, len - strbuf_avail(&buf) + 128);\n-\t\tva_start(ap, fmt);\n-\t\tlen = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);\n-\t\tva_end(ap);\n-\t\tif (len >= strbuf_avail(&buf))\n-\t\t\tdie(\"broken vsnprintf\");\n-\t}\n-\tstrbuf_setlen(&buf, len);\n \n \tsq_quote_argv(&buf, argv, 0);\n \tstrbuf_addch(&buf, '\\n');\n-- \n1.7.4.1\n"},{"id":"162287","messageId":"20110226050941.GC27887@elie","threadId":"26607","inReplyTo":"20110226050723.GA27864@elie","subject":"[PATCH 3/5] wt-status: add helpers for printing wt-status lines","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-26T05:09:41Z","receivedAt":"2011-02-26T05:09:41Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Introduce status_printf{,_ln,_more} wrapper functions around\ncolor_vfprintf() which take care of adding \"#\" to the beginning of\nstatus lines automatically.  The semantics:\n\n - status_printf() is just like color_fprintf() but it adds a \"# \"\n   at the beginning of each line of output;\n\n - status_printf_ln() is a convenience function that additionally\n   adds \"\\n\" at the end;\n\n - status_printf_more() is a variant of status_printf() used to\n   continue lines that have already started.  It suppresses the \"#\" at\n   the beginning of the first line.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n color.c     |    9 +++++++\n color.h     |    3 ++\n wt-status.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n wt-status.h |    7 +++++\n 4 files changed, 93 insertions(+), 0 deletions(-)\n\ndiff --git a/color.c b/color.c\nindex 6a5a54e..417cf8f 100644\n--- a/color.c\n+++ b/color.c\n@@ -175,6 +175,15 @@ int git_color_default_config(const char *var, const char *value, void *cb)\n \treturn git_default_config(var, value, cb);\n }\n \n+void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)\n+{\n+\tif (*color)\n+\t\tfprintf(fp, \"%s\", color);\n+\tfprintf(fp, \"%s\", sb->buf);\n+\tif (*color)\n+\t\tfprintf(fp, \"%s\", GIT_COLOR_RESET);\n+}\n+\n static int color_vfprintf(FILE *fp, const char *color, const char *fmt,\n \t\tva_list args, const char *trail)\n {\ndiff --git a/color.h b/color.h\nindex 170ff40..c0528cf 100644\n--- a/color.h\n+++ b/color.h\n@@ -1,6 +1,8 @@\n #ifndef COLOR_H\n #define COLOR_H\n \n+struct strbuf;\n+\n /*  2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */\n /* \"\\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\\0\" */\n /*\n@@ -64,6 +66,7 @@ __attribute__((format (printf, 3, 4)))\n int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);\n __attribute__((format (printf, 3, 4)))\n int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);\n+void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);\n \n int color_is_nil(const char *color);\n \ndiff --git a/wt-status.c b/wt-status.c\nindex 123582b..1abd7c3 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -32,6 +32,80 @@ static const char *color(int slot, struct wt_status *s)\n \treturn c;\n }\n \n+static void status_vprintf(struct wt_status *s, int at_bol, const char *color,\n+\t\tconst char *fmt, va_list ap, const char *trail)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tstruct strbuf linebuf = STRBUF_INIT;\n+\tconst char *line, *eol;\n+\n+\tstrbuf_vaddf(&sb, fmt, ap);\n+\tif (!sb.len) {\n+\t\tstrbuf_addch(&sb, '#');\n+\t\tif (!trail)\n+\t\t\tstrbuf_addch(&sb, ' ');\n+\t\tcolor_print_strbuf(s->fp, color, &sb);\n+\t\tif (trail)\n+\t\t\tfprintf(s->fp, \"%s\", trail);\n+\t\tstrbuf_release(&sb);\n+\t\treturn;\n+\t}\n+\tfor (line = sb.buf; *line; line = eol + 1) {\n+\t\teol = strchr(line, '\\n');\n+\n+\t\tstrbuf_reset(&linebuf);\n+\t\tif (at_bol) {\n+\t\t\tstrbuf_addch(&linebuf, '#');\n+\t\t\tif (*line != '\\n' && *line != '\\t')\n+\t\t\t\tstrbuf_addch(&linebuf, ' ');\n+\t\t}\n+\t\tif (eol)\n+\t\t\tstrbuf_add(&linebuf, line, eol - line);\n+\t\telse\n+\t\t\tstrbuf_addstr(&linebuf, line);\n+\t\tcolor_print_strbuf(s->fp, color, &linebuf);\n+\t\tif (eol)\n+\t\t\tfprintf(s->fp, \"\\n\");\n+\t\telse\n+\t\t\tbreak;\n+\t\tat_bol = 1;\n+\t}\n+\tif (trail)\n+\t\tfprintf(s->fp, \"%s\", trail);\n+\tstrbuf_release(&linebuf);\n+\tstrbuf_release(&sb);\n+}\n+\n+void status_printf_ln(struct wt_status *s, const char *color,\n+\t\t\tconst char *fmt, ...)\n+{\n+\tva_list ap;\n+\n+\tva_start(ap, fmt);\n+\tstatus_vprintf(s, 1, color, fmt, ap, \"\\n\");\n+\tva_end(ap);\n+}\n+\n+void status_printf(struct wt_status *s, const char *color,\n+\t\t\tconst char *fmt, ...)\n+{\n+\tva_list ap;\n+\n+\tva_start(ap, fmt);\n+\tstatus_vprintf(s, 1, color, fmt, ap, NULL);\n+\tva_end(ap);\n+}\n+\n+void status_printf_more(struct wt_status *s, const char *color,\n+\t\t\tconst char *fmt, ...)\n+{\n+\tva_list ap;\n+\n+\tva_start(ap, fmt);\n+\tstatus_vprintf(s, 0, color, fmt, ap, NULL);\n+\tva_end(ap);\n+}\n+\n void wt_status_prepare(struct wt_status *s)\n {\n \tunsigned char sha1[20];\ndiff --git a/wt-status.h b/wt-status.h\nindex 20b17cf..204a519 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -68,4 +68,11 @@ void wt_status_collect(struct wt_status *s);\n void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch);\n void wt_porcelain_print(struct wt_status *s, int null_termination);\n \n+void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)\n+\t__attribute__((format(printf, 3, 4)));\n+void status_printf(struct wt_status *s, const char *color, const char *fmt, ...)\n+\t__attribute__((format(printf, 3, 4)));\n+void status_printf_more(struct wt_status *s, const char *color, const char *fmt, ...)\n+\t__attribute__((format(printf, 3, 4)));\n+\n #endif /* STATUS_H */\n-- \n1.7.4.1\n"},{"id":"162288","messageId":"20110226051049.GD27887@elie","threadId":"26607","inReplyTo":"20110226050723.GA27864@elie","subject":"[PATCH 4/5] commit: refer to commit template as s->fp","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-26T05:10:49Z","receivedAt":"2011-02-26T05:10:49Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Instead of maintaining a local variable for it, use s->fp to keep\ntrack of where the commit message template should be written.\n\nThis prepares us to take advantage of the status_printf functions,\nwhich use a struct wt_status instead of a FILE pointer to determine\nwhere to send their output.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/commit.c |   27 +++++++++++++--------------\n 1 files changed, 13 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex d7f55e3..ef5f0b2 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -568,7 +568,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tint commitable, saved_color_setting;\n \tstruct strbuf sb = STRBUF_INIT;\n \tchar *buffer;\n-\tFILE *fp;\n \tconst char *hook_arg1 = NULL;\n \tconst char *hook_arg2 = NULL;\n \tint ident_shown = 0;\n@@ -657,8 +656,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\thook_arg2 = \"\";\n \t}\n \n-\tfp = fopen(git_path(commit_editmsg), \"w\");\n-\tif (fp == NULL)\n+\ts->fp = fopen(git_path(commit_editmsg), \"w\");\n+\tif (s->fp == NULL)\n \t\tdie_errno(\"could not open '%s'\", git_path(commit_editmsg));\n \n \tif (cleanup_mode != CLEANUP_NONE)\n@@ -682,7 +681,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tstrbuf_release(&sob);\n \t}\n \n-\tif (fwrite(sb.buf, 1, sb.len, fp) < sb.len)\n+\tif (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)\n \t\tdie_errno(\"could not write commit template\");\n \n \tstrbuf_release(&sb);\n@@ -695,7 +694,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tif (use_editor && include_status) {\n \t\tchar *ai_tmp, *ci_tmp;\n \t\tif (in_merge)\n-\t\t\tfprintf(fp,\n+\t\t\tfprintf(s->fp,\n \t\t\t\t\"#\\n\"\n \t\t\t\t\"# It looks like you may be committing a MERGE.\\n\"\n \t\t\t\t\"# If this is not correct, please remove the file\\n\"\n@@ -704,45 +703,45 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\t\t\t\"#\\n\",\n \t\t\t\tgit_path(\"MERGE_HEAD\"));\n \n-\t\tfprintf(fp,\n+\t\tfprintf(s->fp,\n \t\t\t\"\\n\"\n \t\t\t\"# Please enter the commit message for your changes.\");\n \t\tif (cleanup_mode == CLEANUP_ALL)\n-\t\t\tfprintf(fp,\n+\t\t\tfprintf(s->fp,\n \t\t\t\t\" Lines starting\\n\"\n \t\t\t\t\"# with '#' will be ignored, and an empty\"\n \t\t\t\t\" message aborts the commit.\\n\");\n \t\telse /* CLEANUP_SPACE, that is. */\n-\t\t\tfprintf(fp,\n+\t\t\tfprintf(s->fp,\n \t\t\t\t\" Lines starting\\n\"\n \t\t\t\t\"# with '#' will be kept; you may remove them\"\n \t\t\t\t\" yourself if you want to.\\n\"\n \t\t\t\t\"# An empty message aborts the commit.\\n\");\n \t\tif (only_include_assumed)\n-\t\t\tfprintf(fp, \"# %s\\n\", only_include_assumed);\n+\t\t\tfprintf(s->fp, \"# %s\\n\", only_include_assumed);\n \n \t\tai_tmp = cut_ident_timestamp_part(author_ident->buf);\n \t\tci_tmp = cut_ident_timestamp_part(committer_ident.buf);\n \t\tif (strcmp(author_ident->buf, committer_ident.buf))\n-\t\t\tfprintf(fp,\n+\t\t\tfprintf(s->fp,\n \t\t\t\t\"%s\"\n \t\t\t\t\"# Author:    %s\\n\",\n \t\t\t\tident_shown++ ? \"\" : \"#\\n\",\n \t\t\t\tauthor_ident->buf);\n \n \t\tif (!user_ident_sufficiently_given())\n-\t\t\tfprintf(fp,\n+\t\t\tfprintf(s->fp,\n \t\t\t\t\"%s\"\n \t\t\t\t\"# Committer: %s\\n\",\n \t\t\t\tident_shown++ ? \"\" : \"#\\n\",\n \t\t\t\tcommitter_ident.buf);\n \n \t\tif (ident_shown)\n-\t\t\tfprintf(fp, \"#\\n\");\n+\t\t\tfprintf(s->fp, \"#\\n\");\n \n \t\tsaved_color_setting = s->use_color;\n \t\ts->use_color = 0;\n-\t\tcommitable = run_status(fp, index_file, prefix, 1, s);\n+\t\tcommitable = run_status(s->fp, index_file, prefix, 1, s);\n \t\ts->use_color = saved_color_setting;\n \n \t\t*ai_tmp = ' ';\n@@ -764,7 +763,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t}\n \tstrbuf_release(&committer_ident);\n \n-\tfclose(fp);\n+\tfclose(s->fp);\n \n \tif (!commitable && !in_merge && !allow_empty &&\n \t    !(amend && is_a_merge(head_sha1))) {\n-- \n1.7.4.1\n"},{"id":"162289","messageId":"20110226051137.GE27887@elie","threadId":"26607","inReplyTo":"20110226050723.GA27864@elie","subject":"[PATCH 5/5] commit, status: use status_printf{,_ln,_more} helpers","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-26T05:11:37Z","receivedAt":"2011-02-26T05:11:37Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"wt-status code is used to provide a reminder of changes included and\nnot included for the commit message template opened in the operator's\ntext editor by \"git commit\".  Therefore each line of its output begins\nwith the comment character \"#\":\n\n\t# Please enter the commit message for your changes. Lines starting\n\nUse the new status_printf{,_ln,_more} functions to take care of adding\n\"#\" to the beginning of such status lines automatically.  Using these\nwill have two advantages over the current code:\n\n - The obvious one is to force separation of the \"#\" from the\n   translatable part of the message when git learns to translate its\n   output.\n\n - Another advantage is that this makes it easier for us to drop \"#\"\n   prefix in \"git status\" output in later versions of git if we want\n   to.\n\nExplained-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nThanks for reading.\n\n builtin/commit.c |   47 +++++++++++++++--------------\n wt-status.c      |   86 +++++++++++++++++++++++++++---------------------------\n 2 files changed, 67 insertions(+), 66 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex ef5f0b2..ae62a25 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -694,50 +694,51 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tif (use_editor && include_status) {\n \t\tchar *ai_tmp, *ci_tmp;\n \t\tif (in_merge)\n-\t\t\tfprintf(s->fp,\n-\t\t\t\t\"#\\n\"\n-\t\t\t\t\"# It looks like you may be committing a MERGE.\\n\"\n-\t\t\t\t\"# If this is not correct, please remove the file\\n\"\n-\t\t\t\t\"#\t%s\\n\"\n-\t\t\t\t\"# and try again.\\n\"\n-\t\t\t\t\"#\\n\",\n+\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n+\t\t\t\t\"\\n\"\n+\t\t\t\t\"It looks like you may be committing a MERGE.\\n\"\n+\t\t\t\t\"If this is not correct, please remove the file\\n\"\n+\t\t\t\t\"\t%s\\n\"\n+\t\t\t\t\"and try again.\\n\"\n+\t\t\t\t\"\",\n \t\t\t\tgit_path(\"MERGE_HEAD\"));\n \n-\t\tfprintf(s->fp,\n-\t\t\t\"\\n\"\n-\t\t\t\"# Please enter the commit message for your changes.\");\n+\t\tfprintf(s->fp, \"\\n\");\n+\t\tstatus_printf(s, GIT_COLOR_NORMAL,\n+\t\t\t\"Please enter the commit message for your changes.\");\n \t\tif (cleanup_mode == CLEANUP_ALL)\n-\t\t\tfprintf(s->fp,\n+\t\t\tstatus_printf_more(s, GIT_COLOR_NORMAL,\n \t\t\t\t\" Lines starting\\n\"\n-\t\t\t\t\"# with '#' will be ignored, and an empty\"\n+\t\t\t\t\"with '#' will be ignored, and an empty\"\n \t\t\t\t\" message aborts the commit.\\n\");\n \t\telse /* CLEANUP_SPACE, that is. */\n-\t\t\tfprintf(s->fp,\n+\t\t\tstatus_printf_more(s, GIT_COLOR_NORMAL,\n \t\t\t\t\" Lines starting\\n\"\n-\t\t\t\t\"# with '#' will be kept; you may remove them\"\n+\t\t\t\t\"with '#' will be kept; you may remove them\"\n \t\t\t\t\" yourself if you want to.\\n\"\n-\t\t\t\t\"# An empty message aborts the commit.\\n\");\n+\t\t\t\t\"An empty message aborts the commit.\\n\");\n \t\tif (only_include_assumed)\n-\t\t\tfprintf(s->fp, \"# %s\\n\", only_include_assumed);\n+\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n+\t\t\t\t\t\"%s\", only_include_assumed);\n \n \t\tai_tmp = cut_ident_timestamp_part(author_ident->buf);\n \t\tci_tmp = cut_ident_timestamp_part(committer_ident.buf);\n \t\tif (strcmp(author_ident->buf, committer_ident.buf))\n-\t\t\tfprintf(s->fp,\n+\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n \t\t\t\t\"%s\"\n-\t\t\t\t\"# Author:    %s\\n\",\n-\t\t\t\tident_shown++ ? \"\" : \"#\\n\",\n+\t\t\t\t\"Author:    %s\",\n+\t\t\t\tident_shown++ ? \"\" : \"\\n\",\n \t\t\t\tauthor_ident->buf);\n \n \t\tif (!user_ident_sufficiently_given())\n-\t\t\tfprintf(s->fp,\n+\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n \t\t\t\t\"%s\"\n-\t\t\t\t\"# Committer: %s\\n\",\n-\t\t\t\tident_shown++ ? \"\" : \"#\\n\",\n+\t\t\t\t\"Committer: %s\",\n+\t\t\t\tident_shown++ ? \"\" : \"\\n\",\n \t\t\t\tcommitter_ident.buf);\n \n \t\tif (ident_shown)\n-\t\t\tfprintf(s->fp, \"#\\n\");\n+\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL, \"\");\n \n \t\tsaved_color_setting = s->use_color;\n \t\ts->use_color = 0;\ndiff --git a/wt-status.c b/wt-status.c\nindex 1abd7c3..c14cbe4 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -131,33 +131,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s)\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\tcolor_fprintf_ln(s->fp, c, \"# Unmerged paths:\");\n+\tstatus_printf_ln(s, c, \"Unmerged paths:\");\n \tif (!advice_status_hints)\n \t\treturn;\n \tif (s->in_merge)\n \t\t;\n \telse if (!s->is_initial)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git reset %s <file>...\\\" to unstage)\", s->reference);\n+\t\tstatus_printf_ln(s, c, \"  (use \\\"git reset %s <file>...\\\" to unstage)\", s->reference);\n \telse\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git rm --cached <file>...\\\" to unstage)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add/rm <file>...\\\" as appropriate to mark resolution)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#\");\n+\t\tstatus_printf_ln(s, c, \"  (use \\\"git rm --cached <file>...\\\" to unstage)\");\n+\tstatus_printf_ln(s, c, \"  (use \\\"git add/rm <file>...\\\" as appropriate to mark resolution)\");\n+\tstatus_printf_ln(s, c, \"\");\n }\n \n static void wt_status_print_cached_header(struct wt_status *s)\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\tcolor_fprintf_ln(s->fp, c, \"# Changes to be committed:\");\n+\tstatus_printf_ln(s, c, \"Changes to be committed:\");\n \tif (!advice_status_hints)\n \t\treturn;\n \tif (s->in_merge)\n \t\t; /* NEEDSWORK: use \"git reset --unresolve\"??? */\n \telse if (!s->is_initial)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git reset %s <file>...\\\" to unstage)\", s->reference);\n+\t\tstatus_printf_ln(s, c, \"  (use \\\"git reset %s <file>...\\\" to unstage)\", s->reference);\n \telse\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git rm --cached <file>...\\\" to unstage)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#\");\n+\t\tstatus_printf_ln(s, c, \"  (use \\\"git rm --cached <file>...\\\" to unstage)\");\n+\tstatus_printf_ln(s, c, \"\");\n }\n \n static void wt_status_print_dirty_header(struct wt_status *s,\n@@ -166,17 +166,17 @@ static void wt_status_print_dirty_header(struct wt_status *s,\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\tcolor_fprintf_ln(s->fp, c, \"# Changes not staged for commit:\");\n+\tstatus_printf_ln(s, c, \"Changes not staged for commit:\");\n \tif (!advice_status_hints)\n \t\treturn;\n \tif (!has_deleted)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add <file>...\\\" to update what will be committed)\");\n+\t\tstatus_printf_ln(s, c, \"  (use \\\"git add <file>...\\\" to update what will be committed)\");\n \telse\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add/rm <file>...\\\" to update what will be committed)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git checkout -- <file>...\\\" to discard changes in working directory)\");\n+\t\tstatus_printf_ln(s, c, \"  (use \\\"git add/rm <file>...\\\" to update what will be committed)\");\n+\tstatus_printf_ln(s, c, \"  (use \\\"git checkout -- <file>...\\\" to discard changes in working directory)\");\n \tif (has_dirty_submodules)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (commit or discard the untracked or modified content in submodules)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#\");\n+\t\tstatus_printf_ln(s, c, \"  (commit or discard the untracked or modified content in submodules)\");\n+\tstatus_printf_ln(s, c, \"\");\n }\n \n static void wt_status_print_other_header(struct wt_status *s,\n@@ -184,16 +184,16 @@ static void wt_status_print_other_header(struct wt_status *s,\n \t\t\t\t\t const char *how)\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n-\tcolor_fprintf_ln(s->fp, c, \"# %s files:\", what);\n+\tstatus_printf_ln(s, c, \"%s files:\", what);\n \tif (!advice_status_hints)\n \t\treturn;\n-\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git %s <file>...\\\" to include in what will be committed)\", how);\n-\tcolor_fprintf_ln(s->fp, c, \"#\");\n+\tstatus_printf_ln(s, c, \"  (use \\\"git %s <file>...\\\" to include in what will be committed)\", how);\n+\tstatus_printf_ln(s, c, \"\");\n }\n \n static void wt_status_print_trailer(struct wt_status *s)\n {\n-\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"#\");\n+\tstatus_printf_ln(s, color(WT_STATUS_HEADER, s), \"\");\n }\n \n #define quote_path quote_path_relative\n@@ -207,7 +207,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,\n \tconst char *one, *how = \"bug\";\n \n \tone = quote_path(it->string, -1, &onebuf, s->prefix);\n-\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"#\\t\");\n+\tstatus_printf(s, color(WT_STATUS_HEADER, s), \"\\t\");\n \tswitch (d->stagemask) {\n \tcase 1: how = \"both deleted:\"; break;\n \tcase 2: how = \"added by us:\"; break;\n@@ -217,7 +217,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,\n \tcase 6: how = \"both added:\"; break;\n \tcase 7: how = \"both modified:\"; break;\n \t}\n-\tcolor_fprintf(s->fp, c, \"%-20s%s\\n\", how, one);\n+\tstatus_printf_more(s, c, \"%-20s%s\\n\", how, one);\n \tstrbuf_release(&onebuf);\n }\n \n@@ -260,40 +260,40 @@ static void wt_status_print_change_data(struct wt_status *s,\n \tone = quote_path(one_name, -1, &onebuf, s->prefix);\n \ttwo = quote_path(two_name, -1, &twobuf, s->prefix);\n \n-\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"#\\t\");\n+\tstatus_printf(s, color(WT_STATUS_HEADER, s), \"\\t\");\n \tswitch (status) {\n \tcase DIFF_STATUS_ADDED:\n-\t\tcolor_fprintf(s->fp, c, \"new file:   %s\", one);\n+\t\tstatus_printf_more(s, c, \"new file:   %s\", one);\n \t\tbreak;\n \tcase DIFF_STATUS_COPIED:\n-\t\tcolor_fprintf(s->fp, c, \"copied:     %s -> %s\", one, two);\n+\t\tstatus_printf_more(s, c, \"copied:     %s -> %s\", one, two);\n \t\tbreak;\n \tcase DIFF_STATUS_DELETED:\n-\t\tcolor_fprintf(s->fp, c, \"deleted:    %s\", one);\n+\t\tstatus_printf_more(s, c, \"deleted:    %s\", one);\n \t\tbreak;\n \tcase DIFF_STATUS_MODIFIED:\n-\t\tcolor_fprintf(s->fp, c, \"modified:   %s\", one);\n+\t\tstatus_printf_more(s, c, \"modified:   %s\", one);\n \t\tbreak;\n \tcase DIFF_STATUS_RENAMED:\n-\t\tcolor_fprintf(s->fp, c, \"renamed:    %s -> %s\", one, two);\n+\t\tstatus_printf_more(s, c, \"renamed:    %s -> %s\", one, two);\n \t\tbreak;\n \tcase DIFF_STATUS_TYPE_CHANGED:\n-\t\tcolor_fprintf(s->fp, c, \"typechange: %s\", one);\n+\t\tstatus_printf_more(s, c, \"typechange: %s\", one);\n \t\tbreak;\n \tcase DIFF_STATUS_UNKNOWN:\n-\t\tcolor_fprintf(s->fp, c, \"unknown:    %s\", one);\n+\t\tstatus_printf_more(s, c, \"unknown:    %s\", one);\n \t\tbreak;\n \tcase DIFF_STATUS_UNMERGED:\n-\t\tcolor_fprintf(s->fp, c, \"unmerged:   %s\", one);\n+\t\tstatus_printf_more(s, c, \"unmerged:   %s\", one);\n \t\tbreak;\n \tdefault:\n \t\tdie(\"bug: unhandled diff status %c\", status);\n \t}\n \tif (extra.len) {\n-\t\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"%s\", extra.buf);\n+\t\tstatus_printf_more(s, color(WT_STATUS_HEADER, s), \"%s\", extra.buf);\n \t\tstrbuf_release(&extra);\n \t}\n-\tfprintf(s->fp, \"\\n\");\n+\tstatus_printf_more(s, GIT_COLOR_NORMAL, \"\\n\");\n \tstrbuf_release(&onebuf);\n \tstrbuf_release(&twobuf);\n }\n@@ -647,9 +647,9 @@ static void wt_status_print_other(struct wt_status *s,\n \tfor (i = 0; i < l->nr; i++) {\n \t\tstruct string_list_item *it;\n \t\tit = &(l->items[i]);\n-\t\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"#\\t\");\n-\t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), \"%s\",\n-\t\t\t\t quote_path(it->string, strlen(it->string),\n+\t\tstatus_printf(s, color(WT_STATUS_HEADER, s), \"\\t\");\n+\t\tstatus_printf_more(s, color(WT_STATUS_UNTRACKED, s),\n+\t\t\t\"%s\\n\", quote_path(it->string, strlen(it->string),\n \t\t\t\t\t    &buf, s->prefix));\n \t}\n \tstrbuf_release(&buf);\n@@ -716,17 +716,17 @@ void wt_status_print(struct wt_status *s)\n \t\t\tbranch_status_color = color(WT_STATUS_NOBRANCH, s);\n \t\t\ton_what = \"Not currently on any branch.\";\n \t\t}\n-\t\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"# \");\n-\t\tcolor_fprintf(s->fp, branch_status_color, \"%s\", on_what);\n-\t\tcolor_fprintf_ln(s->fp, branch_color, \"%s\", branch_name);\n+\t\tstatus_printf(s, color(WT_STATUS_HEADER, s), \"\");\n+\t\tstatus_printf_more(s, branch_status_color, \"%s\", on_what);\n+\t\tstatus_printf_more(s, branch_color, \"%s\\n\", branch_name);\n \t\tif (!s->is_initial)\n \t\t\twt_status_print_tracking(s);\n \t}\n \n \tif (s->is_initial) {\n-\t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"#\");\n-\t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"# Initial commit\");\n-\t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"#\");\n+\t\tstatus_printf_ln(s, color(WT_STATUS_HEADER, s), \"\");\n+\t\tstatus_printf_ln(s, color(WT_STATUS_HEADER, s), \"Initial commit\");\n+\t\tstatus_printf_ln(s, color(WT_STATUS_HEADER, s), \"\");\n \t}\n \n \twt_status_print_updated(s);\n@@ -743,7 +743,7 @@ void wt_status_print(struct wt_status *s)\n \t\tif (s->show_ignored_files)\n \t\t\twt_status_print_other(s, &s->ignored, \"Ignored\", \"add -f\");\n \t} else if (s->commitable)\n-\t\tfprintf(s->fp, \"# Untracked files not listed%s\\n\",\n+\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL, \"Untracked files not listed%s\",\n \t\t\tadvice_status_hints\n \t\t\t? \" (use -u option to show untracked files)\" : \"\");\n \n@@ -751,7 +751,7 @@ void wt_status_print(struct wt_status *s)\n \t\twt_status_print_verbose(s);\n \tif (!s->commitable) {\n \t\tif (s->amend)\n-\t\t\tfprintf(s->fp, \"# No changes\\n\");\n+\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL, \"No changes\");\n \t\telse if (s->nowarn)\n \t\t\t; /* nothing */\n \t\telse if (s->workdir_dirty)\n-- \n1.7.4.1\n"},{"id":"162344","messageId":"7vaahh6dw0.fsf@alter.siamese.dyndns.org","threadId":"26607","inReplyTo":"20110226051137.GE27887@elie","subject":"Re: [PATCH 5/5] commit, status: use status_printf{,_ln,_more} helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-27T09:11:11Z","receivedAt":"2011-02-27T09:11:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index ef5f0b2..ae62a25 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -694,50 +694,51 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n>  \tif (use_editor && include_status) {\n>  \t\tchar *ai_tmp, *ci_tmp;\n>  \t\tif (in_merge)\n> -...\n> +\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n> +\t\t\t\t\"\\n\"\n> +\t\t\t\t\"It looks like you may be committing a MERGE.\\n\"\n> +\t\t\t\t\"If this is not correct, please remove the file\\n\"\n> +\t\t\t\t\"\t%s\\n\"\n> +\t\t\t\t\"and try again.\\n\"\n> +\t\t\t\t\"\",\n\nThis trick to avoid difference-in-comma-when-updated was semi \"Huh\" when\nreading.  Is it worth it?\n\n> ...\n>  \t\tif (ident_shown)\n> -\t\t\tfprintf(s->fp, \"#\\n\");\n> +\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL, \"\");\n\nThe \"attribute((format))\" safety seems to bite us here...\n\n    $ Meta/Make --pedantic builtin/commit.o\n        CC builtin/commit.o\n    cc1: warnings being treated as errors\n    builtin/commit.c: In function 'prepare_to_commit':\n    builtin/commit.c:741: error: zero-length printf format string\n\nIn wt-status.c many similar ones exist, unfortunately.\n"},{"id":"162348","messageId":"20110227095022.GB24391@elie","threadId":"26607","inReplyTo":"7vaahh6dw0.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 5/5] commit, status: use status_printf{,_ln,_more} helpers","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-27T09:50:37Z","receivedAt":"2011-02-27T09:50:37Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n> Jonathan Nieder <jrnieder@gmail.com> writes:\n\n>> +++ b/builtin/commit.c\n>> @@ -694,50 +694,51 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n>>  \tif (use_editor && include_status) {\n>>  \t\tchar *ai_tmp, *ci_tmp;\n>>  \t\tif (in_merge)\n>> -...\n>> +\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n>> +\t\t\t\t\"\\n\"\n>> +\t\t\t\t\"It looks like you may be committing a MERGE.\\n\"\n>> +\t\t\t\t\"If this is not correct, please remove the file\\n\"\n>> +\t\t\t\t\"\t%s\\n\"\n>> +\t\t\t\t\"and try again.\\n\"\n>> +\t\t\t\t\"\",\n>\n> This trick to avoid difference-in-comma-when-updated was semi \"Huh\" when\n> reading.  Is it worth it?\n\nThe hint starts and ends with a blank (commented) line.\n\n\t\t\tstatus_printf(s, GIT_COLOR_NORMAL,\n\t\t\t\t\"\\n\"\n\t\t\t\t...\n\t\t\t\t\"and try again.\\n\"\n\t\t\t\t\"\\n\",\n\nwould be clearer.\n\n> The \"attribute((format))\" safety seems to bite us here...\n>\n>     $ Meta/Make --pedantic builtin/commit.o\n>         CC builtin/commit.o\n>     cc1: warnings being treated as errors\n>     builtin/commit.c: In function 'prepare_to_commit':\n>     builtin/commit.c:741: error: zero-length printf format string\n>\n> In wt-status.c many similar ones exist, unfortunately.\n\nWhat a warning. :)  I don't understand how it is supposed to benefit\nthe world[1].\n\n\tstatus_printf_ln(s, GIT_COLOR_NORMAL, \"%s\", \"\");\n\tstatus_printf(s, GIT_COLOR_NORMAL, \"\\n\");\n\nI suppose the latter could be a bearable workaround.\n\n[1] http://gcc.gnu.org/ml/gcc-patches/2002-05/msg01462.html\n"}]}