{"thread":{"id":"5192","subject":"[PATCH] combine-diff: use color","startedAt":"2006-08-10T07:31:47Z","lastAt":"2006-08-10T07:31:47Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"25065","messageId":"7v64h1xd0c.fsf@assigned-by-dhcp.cox.net","threadId":"5192","inReplyTo":null,"subject":"[PATCH] combine-diff: use color","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-10T07:31:47Z","receivedAt":"2006-08-10T07:31:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Using the same mechanism as the regular diffs, color combined diff\noutput.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * I do not use color myself, but I thought this would be good\n   for consistency's sake...\n\n combine-diff.c |   50 ++++++++++++++++++++++++++++++++++----------------\n 1 files changed, 34 insertions(+), 16 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 919112b..ba8baca 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -497,11 +497,17 @@ static void show_parent_lno(struct sline\n \tprintf(\" -%lu,%lu\", l0, l1-l0);\n }\n \n-static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)\n+static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n+\t\t       int use_color)\n {\n \tunsigned long mark = (1UL<<num_parent);\n \tint i;\n \tunsigned long lno = 0;\n+\tconst char *c_frag = diff_get_color(use_color, DIFF_FRAGINFO);\n+\tconst char *c_new = diff_get_color(use_color, DIFF_FILE_NEW);\n+\tconst char *c_old = diff_get_color(use_color, DIFF_FILE_OLD);\n+\tconst char *c_plain = diff_get_color(use_color, DIFF_PLAIN);\n+\tconst char *c_reset = diff_get_color(use_color, DIFF_RESET);\n \n \tif (!cnt)\n \t\treturn; /* result deleted */\n@@ -522,12 +528,13 @@ static void dump_sline(struct sline *sli\n \t\trlines = hunk_end - lno;\n \t\tif (cnt < hunk_end)\n \t\t\trlines--; /* pointing at the last delete hunk */\n+\t\tfputs(c_frag, stdout);\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);\n \t\tprintf(\" +%lu,%lu \", lno+1, rlines);\n \t\tfor (i = 0; i <= num_parent; i++) putchar(combine_marker);\n-\t\tputchar('\\n');\n+\t\tprintf(\"%s\\n\", c_reset);\n \t\twhile (lno < hunk_end) {\n \t\t\tstruct lline *ll;\n \t\t\tint j;\n@@ -535,18 +542,23 @@ static void dump_sline(struct sline *sli\n \t\t\tsl = &sline[lno++];\n \t\t\tll = sl->lost_head;\n \t\t\twhile (ll) {\n+\t\t\t\tfputs(c_old, stdout);\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 \t\t\t\t\telse\n \t\t\t\t\t\tputchar(' ');\n \t\t\t\t}\n-\t\t\t\tputs(ll->line);\n+\t\t\t\tprintf(\"%s%s\\n\", ll->line, c_reset);\n \t\t\t\tll = ll->next;\n \t\t\t}\n \t\t\tif (cnt < lno)\n \t\t\t\tbreak;\n \t\t\tp_mask = 1;\n+\t\t\tif (!(sl->flag & (mark-1)))\n+\t\t\t\tfputs(c_plain, stdout);\n+\t\t\telse\n+\t\t\t\tfputs(c_new, stdout);\n \t\t\tfor (j = 0; j < num_parent; j++) {\n \t\t\t\tif (p_mask & sl->flag)\n \t\t\t\t\tputchar('+');\n@@ -554,7 +566,7 @@ static void dump_sline(struct sline *sli\n \t\t\t\t\tputchar(' ');\n \t\t\t\tp_mask <<= 1;\n \t\t\t}\n-\t\t\tprintf(\"%.*s\\n\", sl->len, sl->bol);\n+\t\t\tprintf(\"%.*s%s\\n\", sl->len, sl->bol, c_reset);\n \t\t}\n \t}\n }\n@@ -586,14 +598,15 @@ static void reuse_combine_diff(struct sl\n \tsline->p_lno[i] = sline->p_lno[j];\n }\n \n-static void dump_quoted_path(const char *prefix, const char *path)\n+static void dump_quoted_path(const char *prefix, const char *path,\n+\t\t\t     const char *c_meta, const char *c_reset)\n {\n-\tfputs(prefix, stdout);\n+\tprintf(\"%s%s\", c_meta, prefix);\n \tif (quote_c_style(path, NULL, NULL, 0))\n \t\tquote_c_style(path, NULL, stdout, 0);\n \telse\n \t\tprintf(\"%s\", path);\n-\tputchar('\\n');\n+\tprintf(\"%s\\n\", c_reset);\n }\n \n static int show_patch_diff(struct combine_diff_path *elem, int num_parent,\n@@ -699,18 +712,22 @@ static int show_patch_diff(struct combin\n \n \tif (show_hunks || mode_differs || working_tree_file) {\n \t\tconst char *abb;\n+\t\tint use_color = opt->color_diff;\n+\t\tconst char *c_meta = diff_get_color(use_color, DIFF_METAINFO);\n+\t\tconst char *c_reset = diff_get_color(use_color, DIFF_RESET);\n \n \t\tif (rev->loginfo)\n \t\t\tshow_log(rev, opt->msg_sep);\n-\t\tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \", elem->path);\n-\t\tprintf(\"index \");\n+\t\tdump_quoted_path(dense ? \"diff --cc \" : \"diff --combined \",\n+\t\t\t\t elem->path, c_meta, c_reset);\n+\t\tprintf(\"%sindex \", c_meta);\n \t\tfor (i = 0; i < num_parent; i++) {\n \t\t\tabb = find_unique_abbrev(elem->parent[i].sha1,\n \t\t\t\t\t\t abbrev);\n \t\t\tprintf(\"%s%s\", i ? \",\" : \"\", abb);\n \t\t}\n \t\tabb = find_unique_abbrev(elem->sha1, abbrev);\n-\t\tprintf(\"..%s\\n\", abb);\n+\t\tprintf(\"..%s%s\\n\", abb, c_reset);\n \n \t\tif (mode_differs) {\n \t\t\tint added = !!elem->mode;\n@@ -719,10 +736,11 @@ static int show_patch_diff(struct combin\n \t\t\t\t    DIFF_STATUS_ADDED)\n \t\t\t\t\tadded = 0;\n \t\t\tif (added)\n-\t\t\t\tprintf(\"new file mode %06o\", elem->mode);\n+\t\t\t\tprintf(\"%snew file mode %06o\",\n+\t\t\t\t       c_meta, elem->mode);\n \t\t\telse {\n \t\t\t\tif (!elem->mode)\n-\t\t\t\t\tprintf(\"deleted file \");\n+\t\t\t\t\tprintf(\"%sdeleted file \", c_meta);\n \t\t\t\tprintf(\"mode \");\n \t\t\t\tfor (i = 0; i < num_parent; i++) {\n \t\t\t\t\tprintf(\"%s%06o\", i ? \",\" : \"\",\n@@ -731,11 +749,11 @@ static int show_patch_diff(struct combin\n \t\t\t\tif (elem->mode)\n \t\t\t\t\tprintf(\"..%06o\", elem->mode);\n \t\t\t}\n-\t\t\tputchar('\\n');\n+\t\t\tprintf(\"%s\\n\", c_reset);\n \t\t}\n-\t\tdump_quoted_path(\"--- a/\", elem->path);\n-\t\tdump_quoted_path(\"+++ b/\", elem->path);\n-\t\tdump_sline(sline, cnt, num_parent);\n+\t\tdump_quoted_path(\"--- a/\", elem->path, c_meta, c_reset);\n+\t\tdump_quoted_path(\"+++ b/\", elem->path, c_meta, c_reset);\n+\t\tdump_sline(sline, cnt, num_parent, opt->color_diff);\n \t}\n \tfree(result);\n \n-- \n1.4.2.rc4.gcdaa\n"}]}