]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pass config slots as pointers instead of offsets
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 7 Oct 2014 19:16:57 +0000 (15:16 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Oct 2014 18:01:05 +0000 (11:01 -0700)
Many config-parsing helpers, like parse_branch_color_slot,
take the name of a config variable and an offset to the
"slot" name (e.g., "color.branch.plain" is passed along with
"13" to effectively pass "plain"). This is leftover from the
time that these functions would die() on error, and would
want the full variable name for error reporting.

These days they do not use the full variable name at all.
Passing a single pointer to the slot name is more natural,
and lets us more easily adjust the callers to use skip_prefix
to avoid manually writing offset numbers.

This is effectively a continuation of 9e1a5eb, which did the
same for parse_diff_color_slot. This patch covers all of the
remaining similar constructs.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
builtin/commit.c
builtin/log.c
log-tree.c
log-tree.h

index 0591b22a483619ac9a7d889a49e45ffa9d68ab72..b2e1895ca92ec2037349d88b945ba64ebf16d62d 100644 (file)
@@ -62,19 +62,19 @@ static unsigned char merge_filter_ref[20];
 static struct string_list output = STRING_LIST_INIT_DUP;
 static unsigned int colopts;
 
-static int parse_branch_color_slot(const char *var, int ofs)
+static int parse_branch_color_slot(const char *slot)
 {
-       if (!strcasecmp(var+ofs, "plain"))
+       if (!strcasecmp(slot, "plain"))
                return BRANCH_COLOR_PLAIN;
-       if (!strcasecmp(var+ofs, "reset"))
+       if (!strcasecmp(slot, "reset"))
                return BRANCH_COLOR_RESET;
-       if (!strcasecmp(var+ofs, "remote"))
+       if (!strcasecmp(slot, "remote"))
                return BRANCH_COLOR_REMOTE;
-       if (!strcasecmp(var+ofs, "local"))
+       if (!strcasecmp(slot, "local"))
                return BRANCH_COLOR_LOCAL;
-       if (!strcasecmp(var+ofs, "current"))
+       if (!strcasecmp(slot, "current"))
                return BRANCH_COLOR_CURRENT;
-       if (!strcasecmp(var+ofs, "upstream"))
+       if (!strcasecmp(slot, "upstream"))
                return BRANCH_COLOR_UPSTREAM;
        return -1;
 }
@@ -88,7 +88,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (starts_with(var, "color.branch.")) {
-               int slot = parse_branch_color_slot(var, 13);
+               int slot = parse_branch_color_slot(var + 13);
                if (slot < 0)
                        return 0;
                if (!value)
index 5ed60364ce5eb1f458e1f5155d76abd7341d24ea..5a8a29e07534237aee822cdee26f7c7f6a612c02 100644 (file)
@@ -1238,22 +1238,21 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
        return commitable ? 0 : 1;
 }
 
-static int parse_status_slot(const char *var, int offset)
+static int parse_status_slot(const char *slot)
 {
-       if (!strcasecmp(var+offset, "header"))
+       if (!strcasecmp(slot, "header"))
                return WT_STATUS_HEADER;
-       if (!strcasecmp(var+offset, "branch"))
+       if (!strcasecmp(slot, "branch"))
                return WT_STATUS_ONBRANCH;
-       if (!strcasecmp(var+offset, "updated")
-               || !strcasecmp(var+offset, "added"))
+       if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added"))
                return WT_STATUS_UPDATED;
-       if (!strcasecmp(var+offset, "changed"))
+       if (!strcasecmp(slot, "changed"))
                return WT_STATUS_CHANGED;
-       if (!strcasecmp(var+offset, "untracked"))
+       if (!strcasecmp(slot, "untracked"))
                return WT_STATUS_UNTRACKED;
-       if (!strcasecmp(var+offset, "nobranch"))
+       if (!strcasecmp(slot, "nobranch"))
                return WT_STATUS_NOBRANCH;
-       if (!strcasecmp(var+offset, "unmerged"))
+       if (!strcasecmp(slot, "unmerged"))
                return WT_STATUS_UNMERGED;
        return -1;
 }
@@ -1291,7 +1290,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
                return 0;
        }
        if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) {
-               int slot = parse_status_slot(k, 13);
+               int slot = parse_status_slot(k + 13);
                if (slot < 0)
                        return 0;
                if (!v)
index 4389722b4b1edffce8cd2a63dae52277e022ac99..4c5fc4bff5b955f712024a935b8b804fd7d5e363 100644 (file)
@@ -389,7 +389,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (starts_with(var, "color.decorate."))
-               return parse_decorate_color_config(var, 15, value);
+               return parse_decorate_color_config(var, var + 15, value);
        if (!strcmp(var, "log.mailmap")) {
                use_mailmap_config = git_config_bool(var, value);
                return 0;
index 95e9b1da259ef33a1c5bc7f7d07e853ebc5dbcec..479b1d2a5b51fec78706467ac8dc0821d018478c 100644 (file)
@@ -66,9 +66,9 @@ static int parse_decorate_color_slot(const char *slot)
        return -1;
 }
 
-int parse_decorate_color_config(const char *var, const int ofs, const char *value)
+int parse_decorate_color_config(const char *var, const char *slot_name, const char *value)
 {
-       int slot = parse_decorate_color_slot(var + ofs);
+       int slot = parse_decorate_color_slot(slot_name);
        if (slot < 0)
                return 0;
        if (!value)
index d6ecd4dc46b82147c5c7e00dcfa2e9088ab00d7c..8cbefac573242cc6e1bfec100a3cb5e931a6e5c7 100644 (file)
@@ -7,7 +7,7 @@ struct log_info {
        struct commit *commit, *parent;
 };
 
-int parse_decorate_color_config(const char *var, const int ofs, const char *value);
+int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);
 void init_log_tree_opt(struct rev_info *);
 int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);