Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-26 16:55:21 +0300
committerJunio C Hamano <gitster@pobox.com>2018-05-29 08:51:28 +0300
commita73b3680c4910866e3e215c3927a0c71f0b9229d (patch)
tree4c48aca0f71bba28888b19f3dec47088334ea7d1 /log-tree.c
parent17b3e5150506281fd2d675c150cf1e71f914ad54 (diff)
Add and use generic name->id mapping code for color slot parsing
Instead of hard coding the name-to-id mapping in C code, keep it in an array and use a common function to do the parsing. This reduces code and also allows us to list all possible color slots later. This starts using C99 designated initializers more for convenience (the first designated initializers have been introduced in builtin/clean.c for some time without complaints) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'log-tree.c')
-rw-r--r--log-tree.c35
1 files changed, 9 insertions, 26 deletions
diff --git a/log-tree.c b/log-tree.c
index 724bae0de2..d85e179077 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -27,6 +27,14 @@ static char decoration_colors[][COLOR_MAXLEN] = {
GIT_COLOR_BOLD_BLUE, /* GRAFTED */
};
+static const char *color_decorate_slots[] = {
+ [DECORATION_REF_LOCAL] = "branch",
+ [DECORATION_REF_REMOTE] = "remoteBranch",
+ [DECORATION_REF_TAG] = "tag",
+ [DECORATION_REF_STASH] = "stash",
+ [DECORATION_REF_HEAD] = "HEAD",
+};
+
static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
{
if (want_color(decorate_use_color))
@@ -34,34 +42,9 @@ static const char *decorate_get_color(int decorate_use_color, enum decoration_ty
return "";
}
-static int parse_decorate_color_slot(const char *slot)
-{
- /*
- * We're comparing with 'ignore-case' on
- * (because config.c sets them all tolower),
- * but let's match the letters in the literal
- * string values here with how they are
- * documented in Documentation/config.txt, for
- * consistency.
- *
- * We love being consistent, don't we?
- */
- if (!strcasecmp(slot, "branch"))
- return DECORATION_REF_LOCAL;
- if (!strcasecmp(slot, "remoteBranch"))
- return DECORATION_REF_REMOTE;
- if (!strcasecmp(slot, "tag"))
- return DECORATION_REF_TAG;
- if (!strcasecmp(slot, "stash"))
- return DECORATION_REF_STASH;
- if (!strcasecmp(slot, "HEAD"))
- return DECORATION_REF_HEAD;
- return -1;
-}
-
int parse_decorate_color_config(const char *var, const char *slot_name, const char *value)
{
- int slot = parse_decorate_color_slot(slot_name);
+ int slot = LOOKUP_CONFIG(color_decorate_slots, slot_name);
if (slot < 0)
return 0;
if (!value)