{"thread":{"id":"24143","subject":"[PATCH] Colorize commit decorations","startedAt":"2010-06-17T16:15:44Z","lastAt":"2010-06-24T00:21:16Z","messageCount":9,"participants":["Nazri Ramliy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"143876","messageId":"1276791344-25550-1-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":null,"subject":"[PATCH] Colorize commit decorations","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-17T16:15:44Z","receivedAt":"2010-06-17T16:15:44Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"Use different color for each type of refs (local, remote, tags, HEAD,\nand stash). This makes the decorations and their type stand out more\nand easier to distinguish in 'git log --decorate'.\n\nCurrently all the different types of decorations are shown in the same\ncolor as the commit id, which is not that easy to spot.\n\nThe color applied for each type of refs are customizable via\ncolor.log.decorate.<slot> config entry, as documented in\nDocumentation/config.txt.\n---\n Documentation/config.txt |    5 +++++\n builtin/log.c            |    2 ++\n commit.h                 |    1 +\n decorate.c               |   42 ++++++++++++++++++++++++++++++++++++++++++\n decorate.h               |   27 +++++++++++++++++++++++++++\n log-tree.c               |   39 +++++++++++++++++++++++++++++++--------\n 6 files changed, 108 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 95cf73c..afa4f5a 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -725,6 +725,11 @@ color.interactive.<slot>::\n \tcommands.  The values of these variables may be specified as\n \tin color.branch.<slot>.\n \n+color.log.decorate.<slot>::\n+\tUse customized color for 'git log --decorate' output.\n+\t`<slot>` is one of `local`, `remote`, `tag`, `stash` or `head`\n+\tfor local refs, remote refs, tags, stash and HEAD, respectively.\n+\n color.pager::\n \tA boolean to enable/disable colored output when the pager is in\n \tuse (default is true).\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 976e16f..bbc5d02 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -296,6 +296,8 @@ static int git_log_config(const char *var, const char *value, void *cb)\n \t\tdefault_show_root = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!prefixcmp(var, \"color.log.decorate.\"))\n+\t\treturn parse_decorate_color_config(var, 19, value);\n \treturn git_diff_ui_config(var, value, cb);\n }\n \ndiff --git a/commit.h b/commit.h\nindex 6ef88dc..a49cfe3 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -28,6 +28,7 @@ extern const char *commit_type;\n extern struct decoration name_decoration;\n struct name_decoration {\n \tstruct name_decoration *next;\n+\tenum decoration_type type;\n \tchar name[1];\n };\n \ndiff --git a/decorate.c b/decorate.c\nindex 2f8a63e..cbef2b4 100644\n--- a/decorate.c\n+++ b/decorate.c\n@@ -5,6 +5,48 @@\n #include \"cache.h\"\n #include \"object.h\"\n #include \"decorate.h\"\n+#include \"color.h\"\n+\n+static char decoration_colors[][COLOR_MAXLEN] = {\n+\tGIT_COLOR_RESET,\t/* DECORATION_NONE */\n+\tGIT_COLOR_BOLD_GREEN,\t/* DECORATION_REF_LOCAL */\n+\tGIT_COLOR_BOLD_RED,\t/* DECORATION_REF_REMOTE */\n+\tGIT_COLOR_BOLD_YELLOW,\t/* DECORATION_TAG */\n+\tGIT_COLOR_BOLD_MAGENTA,\t/* DECORATION_STASH */\n+\tGIT_COLOR_BOLD_CYAN\t/* DECORATION_HEAD */\n+};\n+\n+const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)\n+{\n+\tif (decorate_use_color) {\n+\t\treturn decoration_colors[ix];\n+\t}\n+\treturn \"\";\n+}\n+\n+static int parse_decorate_color_slot(const char *slot) {\n+\tif (!strcasecmp(slot, \"local\"))\n+\t\treturn COLOR_DECORATION_REF_LOCAL;\n+\tif (!strcasecmp(slot, \"remote\"))\n+\t\treturn COLOR_DECORATION_REF_REMOTE;\n+\tif (!strcasecmp(slot, \"tag\"))\n+\t\treturn COLOR_DECORATION_TAG;\n+\tif (!strcasecmp(slot, \"stash\"))\n+\t\treturn COLOR_DECORATION_STASH;\n+\tif (!strcasecmp(slot, \"head\"))\n+\t\treturn COLOR_DECORATION_HEAD;\n+\treturn -1;\n+}\n+\n+int parse_decorate_color_config(const char *var, const int ofs, const char *value) {\n+\tint slot = parse_decorate_color_slot(var + ofs);\n+\tif (slot < 0)\n+\t\treturn 0;\n+\tif (!value)\n+\t\treturn config_error_nonbool(var);\n+\tcolor_parse(value, var, decoration_colors[slot]);\n+\treturn 0;\n+}\n \n static unsigned int hash_obj(const struct object *obj, unsigned int n)\n {\ndiff --git a/decorate.h b/decorate.h\nindex e732804..d593d32 100644\n--- a/decorate.h\n+++ b/decorate.h\n@@ -12,6 +12,33 @@ struct decoration {\n \tstruct object_decoration *hash;\n };\n \n+enum decoration_type {\n+\tDECORATION_NONE = 0,\n+\tDECORATION_REF_LOCAL,\n+\tDECORATION_REF_REMOTE,\n+\tDECORATION_TAG,\n+\tDECORATION_STASH,\n+\tDECORATION_HEAD\n+};\n+\n+enum color_decoration {\n+\tCOLOR_DECORATION_RESET = 0,\n+\tCOLOR_DECORATION_REF_LOCAL,\n+\tCOLOR_DECORATION_REF_REMOTE,\n+\tCOLOR_DECORATION_TAG,\n+\tCOLOR_DECORATION_STASH,\n+\tCOLOR_DECORATION_HEAD\n+};\n+\n+const char *decorate_get_color(int diff_use_color, enum decoration_type ix);\n+\n+/*\n+ * log-tree.c uses DIFF_OPT_TST for determining whether to use color\n+ * for showing the commit sha1, use the same check for --decorate\n+ */\n+#define decorate_get_color_opt(o, ix) \\\n+\tdecorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)\n+\n extern void *add_decoration(struct decoration *n, const struct object *obj, void *decoration);\n extern void *lookup_decoration(struct decoration *n, const struct object *obj);\n \ndiff --git a/log-tree.c b/log-tree.c\nindex d3ae969..95ebf1a 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -10,29 +10,41 @@\n \n struct decoration name_decoration = { \"object names\" };\n \n-static void add_name_decoration(const char *prefix, const char *name, struct object *obj)\n+static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)\n {\n-\tint plen = strlen(prefix);\n \tint nlen = strlen(name);\n-\tstruct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);\n-\tmemcpy(res->name, prefix, plen);\n-\tmemcpy(res->name + plen, name, nlen + 1);\n+\tstruct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);\n+\tmemcpy(res->name, name, nlen + 1);\n+\tres->type = type;\n \tres->next = add_decoration(&name_decoration, obj, res);\n }\n \n static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)\n {\n \tstruct object *obj = parse_object(sha1);\n+\tenum decoration_type type = DECORATION_NONE;\n \tif (!obj)\n \t\treturn 0;\n+\n+\tif (!prefixcmp(refname, \"refs/heads\"))\n+\t\ttype = DECORATION_REF_LOCAL;\n+\telse if (!prefixcmp(refname, \"refs/remotes\"))\n+\t\ttype = DECORATION_REF_REMOTE;\n+\telse if (!prefixcmp(refname, \"refs/tags\"))\n+\t\ttype = DECORATION_TAG;\n+\telse if (!prefixcmp(refname, \"refs/stash\"))\n+\t\ttype = DECORATION_STASH;\n+\telse if (!prefixcmp(refname, \"HEAD\"))\n+\t\ttype = DECORATION_HEAD;\n+\n \tif (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)\n \t\trefname = prettify_refname(refname);\n-\tadd_name_decoration(\"\", refname, obj);\n+\tadd_name_decoration(type, refname, obj);\n \twhile (obj->type == OBJ_TAG) {\n \t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\tbreak;\n-\t\tadd_name_decoration(\"tag: \", refname, obj);\n+\t\tadd_name_decoration(DECORATION_TAG, refname, obj);\n \t}\n \treturn 0;\n }\n@@ -60,6 +72,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)\n {\n \tconst char *prefix;\n \tstruct name_decoration *decoration;\n+\tconst char *color_commit =\n+\t\tdiff_get_color_opt(&opt->diffopt, DIFF_COMMIT);\n+\tconst char *color_reset =\n+\t\tdecorate_get_color_opt(&opt->diffopt, DECORATION_NONE);\n \n \tif (opt->show_source && commit->util)\n \t\tprintf(\"\\t%s\", (char *) commit->util);\n@@ -70,7 +86,14 @@ void show_decorations(struct rev_info *opt, struct commit *commit)\n \t\treturn;\n \tprefix = \" (\";\n \twhile (decoration) {\n-\t\tprintf(\"%s%s\", prefix, decoration->name);\n+\t\tprintf(\"%s\", prefix);\n+\t\tfputs(decorate_get_color_opt(&opt->diffopt, decoration->type),\n+\t\t      stdout);\n+\t\tif (decoration->type == DECORATION_TAG)\n+\t\t\tfputs(\"tag: \", stdout);\n+\t\tprintf(\"%s\", decoration->name);\n+\t\tfputs(color_reset, stdout);\n+\t\tfputs(color_commit, stdout);\n \t\tprefix = \", \";\n \t\tdecoration = decoration->next;\n \t}\n-- \n1.7.1.245.g7c42e.dirty\n"},{"id":"143885","messageId":"7vtyp11k9x.fsf@alter.siamese.dyndns.org","threadId":"24143","inReplyTo":"1276791344-25550-1-git-send-email-ayiehere@gmail.com","subject":"Re: [PATCH] Colorize commit decorations","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-17T20:22:50Z","receivedAt":"2010-06-17T20:22:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nazri Ramliy <ayiehere@gmail.com> writes:\n\n> Use different color for each type of refs (local, remote, tags, HEAD,\n> and stash). This makes the decorations and their type stand out more\n> and easier to distinguish in 'git log --decorate'.\n>\n> Currently all the different types of decorations are shown in the same\n> color as the commit id, which is not that easy to spot.\n>\n> The color applied for each type of refs are customizable via\n> color.log.decorate.<slot> config entry, as documented in\n> Documentation/config.txt.\n> ---\n\nSign-off?\n\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index 95cf73c..afa4f5a 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -725,6 +725,11 @@ color.interactive.<slot>::\n>  \tcommands.  The values of these variables may be specified as\n>  \tin color.branch.<slot>.\n>  \n> +color.log.decorate.<slot>::\n> +\tUse customized color for 'git log --decorate' output.\n> +\t`<slot>` is one of `local`, `remote`, `tag`, `stash` or `head`\n> +\tfor local refs, remote refs, tags, stash and HEAD, respectively.\n\nConfiguration variable names are either 2-level or 3-level.  There are\nexisting examples for <slot> (e.g. color.branch.<slot>).\n\n> diff --git a/decorate.c b/decorate.c\n> index 2f8a63e..cbef2b4 100644\n> --- a/decorate.c\n> +++ b/decorate.c\n> @@ -5,6 +5,48 @@\n>  #include \"cache.h\"\n>  #include \"object.h\"\n>  #include \"decorate.h\"\n> +#include \"color.h\"\n> ...\n> +int parse_decorate_color_config(const char *var, const int ofs, const char *value) {\n> +\tint slot = parse_decorate_color_slot(var + ofs);\n> +\tif (slot < 0)\n> +\t\treturn 0;\n> +\tif (!value)\n> +\t\treturn config_error_nonbool(var);\n> +\tcolor_parse(value, var, decoration_colors[slot]);\n> +\treturn 0;\n> +}\n\nI don't think any of the above belongs to \"decorate.c\", which is the\ngeneric mechanism to annotate commits with arbitrary data.  The Porcelain\nfeature \"log --decorate\" is just one user that happens to use refname as\nthat \"arbitrary data\", and that is what you are coloring.  The code for\nthat is in log-tree.c, I think.\n\n> diff --git a/decorate.h b/decorate.h\n> index e732804..d593d32 100644\n\nSo is any change to this file.\n\n> diff --git a/log-tree.c b/log-tree.c\n> index d3ae969..95ebf1a 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -10,29 +10,41 @@\n>  \n>  struct decoration name_decoration = { \"object names\" };\n>  \n> -static void add_name_decoration(const char *prefix, const char *name, struct object *obj)\n> +static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)\n>  {\n> -\tint plen = strlen(prefix);\n>  \tint nlen = strlen(name);\n> -\tstruct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);\n> -\tmemcpy(res->name, prefix, plen);\n> -\tmemcpy(res->name + plen, name, nlen + 1);\n> +\tstruct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);\n> +\tmemcpy(res->name, name, nlen + 1);\n> +\tres->type = type;\n>  \tres->next = add_decoration(&name_decoration, obj, res);\n>  }\n\nWhen color is not in use (e.g. output is not going to the terminal), you\nwould lose \"tag: \" prefix, wouldn't you?\n\nEven when color _is_ in use, people may want to see familiar \"tag: \"\nprefix in the output---I personally do not think that is necessary,\nthough.\n\n>  static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)\n>  {\n>  \tstruct object *obj = parse_object(sha1);\n> +\tenum decoration_type type = DECORATION_NONE;\n>  \tif (!obj)\n>  \t\treturn 0;\n> +\n> +\tif (!prefixcmp(refname, \"refs/heads\"))\n> +\t\ttype = DECORATION_REF_LOCAL;\n> +\telse if (!prefixcmp(refname, \"refs/remotes\"))\n> +\t\ttype = DECORATION_REF_REMOTE;\n> +\telse if (!prefixcmp(refname, \"refs/tags\"))\n> +\t\ttype = DECORATION_TAG;\n> +\telse if (!prefixcmp(refname, \"refs/stash\"))\n> +\t\ttype = DECORATION_STASH;\n> +\telse if (!prefixcmp(refname, \"HEAD\"))\n> +\t\ttype = DECORATION_HEAD;\n\nI suspect that users would expect DECORATION_HEAD to be used to highlight\nthe object at the tip of the current branch, but I also suspect this code\nwould not do so.\n"},{"id":"143928","messageId":"1276911456-18466-1-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":"7vtyp11k9x.fsf@alter.siamese.dyndns.org","subject":"[PATCH 1/4] commit.h: add 'type' to struct name_decoration","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-19T01:37:33Z","receivedAt":"2010-06-19T01:37:33Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"This allows for semantically better handling of decoration type.\n\nSigned-off-by: Nazri Ramliy <ayiehere@gmail.com>\n---\nI have splitted the patch into four logical commits:\n\n      1. commit.h: add 'type' to struct name_decoration\n      2. log-tree.c: Use struct name_decoration's type for classifying decoration\n      3. log --decorate: Colorize commit decorations\n      4. Allow customizable coloring of commit decorations\n\nThis should make it easier for you (or anyone else)  to spot any problem with\nmy approach in colorizing --decorate stuff.\n\nThis is the first commit, and the rest will follow suit.\n\nMy reply to your comments are as follows:\n\nOn Fri, Jun 18, 2010 at 4:22 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Configuration variable names are either 2-level or 3-level.  There are\n> existing examples for <slot> (e.g. color.branch.<slot>).\n\nFixed. Now the slots are no longer tied to log, and they are named like\nthis:\n\n        color.decorate.reflocal\n        color.decorate.refremote\n        color.decorate.reftag\n        color.decorate.refstash\n        color.decorate.refhead\n\nThis should allow for handling different type of decorations in the\nfuture.\n\n> I don't think any of the above belongs to \"decorate.c\", which is the\n> generic mechanism to annotate commits with arbitrary data.  The Porcelain\n> feature \"log --decorate\" is just one user that happens to use refname as\n> that \"arbitrary data\", and that is what you are coloring.  The code for\n> that is in log-tree.c, I think.\n>\n>> diff --git a/decorate.h b/decorate.h\n>> index e732804..d593d32 100644\n>\n> So is any change to this file.\n\nFixed. decorate.[ch] is no longer affected by this series.\n\n> When color is not in use (e.g. output is not going to the terminal), you\n> would lose \"tag: \" prefix, wouldn't you?\n\nNo. The \"tag: \" prefix is not lost. It will be shown by show_decorations() if\nthe type of the decoration matches DECORATION_REF_TAG.\n\n>> +     else if (!prefixcmp(refname, \"refs/stash\"))\n>> +             type = DECORATION_STASH;\n>> +     else if (!prefixcmp(refname, \"HEAD\"))\n>> +             type = DECORATION_HEAD;\n>\n> I suspect that users would expect DECORATION_HEAD to be used to highlight\n> the object at the tip of the current branch, but I also suspect this code\n> would not do so.\n\nNo the code would not do so. It would only colorize the literal printed 'HEAD'\nstring. The current --decorate shows only 'HEAD' for symbolic refs (is this the\nright term for it?) and nothing else (it seems that way to me, I might be wrong\nhere).\n\nnazri\n\n commit.h |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/commit.h b/commit.h\nindex 6ef88dc..ba818fc 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -28,6 +28,7 @@ extern const char *commit_type;\n extern struct decoration name_decoration;\n struct name_decoration {\n \tstruct name_decoration *next;\n+\tint type;\n \tchar name[1];\n };\n \n-- \n1.7.1.245.g7c42e.dirty\n"},{"id":"143929","messageId":"1276911456-18466-2-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":"7vtyp11k9x.fsf@alter.siamese.dyndns.org","subject":"[PATCH 2/4] log-tree.c: Use struct name_decoration's type for classifying decoration","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-19T01:37:34Z","receivedAt":"2010-06-19T01:37:34Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"The \"tag: \" prefix is no longer prepended to the name of the decoration.\nIt is now printed conditionally by show_decorations if the decoration\ntype is DECORATION_REF_TAG.\n\nSigned-off-by: Nazri Ramliy <ayiehere@gmail.com>\n---\n log-tree.c |   40 ++++++++++++++++++++++++++++++++--------\n 1 files changed, 32 insertions(+), 8 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex d3ae969..2d804ee 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -10,29 +10,50 @@\n \n struct decoration name_decoration = { \"object names\" };\n \n-static void add_name_decoration(const char *prefix, const char *name, struct object *obj)\n+enum decoration_type {\n+\tDECORATION_NONE = 0,\n+\tDECORATION_REF_LOCAL,\n+\tDECORATION_REF_REMOTE,\n+\tDECORATION_REF_TAG,\n+\tDECORATION_REF_STASH,\n+\tDECORATION_REF_HEAD,\n+};\n+\n+static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)\n {\n-\tint plen = strlen(prefix);\n \tint nlen = strlen(name);\n-\tstruct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);\n-\tmemcpy(res->name, prefix, plen);\n-\tmemcpy(res->name + plen, name, nlen + 1);\n+\tstruct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);\n+\tmemcpy(res->name, name, nlen + 1);\n+\tres->type = type;\n \tres->next = add_decoration(&name_decoration, obj, res);\n }\n \n static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)\n {\n \tstruct object *obj = parse_object(sha1);\n+\tenum decoration_type type = DECORATION_NONE;\n \tif (!obj)\n \t\treturn 0;\n+\n+\tif (!prefixcmp(refname, \"refs/heads\"))\n+\t\ttype = DECORATION_REF_LOCAL;\n+\telse if (!prefixcmp(refname, \"refs/remotes\"))\n+\t\ttype = DECORATION_REF_REMOTE;\n+\telse if (!prefixcmp(refname, \"refs/tags\"))\n+\t\ttype = DECORATION_REF_TAG;\n+\telse if (!prefixcmp(refname, \"refs/stash\"))\n+\t\ttype = DECORATION_REF_STASH;\n+\telse if (!prefixcmp(refname, \"HEAD\"))\n+\t\ttype = DECORATION_REF_HEAD;\n+\n \tif (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)\n \t\trefname = prettify_refname(refname);\n-\tadd_name_decoration(\"\", refname, obj);\n+\tadd_name_decoration(type, refname, obj);\n \twhile (obj->type == OBJ_TAG) {\n \t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\tbreak;\n-\t\tadd_name_decoration(\"tag: \", refname, obj);\n+\t\tadd_name_decoration(DECORATION_REF_TAG, refname, obj);\n \t}\n \treturn 0;\n }\n@@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)\n \t\treturn;\n \tprefix = \" (\";\n \twhile (decoration) {\n-\t\tprintf(\"%s%s\", prefix, decoration->name);\n+\t\tprintf(\"%s\", prefix);\n+\t\tif (decoration->type == DECORATION_REF_TAG)\n+\t\t\tprintf(\"tag: \");\n+\t\tprintf(\"%s\", decoration->name);\n \t\tprefix = \", \";\n \t\tdecoration = decoration->next;\n \t}\n-- \n1.7.1.245.g7c42e.dirty\n"},{"id":"143930","messageId":"1276911456-18466-3-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":"7vtyp11k9x.fsf@alter.siamese.dyndns.org","subject":"[PATCH 3/4] log --decorate: Colorize commit decorations","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-19T01:37:35Z","receivedAt":"2010-06-19T01:37:35Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"This makes the decorations stand out more and easier to distinguish\nand spot because they are colored differently depending on their type.\n\nSigned-off-by: Nazri Ramliy <ayiehere@gmail.com>\n---\n log-tree.c |   34 +++++++++++++++++++++++++++++++++-\n 1 files changed, 33 insertions(+), 1 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 2d804ee..25586cf 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -7,6 +7,7 @@\n #include \"reflog-walk.h\"\n #include \"refs.h\"\n #include \"string-list.h\"\n+#include \"color.h\"\n \n struct decoration name_decoration = { \"object names\" };\n \n@@ -19,6 +20,29 @@ enum decoration_type {\n \tDECORATION_REF_HEAD,\n };\n \n+static char decoration_colors[][COLOR_MAXLEN] = {\n+\tGIT_COLOR_RESET,\n+\tGIT_COLOR_BOLD_GREEN,\t/* REF_LOCAL */\n+\tGIT_COLOR_BOLD_RED,\t/* REF_REMOTE */\n+\tGIT_COLOR_BOLD_YELLOW,\t/* REF_TAG */\n+\tGIT_COLOR_BOLD_MAGENTA,\t/* REF_STASH */\n+\tGIT_COLOR_BOLD_CYAN,\t/* REF_HEAD */\n+};\n+\n+static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)\n+{\n+\tif (decorate_use_color)\n+\t\treturn decoration_colors[ix];\n+\treturn \"\";\n+}\n+\n+/*\n+ * log-tree.c uses DIFF_OPT_TST for determining whether to use color\n+ * for showing the commit sha1, use the same check for --decorate\n+ */\n+#define decorate_get_color_opt(o, ix) \\\n+\tdecorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)\n+\n static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)\n {\n \tint nlen = strlen(name);\n@@ -81,6 +105,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)\n {\n \tconst char *prefix;\n \tstruct name_decoration *decoration;\n+\tconst char *color_commit =\n+\t\tdiff_get_color_opt(&opt->diffopt, DIFF_COMMIT);\n+\tconst char *color_reset =\n+\t\tdecorate_get_color_opt(&opt->diffopt, DECORATION_NONE);\n \n \tif (opt->show_source && commit->util)\n \t\tprintf(\"\\t%s\", (char *) commit->util);\n@@ -92,9 +120,13 @@ void show_decorations(struct rev_info *opt, struct commit *commit)\n \tprefix = \" (\";\n \twhile (decoration) {\n \t\tprintf(\"%s\", prefix);\n+\t\tfputs(decorate_get_color_opt(&opt->diffopt, decoration->type),\n+\t\t      stdout);\n \t\tif (decoration->type == DECORATION_REF_TAG)\n-\t\t\tprintf(\"tag: \");\n+\t\t\tfputs(\"tag: \", stdout);\n \t\tprintf(\"%s\", decoration->name);\n+\t\tfputs(color_reset, stdout);\n+\t\tfputs(color_commit, stdout);\n \t\tprefix = \", \";\n \t\tdecoration = decoration->next;\n \t}\n-- \n1.7.1.245.g7c42e.dirty\n"},{"id":"143931","messageId":"1276911456-18466-4-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":"7vtyp11k9x.fsf@alter.siamese.dyndns.org","subject":"[PATCH 4/4] Allow customizable coloring of commit decorations","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-19T01:37:36Z","receivedAt":"2010-06-19T01:37:36Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>\n---\n Documentation/config.txt |    6 ++++++\n builtin/log.c            |    3 +++\n log-tree.c               |   24 ++++++++++++++++++++++++\n log-tree.h               |    1 +\n 4 files changed, 34 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 95cf73c..b3e80c1 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -683,6 +683,12 @@ color.diff.<slot>::\n \t(highlighting whitespace errors). The values of these variables may be\n \tspecified as in color.branch.<slot>.\n \n+color.decorate.<slot>::\n+\tUse customized color for 'git log --decorate' output.\n+\t`<slot>` is one of `reflocal`, `refremote`, `reftag`, `refstash` or\n+\t`refhead` for local refs, remote refs, tags, stash and HEAD,\n+\trespectively.\n+\n color.grep::\n \tWhen set to `always`, always highlight matches.  When `false` (or\n \t`never`), never.  When set to `true` or `auto`, use color only\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 976e16f..0835866 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb)\n \t\tdefault_show_root = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!prefixcmp(var, \"color.decorate.\"))\n+\t\treturn parse_decorate_color_config(var, 15, value);\n+\n \treturn git_diff_ui_config(var, value, cb);\n }\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 25586cf..0265228 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -36,6 +36,30 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty\n \treturn \"\";\n }\n \n+static int parse_decorate_color_slot(const char *slot) {\n+\tif (!strcasecmp(slot, \"reflocal\"))\n+\t\treturn DECORATION_REF_LOCAL;\n+\tif (!strcasecmp(slot, \"refremote\"))\n+\t\treturn DECORATION_REF_REMOTE;\n+\tif (!strcasecmp(slot, \"reftag\"))\n+\t\treturn DECORATION_REF_TAG;\n+\tif (!strcasecmp(slot, \"refstash\"))\n+\t\treturn DECORATION_REF_STASH;\n+\tif (!strcasecmp(slot, \"refhead\"))\n+\t\treturn DECORATION_REF_HEAD;\n+\treturn -1;\n+}\n+\n+int parse_decorate_color_config(const char *var, const int ofs, const char *value) {\n+\tint slot = parse_decorate_color_slot(var + ofs);\n+\tif (slot < 0)\n+\t\treturn 0;\n+\tif (!value)\n+\t\treturn config_error_nonbool(var);\n+\tcolor_parse(value, var, decoration_colors[slot]);\n+\treturn 0;\n+}\n+\n /*\n  * log-tree.c uses DIFF_OPT_TST for determining whether to use color\n  * for showing the commit sha1, use the same check for --decorate\ndiff --git a/log-tree.h b/log-tree.h\nindex 3f7b400..5c4cf7c 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -7,6 +7,7 @@ struct log_info {\n \tstruct commit *commit, *parent;\n };\n \n+int parse_decorate_color_config(const char *var, const int ofs, const char *value);\n void init_log_tree_opt(struct rev_info *);\n int log_tree_diff_flush(struct rev_info *);\n int log_tree_commit(struct rev_info *, struct commit *);\n-- \n1.7.1.245.g7c42e.dirty\n"},{"id":"144023","messageId":"7vhbkvg1bd.fsf@alter.siamese.dyndns.org","threadId":"24143","inReplyTo":"1276911456-18466-1-git-send-email-ayiehere@gmail.com","subject":"Re: [PATCH 1/4] commit.h: add 'type' to struct name_decoration","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-22T04:04:38Z","receivedAt":"2010-06-22T04:04:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nazri Ramliy <ayiehere@gmail.com> writes:\n\n> Now the slots are no longer tied to log, and they are named like\n> this:\n>\n>         color.decorate.reflocal\n>         color.decorate.refremote\n\nWouldn't \"(local) branch\" and \"remote (tracking) branch\" be more natural\nway to call these things?\n\n>         color.decorate.reftag\n>         color.decorate.refstash\n>         color.decorate.refhead\n\nAnd these would just be \"tag\", \"stash\" and \"head\".\n"},{"id":"144056","messageId":"1277253782-3330-1-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":"7vhbkvg1bd.fsf@alter.siamese.dyndns.org","subject":"[PATCH] Allow customizable commit decorations colors","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-23T00:43:02Z","receivedAt":"2010-06-23T00:43:02Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>\n---\nOn Tue, Jun 22, 2010 at 12:04 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Nazri Ramliy <ayiehere@gmail.com> writes:\n>>         color.decorate.reflocal\n>>         color.decorate.refremote\n>\n> Wouldn't \"(local) branch\" and \"remote (tracking) branch\" be more natural\n> way to call these things?\n>\n>>         color.decorate.reftag\n>>         color.decorate.refstash\n>>         color.decorate.refhead\n>\n> And these would just be \"tag\", \"stash\" and \"head\".\n\nMakes sense. The names above are not user friendly. The new names are:\n\n\tcolor.decorate.branch\n\tcolor.decorate.remoteBranch\n\tcolor.decorate.tag\n\tcolor.decorate.stash\n\tcolor.decorate.HEAD\n\nDocumentation/config.txt explains how 'branch' and 'remoteBranch' are for local\nbranches and remote tracking branches, respectively.  Also the config entries\nare shown as if the case matters while in fact it does not. But I think it\nhelps readability and at the same time it disambiguates 'head' vs. 'HEAD'.\n\nThis is to be applied on top of 67a4b5864f9423ccfe8090365029dae918504830:\n\"log --decorate: Colorize commit decorations\" in pu.\n\nLet me know if you want me to send the whole series again (4 patches).\n\n Documentation/config.txt |    5 +++++\n builtin/log.c            |    3 +++\n log-tree.c               |   34 ++++++++++++++++++++++++++++++++++\n log-tree.h               |    1 +\n 4 files changed, 43 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 7afd0a3..89cb487 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -683,6 +683,11 @@ color.diff.<slot>::\n \t(highlighting whitespace errors). The values of these variables may be\n \tspecified as in color.branch.<slot>.\n \n+color.decorate.<slot>::\n+\tUse customized color for 'git log --decorate' output.  `<slot>` is one\n+\tof `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local\n+\tbranches, remote tracking branches, tags, stash and HEAD, respectively.\n+\n color.grep::\n \tWhen set to `always`, always highlight matches.  When `false` (or\n \t`never`), never.  When set to `true` or `auto`, use color only\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 976e16f..0835866 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb)\n \t\tdefault_show_root = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!prefixcmp(var, \"color.decorate.\"))\n+\t\treturn parse_decorate_color_config(var, 15, value);\n+\n \treturn git_diff_ui_config(var, value, cb);\n }\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 61680f4..28280e9 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -36,6 +36,40 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty\n \treturn \"\";\n }\n \n+static int parse_decorate_color_slot(const char *slot) {\n+\t/*\n+\t * We're comparing with 'ignore-case' on\n+\t * (because config.c sets them all tolower),\n+\t * but let's match the letters in the literal\n+\t * string values here with how they are\n+\t * documented in Documentation/config.txt, for\n+\t * consistency.\n+\t *\n+\t * We love being consistent, don't we?\n+\t */\n+\tif (!strcasecmp(slot, \"branch\"))\n+\t\treturn DECORATION_REF_LOCAL;\n+\tif (!strcasecmp(slot, \"remoteBranch\"))\n+\t\treturn DECORATION_REF_REMOTE;\n+\tif (!strcasecmp(slot, \"tag\"))\n+\t\treturn DECORATION_REF_TAG;\n+\tif (!strcasecmp(slot, \"stash\"))\n+\t\treturn DECORATION_REF_STASH;\n+\tif (!strcasecmp(slot, \"HEAD\"))\n+\t\treturn DECORATION_REF_HEAD;\n+\treturn -1;\n+}\n+\n+int parse_decorate_color_config(const char *var, const int ofs, const char *value) {\n+\tint slot = parse_decorate_color_slot(var + ofs);\n+\tif (slot < 0)\n+\t\treturn 0;\n+\tif (!value)\n+\t\treturn config_error_nonbool(var);\n+\tcolor_parse(value, var, decoration_colors[slot]);\n+\treturn 0;\n+}\n+\n /*\n  * log-tree.c uses DIFF_OPT_TST for determining whether to use color\n  * for showing the commit sha1, use the same check for --decorate\ndiff --git a/log-tree.h b/log-tree.h\nindex 3f7b400..5c4cf7c 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -7,6 +7,7 @@ struct log_info {\n \tstruct commit *commit, *parent;\n };\n \n+int parse_decorate_color_config(const char *var, const int ofs, const char *value);\n void init_log_tree_opt(struct rev_info *);\n int log_tree_diff_flush(struct rev_info *);\n int log_tree_commit(struct rev_info *, struct commit *);\n-- \n1.7.1.245.g7c42e.dirty\n"},{"id":"144116","messageId":"1277338876-21958-1-git-send-email-ayiehere@gmail.com","threadId":"24143","inReplyTo":"1277253782-3330-1-git-send-email-ayiehere@gmail.com","subject":"[PATCH] Allow customizable commit decorations colors","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-06-24T00:21:16Z","receivedAt":"2010-06-24T00:21:16Z","isPatch":true,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>\n---\nApologies for not catching this earlier.\n\nMy earlier version of this patch \"Allow customizable commit decorations colors\"\n(message id: 1277253782-3330-1-git-send-email-ayiehere@gmail.com) has a bad\nstyle for the opening braces in the functions parse_decorate_color_slot() and\nparse_decorate_color_config() - the opening braces for these two functions were\nat the same line as the function head.\n\nThis patch fixes these style violations (replaces\n4938f6c98e4a6c4484bf652bdb887f0b8d8be822 in pu).\n\nnazri.\n\n Documentation/config.txt |    5 +++++\n builtin/log.c            |    3 +++\n log-tree.c               |   36 ++++++++++++++++++++++++++++++++++++\n log-tree.h               |    1 +\n 4 files changed, 45 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 7afd0a3..89cb487 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -683,6 +683,11 @@ color.diff.<slot>::\n \t(highlighting whitespace errors). The values of these variables may be\n \tspecified as in color.branch.<slot>.\n \n+color.decorate.<slot>::\n+\tUse customized color for 'git log --decorate' output.  `<slot>` is one\n+\tof `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local\n+\tbranches, remote tracking branches, tags, stash and HEAD, respectively.\n+\n color.grep::\n \tWhen set to `always`, always highlight matches.  When `false` (or\n \t`never`), never.  When set to `true` or `auto`, use color only\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 976e16f..0835866 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -296,6 +296,9 @@ static int git_log_config(const char *var, const char *value, void *cb)\n \t\tdefault_show_root = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!prefixcmp(var, \"color.decorate.\"))\n+\t\treturn parse_decorate_color_config(var, 15, value);\n+\n \treturn git_diff_ui_config(var, value, cb);\n }\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 61680f4..b46ed3b 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -36,6 +36,42 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty\n \treturn \"\";\n }\n \n+static int parse_decorate_color_slot(const char *slot)\n+{\n+\t/*\n+\t * We're comparing with 'ignore-case' on\n+\t * (because config.c sets them all tolower),\n+\t * but let's match the letters in the literal\n+\t * string values here with how they are\n+\t * documented in Documentation/config.txt, for\n+\t * consistency.\n+\t *\n+\t * We love being consistent, don't we?\n+\t */\n+\tif (!strcasecmp(slot, \"branch\"))\n+\t\treturn DECORATION_REF_LOCAL;\n+\tif (!strcasecmp(slot, \"remoteBranch\"))\n+\t\treturn DECORATION_REF_REMOTE;\n+\tif (!strcasecmp(slot, \"tag\"))\n+\t\treturn DECORATION_REF_TAG;\n+\tif (!strcasecmp(slot, \"stash\"))\n+\t\treturn DECORATION_REF_STASH;\n+\tif (!strcasecmp(slot, \"HEAD\"))\n+\t\treturn DECORATION_REF_HEAD;\n+\treturn -1;\n+}\n+\n+int parse_decorate_color_config(const char *var, const int ofs, const char *value)\n+{\n+\tint slot = parse_decorate_color_slot(var + ofs);\n+\tif (slot < 0)\n+\t\treturn 0;\n+\tif (!value)\n+\t\treturn config_error_nonbool(var);\n+\tcolor_parse(value, var, decoration_colors[slot]);\n+\treturn 0;\n+}\n+\n /*\n  * log-tree.c uses DIFF_OPT_TST for determining whether to use color\n  * for showing the commit sha1, use the same check for --decorate\ndiff --git a/log-tree.h b/log-tree.h\nindex 3f7b400..5c4cf7c 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -7,6 +7,7 @@ struct log_info {\n \tstruct commit *commit, *parent;\n };\n \n+int parse_decorate_color_config(const char *var, const int ofs, const char *value);\n void init_log_tree_opt(struct rev_info *);\n int log_tree_diff_flush(struct rev_info *);\n int log_tree_commit(struct rev_info *, struct commit *);\n-- \n1.7.1.245.g7c42e.dirty\n"}]}