pass config slots as pointers instead of offsets

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>

Jonathan Nieder committed Oct 7, 2014 at 15:16 UTC 8852117a603c5ed5131233a80453db37c0958871
5 files changed +21 -22
builtin/branch.c
+8 -8
@@ -62,19 +62,19 @@ static unsigned char merge_filter_ref[20];
62 static struct string_list output = STRING_LIST_INIT_DUP;
63 static unsigned int colopts;
64
65 -static int parse_branch_color_slot(const char *var, int ofs)
65 +static int parse_branch_color_slot(const char *slot)
66 {
67 - if (!strcasecmp(var+ofs, "plain"))
67 + if (!strcasecmp(slot, "plain"))
68 return BRANCH_COLOR_PLAIN;
69 - if (!strcasecmp(var+ofs, "reset"))
69 + if (!strcasecmp(slot, "reset"))
70 return BRANCH_COLOR_RESET;
71 - if (!strcasecmp(var+ofs, "remote"))
71 + if (!strcasecmp(slot, "remote"))
72 return BRANCH_COLOR_REMOTE;
73 - if (!strcasecmp(var+ofs, "local"))
73 + if (!strcasecmp(slot, "local"))
74 return BRANCH_COLOR_LOCAL;
75 - if (!strcasecmp(var+ofs, "current"))
75 + if (!strcasecmp(slot, "current"))
76 return BRANCH_COLOR_CURRENT;
77 - if (!strcasecmp(var+ofs, "upstream"))
77 + if (!strcasecmp(slot, "upstream"))
78 return BRANCH_COLOR_UPSTREAM;
79 return -1;
80 }
@@ -88,7 +88,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
88 return 0;
89 }
90 if (starts_with(var, "color.branch.")) {
91 - int slot = parse_branch_color_slot(var, 13);
91 + int slot = parse_branch_color_slot(var + 13);
92 if (slot < 0)
93 return 0;
94 if (!value)
builtin/commit.c
+9 -10
@@ -1238,22 +1238,21 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
1238 return commitable ? 0 : 1;
1239 }
1240
1241 -static int parse_status_slot(const char *var, int offset)
1241 +static int parse_status_slot(const char *slot)
1242 {
1243 - if (!strcasecmp(var+offset, "header"))
1243 + if (!strcasecmp(slot, "header"))
1244 return WT_STATUS_HEADER;
1245 - if (!strcasecmp(var+offset, "branch"))
1245 + if (!strcasecmp(slot, "branch"))
1246 return WT_STATUS_ONBRANCH;
1247 - if (!strcasecmp(var+offset, "updated")
1248 - || !strcasecmp(var+offset, "added"))
1247 + if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added"))
1248 return WT_STATUS_UPDATED;
1250 - if (!strcasecmp(var+offset, "changed"))
1249 + if (!strcasecmp(slot, "changed"))
1250 return WT_STATUS_CHANGED;
1252 - if (!strcasecmp(var+offset, "untracked"))
1251 + if (!strcasecmp(slot, "untracked"))
1252 return WT_STATUS_UNTRACKED;
1254 - if (!strcasecmp(var+offset, "nobranch"))
1253 + if (!strcasecmp(slot, "nobranch"))
1254 return WT_STATUS_NOBRANCH;
1256 - if (!strcasecmp(var+offset, "unmerged"))
1255 + if (!strcasecmp(slot, "unmerged"))
1256 return WT_STATUS_UNMERGED;
1257 return -1;
1258 }
@@ -1291,7 +1290,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
1290 return 0;
1291 }
1292 if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) {
1294 - int slot = parse_status_slot(k, 13);
1293 + int slot = parse_status_slot(k + 13);
1294 if (slot < 0)
1295 return 0;
1296 if (!v)
builtin/log.c
+1 -1
@@ -389,7 +389,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
389 return 0;
390 }
391 if (starts_with(var, "color.decorate."))
392 - return parse_decorate_color_config(var, 15, value);
392 + return parse_decorate_color_config(var, var + 15, value);
393 if (!strcmp(var, "log.mailmap")) {
394 use_mailmap_config = git_config_bool(var, value);
395 return 0;
log-tree.c
+2 -2
@@ -66,9 +66,9 @@ static int parse_decorate_color_slot(const char *slot)
66 return -1;
67 }
68
69 -int parse_decorate_color_config(const char *var, const int ofs, const char *value)
69 +int parse_decorate_color_config(const char *var, const char *slot_name, const char *value)
70 {
71 - int slot = parse_decorate_color_slot(var + ofs);
71 + int slot = parse_decorate_color_slot(slot_name);
72 if (slot < 0)
73 return 0;
74 if (!value)
log-tree.h
+1 -1
@@ -7,7 +7,7 @@ struct log_info {
7 struct commit *commit, *parent;
8 };
9
10 -int parse_decorate_color_config(const char *var, const int ofs, const char *value);
10 +int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);
11 void init_log_tree_opt(struct rev_info *);
12 int log_tree_diff_flush(struct rev_info *);
13 int log_tree_commit(struct rev_info *, struct commit *);