{"thread":{"id":"32852","subject":"[PATCH 3/6] diff.c: make constant string arguments const","startedAt":"2013-02-07T20:15:22Z","lastAt":"2013-02-08T19:31:26Z","messageCount":9,"participants":["John Keeping","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"208946","messageId":"cover.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":null,"subject":"[PATCH 0/6] Improve \"git log --graph\" output of merges","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:22Z","receivedAt":"2013-02-07T20:15:22Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"This series changes a couple of places that do not currently indent\ntheir output when being shown with a graph.\n\nThe first patch was already posted [1] and addresses the output of \"git\nlog --graph -c -p\".  Patch 2 is an independent fix I noticed while\nworking on the later patches.\n\nPatches 3-5 introduce a helper function and change existing sites using\ndiff_options->output_prefix to use it, resulting in a net reduction by\nabout 60 lines.  There is no functional change here.\n\nThe final patch uses the helper introduced in patch 4 to make combined\ndiffs should the output prefix before each line.  This affects the\noutput of \"git log --graph --cc [-p|--raw]\".\n\n[1] http://article.gmane.org/gmane.comp.version-control.git/215630\n\nJohn Keeping (6):\n  graph: output padding for merge subsequent parents\n  diff: write prefix to the correct file\n  diff.c: make constant string arguments const\n  diff: add diff_line_prefix function\n  diff.c: use diff_line_prefix() where applicable\n  combine-diff.c: teach combined diffs about line prefix\n\n combine-diff.c |  47 +++++++++++++--------\n diff.c         | 131 +++++++++++++++------------------------------------------\n diff.h         |   3 ++\n graph.c        |  10 +++++\n 4 files changed, 77 insertions(+), 114 deletions(-)\n\n-- \n1.8.1.2\n"},{"id":"208945","messageId":"b98eb2bfe2b022ddf1afbe9f7123accfe068e8c9.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"[PATCH 1/6] graph: output padding for merge subsequent parents","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:23Z","receivedAt":"2013-02-07T20:15:23Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"When showing merges in git-log, the same commit is shown once for each\nparent.  Combined with \"--graph\" this results in graph_show_commit()\nbeing called once for each parent without graph_update() being called.\n\nCurrently graph_show_commit() does not print anything on subsequent\ninvocations for the same commit (this was changed by commit 656197a -\n\"graph.c: infinite loop in git whatchanged --graph -m\" from the previous\nbehaviour of looping infinitely).\n\nChange this so that if the graph code believes it has already shown the\ncommit it prints a single padding line.\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n---\n graph.c | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/graph.c b/graph.c\nindex 391a712..2a3fc5c 100644\n--- a/graph.c\n+++ b/graph.c\n@@ -1227,6 +1227,16 @@ void graph_show_commit(struct git_graph *graph)\n \tif (!graph)\n \t\treturn;\n \n+\t/*\n+\t * When showing a diff of a merge against each of its parents, we\n+\t * are called once for each parent without graph_update having been\n+\t * called.  In this case, simply output a single padding line.\n+\t */\n+\tif (graph_is_commit_finished(graph)) {\n+\t\tgraph_show_padding(graph);\n+\t\tshown_commit_line = 1;\n+\t}\n+\n \twhile (!shown_commit_line && !graph_is_commit_finished(graph)) {\n \t\tshown_commit_line = graph_next_line(graph, &msgbuf);\n \t\tfwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);\n-- \n1.8.1.2\n"},{"id":"208944","messageId":"c7a6fca9a3199f05281d01f9fddab18a37f28932.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"[PATCH 2/6] diff: write prefix to the correct file","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:24Z","receivedAt":"2013-02-07T20:15:24Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"Write the prefix for an output line to the same file as the actual\ncontent.\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n---\n diff.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/diff.c b/diff.c\nindex 348f71b..bf95235 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4485,7 +4485,7 @@ void diff_flush(struct diff_options *options)\n \t\t\t\tstruct strbuf *msg = NULL;\n \t\t\t\tmsg = options->output_prefix(options,\n \t\t\t\t\toptions->output_prefix_data);\n-\t\t\t\tfwrite(msg->buf, msg->len, 1, stdout);\n+\t\t\t\tfwrite(msg->buf, msg->len, 1, options->file);\n \t\t\t}\n \t\t\tputc(options->line_termination, options->file);\n \t\t\tif (options->stat_sep) {\n-- \n1.8.1.2\n"},{"id":"208943","messageId":"41ec7ef2fdc2a56c43abd00ef9a48fc41b765c9b.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"[PATCH 3/6] diff.c: make constant string arguments const","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:25Z","receivedAt":"2013-02-07T20:15:25Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"Signed-off-by: John Keeping <john@keeping.me.uk>\n---\n diff.c | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex bf95235..73ae02d 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2123,7 +2123,8 @@ static unsigned char *deflate_it(char *data,\n \treturn deflated;\n }\n \n-static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two, char *prefix)\n+static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two,\n+\t\t\t\t  const char *prefix)\n {\n \tvoid *cp;\n \tvoid *delta;\n@@ -2184,7 +2185,8 @@ static void emit_binary_diff_body(FILE *file, mmfile_t *one, mmfile_t *two, char\n \tfree(data);\n }\n \n-static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two, char *prefix)\n+static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two,\n+\t\t\t     const char *prefix)\n {\n \tfprintf(file, \"%sGIT binary patch\\n\", prefix);\n \temit_binary_diff_body(file, one, two, prefix);\n-- \n1.8.1.2\n"},{"id":"208948","messageId":"dfb0c8fc336ae6e125e5307311e8b49425d06aa5.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"[PATCH 4/6] diff: add diff_line_prefix function","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:26Z","receivedAt":"2013-02-07T20:15:26Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"This is a helper function to call the diff output_prefix function and\nreturn its value as a C string, allowing us to greatly simplify\neverywhere that needs to get the output prefix.\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n---\n diff.c | 10 ++++++++++\n diff.h |  3 +++\n 2 files changed, 13 insertions(+)\n\ndiff --git a/diff.c b/diff.c\nindex 73ae02d..ed14d5d 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1105,6 +1105,16 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)\n \treturn \"\";\n }\n \n+const char *diff_line_prefix(struct diff_options *opt)\n+{\n+\tstruct strbuf *msgbuf;\n+\tif (!opt->output_prefix)\n+\t\treturn \"\";\n+\n+\tmsgbuf = opt->output_prefix(opt, opt->output_prefix_data);\n+\treturn msgbuf->buf;\n+}\n+\n static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, unsigned long len)\n {\n \tconst char *cp;\ndiff --git a/diff.h b/diff.h\nindex a47bae4..76830e2 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -174,6 +174,9 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix);\n \tdiff_get_color((o)->use_color, ix)\n \n \n+const char *diff_line_prefix(struct diff_options *);\n+\n+\n extern const char mime_boundary_leader[];\n \n extern void diff_tree_setup_paths(const char **paths, struct diff_options *);\n-- \n1.8.1.2\n"},{"id":"208947","messageId":"360d40dc944e0f2d944c5ba5ae69b4b352d8d6ad.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"[PATCH 5/6] diff.c: use diff_line_prefix() where applicable","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:27Z","receivedAt":"2013-02-07T20:15:27Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"Signed-off-by: John Keeping <john@keeping.me.uk>\n---\n diff.c | 115 ++++++++++++-----------------------------------------------------\n 1 file changed, 20 insertions(+), 95 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex ed14d5d..f441f6c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -402,12 +402,7 @@ static void emit_line_0(struct diff_options *o, const char *set, const char *res\n \tint nofirst;\n \tFILE *file = o->file;\n \n-\tif (o->output_prefix) {\n-\t\tstruct strbuf *msg = NULL;\n-\t\tmsg = o->output_prefix(o, o->output_prefix_data);\n-\t\tassert(msg);\n-\t\tfwrite(msg->buf, msg->len, 1, file);\n-\t}\n+\tfputs(diff_line_prefix(o), file);\n \n \tif (len == 0) {\n \t\thas_trailing_newline = (first == '\\n');\n@@ -625,13 +620,7 @@ static void emit_rewrite_diff(const char *name_a,\n \tchar *data_one, *data_two;\n \tsize_t size_one, size_two;\n \tstruct emit_callback ecbdata;\n-\tchar *line_prefix = \"\";\n-\tstruct strbuf *msgbuf;\n-\n-\tif (o && o->output_prefix) {\n-\t\tmsgbuf = o->output_prefix(o, o->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n+\tconst char *line_prefix = diff_line_prefix(o);\n \n \tif (diff_mnemonic_prefix && DIFF_OPT_TST(o, REVERSE_DIFF)) {\n \t\ta_prefix = o->b_prefix;\n@@ -827,18 +816,14 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)\n \tint minus_first, minus_len, plus_first, plus_len;\n \tconst char *minus_begin, *minus_end, *plus_begin, *plus_end;\n \tstruct diff_options *opt = diff_words->opt;\n-\tstruct strbuf *msgbuf;\n-\tchar *line_prefix = \"\";\n+\tconst char *line_prefix;\n \n \tif (line[0] != '@' || parse_hunk_header(line, len,\n \t\t\t&minus_first, &minus_len, &plus_first, &plus_len))\n \t\treturn;\n \n \tassert(opt);\n-\tif (opt->output_prefix) {\n-\t\tmsgbuf = opt->output_prefix(opt, opt->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n+\tline_prefix = diff_line_prefix(opt);\n \n \t/* POSIX requires that first be decremented by one if len == 0... */\n \tif (minus_len) {\n@@ -962,14 +947,10 @@ static void diff_words_show(struct diff_words_data *diff_words)\n \tstruct diff_words_style *style = diff_words->style;\n \n \tstruct diff_options *opt = diff_words->opt;\n-\tstruct strbuf *msgbuf;\n-\tchar *line_prefix = \"\";\n+\tconst char *line_prefix;\n \n \tassert(opt);\n-\tif (opt->output_prefix) {\n-\t\tmsgbuf = opt->output_prefix(opt, opt->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n+\tline_prefix = diff_line_prefix(opt);\n \n \t/* special case: only removal */\n \tif (!diff_words->plus.text.size) {\n@@ -1155,13 +1136,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \tconst char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);\n \tconst char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);\n \tstruct diff_options *o = ecbdata->opt;\n-\tchar *line_prefix = \"\";\n-\tstruct strbuf *msgbuf;\n-\n-\tif (o && o->output_prefix) {\n-\t\tmsgbuf = o->output_prefix(o, o->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n+\tconst char *line_prefix = diff_line_prefix(o);\n \n \tif (ecbdata->header) {\n \t\tfprintf(ecbdata->opt->file, \"%s\", ecbdata->header->buf);\n@@ -1485,16 +1460,11 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)\n \tconst char *reset, *add_c, *del_c;\n \tconst char *line_prefix = \"\";\n \tint extra_shown = 0;\n-\tstruct strbuf *msg = NULL;\n \n \tif (data->nr == 0)\n \t\treturn;\n \n-\tif (options->output_prefix) {\n-\t\tmsg = options->output_prefix(options, options->output_prefix_data);\n-\t\tline_prefix = msg->buf;\n-\t}\n-\n+\tline_prefix = diff_line_prefix(options);\n \tcount = options->stat_count ? options->stat_count : data->nr;\n \n \treset = diff_get_color_opt(options, DIFF_RESET);\n@@ -1746,12 +1716,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option\n \t\t\tdels += deleted;\n \t\t}\n \t}\n-\tif (options->output_prefix) {\n-\t\tstruct strbuf *msg = NULL;\n-\t\tmsg = options->output_prefix(options,\n-\t\t\t\toptions->output_prefix_data);\n-\t\tfprintf(options->file, \"%s\", msg->buf);\n-\t}\n+\tfprintf(options->file, \"%s\", diff_line_prefix(options));\n \tprint_stat_summary(options->file, total_files, adds, dels);\n }\n \n@@ -1765,12 +1730,7 @@ static void show_numstat(struct diffstat_t *data, struct diff_options *options)\n \tfor (i = 0; i < data->nr; i++) {\n \t\tstruct diffstat_file *file = data->files[i];\n \n-\t\tif (options->output_prefix) {\n-\t\t\tstruct strbuf *msg = NULL;\n-\t\t\tmsg = options->output_prefix(options,\n-\t\t\t\t\toptions->output_prefix_data);\n-\t\t\tfprintf(options->file, \"%s\", msg->buf);\n-\t\t}\n+\t\tfprintf(options->file, \"%s\", diff_line_prefix(options));\n \n \t\tif (file->is_binary)\n \t\t\tfprintf(options->file, \"-\\t-\\t\");\n@@ -1812,13 +1772,7 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,\n {\n \tunsigned long this_dir = 0;\n \tunsigned int sources = 0;\n-\tconst char *line_prefix = \"\";\n-\tstruct strbuf *msg = NULL;\n-\n-\tif (opt->output_prefix) {\n-\t\tmsg = opt->output_prefix(opt, opt->output_prefix_data);\n-\t\tline_prefix = msg->buf;\n-\t}\n+\tconst char *line_prefix = diff_line_prefix(opt);\n \n \twhile (dir->nr) {\n \t\tstruct dirstat_file *f = dir->files;\n@@ -2068,15 +2022,10 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)\n \tconst char *reset = diff_get_color(data->o->use_color, DIFF_RESET);\n \tconst char *set = diff_get_color(data->o->use_color, DIFF_FILE_NEW);\n \tchar *err;\n-\tchar *line_prefix = \"\";\n-\tstruct strbuf *msgbuf;\n+\tconst char *line_prefix;\n \n \tassert(data->o);\n-\tif (data->o->output_prefix) {\n-\t\tmsgbuf = data->o->output_prefix(data->o,\n-\t\t\tdata->o->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n+\tline_prefix = diff_line_prefix(data->o);\n \n \tif (line[0] == '+') {\n \t\tunsigned bad;\n@@ -2263,13 +2212,7 @@ static void builtin_diff(const char *name_a,\n \tstruct userdiff_driver *textconv_one = NULL;\n \tstruct userdiff_driver *textconv_two = NULL;\n \tstruct strbuf header = STRBUF_INIT;\n-\tstruct strbuf *msgbuf;\n-\tchar *line_prefix = \"\";\n-\n-\tif (o->output_prefix) {\n-\t\tmsgbuf = o->output_prefix(o, o->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n+\tconst char *line_prefix = diff_line_prefix(o);\n \n \tif (DIFF_OPT_TST(o, SUBMODULE_LOG) &&\n \t\t\t(!one->mode || S_ISGITLINK(one->mode)) &&\n@@ -2968,14 +2911,9 @@ static void fill_metainfo(struct strbuf *msg,\n {\n \tconst char *set = diff_get_color(use_color, DIFF_METAINFO);\n \tconst char *reset = diff_get_color(use_color, DIFF_RESET);\n-\tstruct strbuf *msgbuf;\n-\tchar *line_prefix = \"\";\n+\tconst char *line_prefix = diff_line_prefix(o);\n \n \t*must_show_header = 1;\n-\tif (o->output_prefix) {\n-\t\tmsgbuf = o->output_prefix(o, o->output_prefix_data);\n-\t\tline_prefix = msgbuf->buf;\n-\t}\n \tstrbuf_init(msg, PATH_MAX * 2 + 300);\n \tswitch (p->status) {\n \tcase DIFF_STATUS_COPIED:\n@@ -3912,12 +3850,8 @@ static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)\n {\n \tint line_termination = opt->line_termination;\n \tint inter_name_termination = line_termination ? '\\t' : '\\0';\n-\tif (opt->output_prefix) {\n-\t\tstruct strbuf *msg = NULL;\n-\t\tmsg = opt->output_prefix(opt, opt->output_prefix_data);\n-\t\tfprintf(opt->file, \"%s\", msg->buf);\n-\t}\n \n+\tfprintf(opt->file, \"%s\", diff_line_prefix(opt));\n \tif (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {\n \t\tfprintf(opt->file, \":%06o %06o %s \", p->one->mode, p->two->mode,\n \t\t\tdiff_unique_abbrev(p->one->sha1, opt->abbrev));\n@@ -4187,12 +4121,7 @@ static void show_rename_copy(FILE *file, const char *renamecopy, struct diff_fil\n static void diff_summary(struct diff_options *opt, struct diff_filepair *p)\n {\n \tFILE *file = opt->file;\n-\tchar *line_prefix = \"\";\n-\n-\tif (opt->output_prefix) {\n-\t\tstruct strbuf *buf = opt->output_prefix(opt, opt->output_prefix_data);\n-\t\tline_prefix = buf->buf;\n-\t}\n+\tconst char *line_prefix = diff_line_prefix(opt);\n \n \tswitch(p->status) {\n \tcase DIFF_STATUS_DELETED:\n@@ -4493,13 +4422,9 @@ void diff_flush(struct diff_options *options)\n \n \tif (output_format & DIFF_FORMAT_PATCH) {\n \t\tif (separator) {\n-\t\t\tif (options->output_prefix) {\n-\t\t\t\tstruct strbuf *msg = NULL;\n-\t\t\t\tmsg = options->output_prefix(options,\n-\t\t\t\t\toptions->output_prefix_data);\n-\t\t\t\tfwrite(msg->buf, msg->len, 1, options->file);\n-\t\t\t}\n-\t\t\tputc(options->line_termination, options->file);\n+\t\t\tfprintf(options->file, \"%s%c\",\n+\t\t\t\tdiff_line_prefix(options),\n+\t\t\t\toptions->line_termination);\n \t\t\tif (options->stat_sep) {\n \t\t\t\t/* attach patch instead of inline */\n \t\t\t\tfputs(options->stat_sep, options->file);\n-- \n1.8.1.2\n"},{"id":"208949","messageId":"ca0ba198f798a5d9aeac2bf23a4ec2d0ceebcdb7.1360267849.git.john@keeping.me.uk","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"[PATCH 6/6] combine-diff.c: teach combined diffs about line prefix","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-07T20:15:28Z","receivedAt":"2013-02-07T20:15:28Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"When running \"git log --graph --cc -p\" the diff output for merges is not\nindented by the graph structure, unlike the diffs of non-merge commits\n(added in commit 7be5761 - diff.c: Output the text graph padding before\neach diff line).\n\nFix this by teaching the combined diff code to output diff_line_prefix()\nbefore each line.\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n---\n combine-diff.c | 47 ++++++++++++++++++++++++++++++-----------------\n 1 file changed, 30 insertions(+), 17 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex bb1cc96..35c817b 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -526,7 +526,8 @@ static void show_line_to_eol(const char *line, int len, const char *reset)\n \t       saw_cr_at_eol ? \"\\r\" : \"\");\n }\n \n-static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n+static void dump_sline(struct sline *sline, const char *line_prefix,\n+\t\t       unsigned long cnt, int num_parent,\n \t\t       int use_color, int result_deleted)\n {\n \tunsigned long mark = (1UL<<num_parent);\n@@ -582,7 +583,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n \t\t\trlines -= null_context;\n \t\t}\n \n-\t\tfputs(c_frag, stdout);\n+\t\tprintf(\"%s%s\", line_prefix, c_frag);\n \t\tfor (i = 0; i <= num_parent; i++) putchar(combine_marker);\n \t\tfor (i = 0; i < num_parent; i++)\n \t\t\tshow_parent_lno(sline, lno, hunk_end, i, null_context);\n@@ -614,7 +615,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n \t\t\tstruct sline *sl = &sline[lno++];\n \t\t\tll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;\n \t\t\twhile (ll) {\n-\t\t\t\tfputs(c_old, stdout);\n+\t\t\t\tprintf(\"%s%s\", line_prefix, c_old);\n \t\t\t\tfor (j = 0; j < num_parent; j++) {\n \t\t\t\t\tif (ll->parent_map & (1UL<<j))\n \t\t\t\t\t\tputchar('-');\n@@ -627,6 +628,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n \t\t\tif (cnt < lno)\n \t\t\t\tbreak;\n \t\t\tp_mask = 1;\n+\t\t\tfputs(line_prefix, stdout);\n \t\t\tif (!(sl->flag & (mark-1))) {\n \t\t\t\t/*\n \t\t\t\t * This sline was here to hang the\n@@ -680,11 +682,13 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,\n static void dump_quoted_path(const char *head,\n \t\t\t     const char *prefix,\n \t\t\t     const char *path,\n+\t\t\t     const char *line_prefix,\n \t\t\t     const char *c_meta, const char *c_reset)\n {\n \tstatic struct strbuf buf = STRBUF_INIT;\n \n \tstrbuf_reset(&buf);\n+\tstrbuf_addstr(&buf, line_prefix);\n \tstrbuf_addstr(&buf, c_meta);\n \tstrbuf_addstr(&buf, head);\n \tquote_two_c_style(&buf, prefix, path, 0);\n@@ -696,6 +700,7 @@ static void show_combined_header(struct combine_diff_path *elem,\n \t\t\t\t int num_parent,\n \t\t\t\t int dense,\n \t\t\t\t struct rev_info *rev,\n+\t\t\t\t const char *line_prefix,\n \t\t\t\t int mode_differs,\n \t\t\t\t int show_file_header)\n {\n@@ -714,8 +719,8 @@ static void show_combined_header(struct combine_diff_path *elem,\n \t\tshow_log(rev);\n \n \tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \",\n-\t\t\t \"\", elem->path, c_meta, c_reset);\n-\tprintf(\"%sindex \", c_meta);\n+\t\t\t \"\", elem->path, line_prefix, c_meta, c_reset);\n+\tprintf(\"%s%sindex \", line_prefix, c_meta);\n \tfor (i = 0; i < num_parent; i++) {\n \t\tabb = find_unique_abbrev(elem->parent[i].sha1,\n \t\t\t\t\t abbrev);\n@@ -734,11 +739,12 @@ static void show_combined_header(struct combine_diff_path *elem,\n \t\t\t    DIFF_STATUS_ADDED)\n \t\t\t\tadded = 0;\n \t\tif (added)\n-\t\t\tprintf(\"%snew file mode %06o\",\n-\t\t\t       c_meta, elem->mode);\n+\t\t\tprintf(\"%s%snew file mode %06o\",\n+\t\t\t       line_prefix, c_meta, elem->mode);\n \t\telse {\n \t\t\tif (deleted)\n-\t\t\t\tprintf(\"%sdeleted file \", c_meta);\n+\t\t\t\tprintf(\"%s%sdeleted file \",\n+\t\t\t\t       line_prefix, c_meta);\n \t\t\tprintf(\"mode \");\n \t\t\tfor (i = 0; i < num_parent; i++) {\n \t\t\t\tprintf(\"%s%06o\", i ? \",\" : \"\",\n@@ -755,16 +761,16 @@ static void show_combined_header(struct combine_diff_path *elem,\n \n \tif (added)\n \t\tdump_quoted_path(\"--- \", \"\", \"/dev/null\",\n-\t\t\t\t c_meta, c_reset);\n+\t\t\t\t line_prefix, c_meta, c_reset);\n \telse\n \t\tdump_quoted_path(\"--- \", a_prefix, elem->path,\n-\t\t\t\t c_meta, c_reset);\n+\t\t\t\t line_prefix, c_meta, c_reset);\n \tif (deleted)\n \t\tdump_quoted_path(\"+++ \", \"\", \"/dev/null\",\n-\t\t\t\t c_meta, c_reset);\n+\t\t\t\t line_prefix, c_meta, c_reset);\n \telse\n \t\tdump_quoted_path(\"+++ \", b_prefix, elem->path,\n-\t\t\t\t c_meta, c_reset);\n+\t\t\t\t line_prefix, c_meta, c_reset);\n }\n \n static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n@@ -782,6 +788,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \tstruct userdiff_driver *userdiff;\n \tstruct userdiff_driver *textconv = NULL;\n \tint is_binary;\n+\tconst char *line_prefix = diff_line_prefix(opt);\n \n \tcontext = opt->context;\n \tuserdiff = userdiff_find_by_path(elem->path);\n@@ -901,7 +908,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t}\n \tif (is_binary) {\n \t\tshow_combined_header(elem, num_parent, dense, rev,\n-\t\t\t\t     mode_differs, 0);\n+\t\t\t\t     line_prefix, mode_differs, 0);\n \t\tprintf(\"Binary files differ\\n\");\n \t\tfree(result);\n \t\treturn;\n@@ -962,8 +969,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \n \tif (show_hunks || mode_differs || working_tree_file) {\n \t\tshow_combined_header(elem, num_parent, dense, rev,\n-\t\t\t\t     mode_differs, 1);\n-\t\tdump_sline(sline, cnt, num_parent,\n+\t\t\t\t     line_prefix, mode_differs, 1);\n+\t\tdump_sline(sline, line_prefix, cnt, num_parent,\n \t\t\t   opt->use_color, result_deleted);\n \t}\n \tfree(result);\n@@ -990,6 +997,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re\n \tint i, offset;\n \tconst char *prefix;\n \tint line_termination, inter_name_termination;\n+\tconst char *line_prefix = diff_line_prefix(opt);\n \n \tline_termination = opt->line_termination;\n \tinter_name_termination = '\\t';\n@@ -1000,6 +1008,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re\n \t\tshow_log(rev);\n \n \tif (opt->output_format & DIFF_FORMAT_RAW) {\n+\t\tprintf(\"%s\", line_prefix);\n \t\toffset = strlen(COLONS) - num_parent;\n \t\tif (offset < 0)\n \t\t\toffset = 0;\n@@ -1040,6 +1049,7 @@ void show_combined_diff(struct combine_diff_path *p,\n \t\t       struct rev_info *rev)\n {\n \tstruct diff_options *opt = &rev->diffopt;\n+\n \tif (!p->len)\n \t\treturn;\n \tif (opt->output_format & (DIFF_FORMAT_RAW |\n@@ -1150,8 +1160,10 @@ void diff_tree_combined(const unsigned char *sha1,\n \n \t\tif (show_log_first && i == 0) {\n \t\t\tshow_log(rev);\n+\n \t\t\tif (rev->verbose_header && opt->output_format)\n-\t\t\t\tputchar(opt->line_termination);\n+\t\t\t\tprintf(\"%s%c\", diff_line_prefix(opt),\n+\t\t\t\t       opt->line_termination);\n \t\t}\n \t\tdiff_flush(&diffopts);\n \t}\n@@ -1179,7 +1191,8 @@ void diff_tree_combined(const unsigned char *sha1,\n \n \t\tif (opt->output_format & DIFF_FORMAT_PATCH) {\n \t\t\tif (needsep)\n-\t\t\t\tputchar(opt->line_termination);\n+\t\t\t\tprintf(\"%s%c\", diff_line_prefix(opt),\n+\t\t\t\t       opt->line_termination);\n \t\t\tfor (p = paths; p; p = p->next) {\n \t\t\t\tif (p->len)\n \t\t\t\t\tshow_patch_diff(p, num_parent, dense,\n-- \n1.8.1.2\n"},{"id":"208950","messageId":"7v4nhn7sms.fsf@alter.siamese.dyndns.org","threadId":"32852","inReplyTo":"cover.1360267849.git.john@keeping.me.uk","subject":"Re: [PATCH 0/6] Improve \"git log --graph\" output of merges","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-07T20:53:31Z","receivedAt":"2013-02-07T20:53:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Keeping <john@keeping.me.uk> writes:\n\n> This series changes a couple of places that do not currently indent\n> their output when being shown with a graph.\n>\n> The first patch was already posted [1] and addresses the output of \"git\n> log --graph -c -p\".  Patch 2 is an independent fix I noticed while\n> working on the later patches.\n>\n> Patches 3-5 introduce a helper function and change existing sites using\n> diff_options->output_prefix to use it, resulting in a net reduction by\n> about 60 lines.  There is no functional change here.\n>\n> The final patch uses the helper introduced in patch 4 to make combined\n> diffs should the output prefix before each line.  This affects the\n> output of \"git log --graph --cc [-p|--raw]\".\n>\n> [1] http://article.gmane.org/gmane.comp.version-control.git/215630\n\nOverall direction looks sensible.\n\nIt is a bit scary that we are doing the the fifth one now, as\nopposed to catching this repetitiveness during the initial review of\npatch series that added the graph code to the diff codepath.\n\nThanks.\n\n> John Keeping (6):\n>   graph: output padding for merge subsequent parents\n>   diff: write prefix to the correct file\n>   diff.c: make constant string arguments const\n>   diff: add diff_line_prefix function\n>   diff.c: use diff_line_prefix() where applicable\n>   combine-diff.c: teach combined diffs about line prefix\n>\n>  combine-diff.c |  47 +++++++++++++--------\n>  diff.c         | 131 +++++++++++++++------------------------------------------\n>  diff.h         |   3 ++\n>  graph.c        |  10 +++++\n>  4 files changed, 77 insertions(+), 114 deletions(-)\n"},{"id":"209025","messageId":"20130208193026.GA1024@river","threadId":"32852","inReplyTo":"b98eb2bfe2b022ddf1afbe9f7123accfe068e8c9.1360267849.git.john@keeping.me.uk","subject":"Re: [PATCH 1/6] graph: output padding for merge subsequent parents","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-02-08T19:31:26Z","receivedAt":"2013-02-08T19:31:26Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"[Moved from the thread where this was initially posted to reply to the\nseries.]\n\nMatthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n> This works, but if we know we're not going to enter the while loop, it\n> seams even easier to do this:\n> \n> --- a/graph.c\n> +++ b/graph.c\n> @@ -1227,7 +1227,17 @@ void graph_show_commit(struct git_graph *graph)\n>         if (!graph)\n>                 return;\n>  \n> -       while (!shown_commit_line && !graph_is_commit_finished(graph)) {\n> +       /*\n> +        * When showing a diff of a merge against each of its parents, we\n> +        * are called once for each parent without graph_update having been\n> +        * called.  In this case, simply output a single padding line.\n> +        */\n> +       if (graph_is_commit_finished(graph)) {\n> +               graph_show_padding(graph);\n> +               return;\n> +       }\n> +\n> +       while (!shown_commit_line) {\n\nThis looks good to me.  I'll amend locally and re-send in a few days\nafter giving others a chance to comment.\n\n\nJohn\n"}]}