Skip to content

Commit 8852117

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80b616d commit 8852117

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

builtin/branch.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ static unsigned char merge_filter_ref[20];
6262
static struct string_list output = STRING_LIST_INIT_DUP;
6363
static unsigned int colopts;
6464

65-
static int parse_branch_color_slot(const char *var, int ofs)
65+
static int parse_branch_color_slot(const char *slot)
6666
{
67-
if (!strcasecmp(var+ofs, "plain"))
67+
if (!strcasecmp(slot, "plain"))
6868
return BRANCH_COLOR_PLAIN;
69-
if (!strcasecmp(var+ofs, "reset"))
69+
if (!strcasecmp(slot, "reset"))
7070
return BRANCH_COLOR_RESET;
71-
if (!strcasecmp(var+ofs, "remote"))
71+
if (!strcasecmp(slot, "remote"))
7272
return BRANCH_COLOR_REMOTE;
73-
if (!strcasecmp(var+ofs, "local"))
73+
if (!strcasecmp(slot, "local"))
7474
return BRANCH_COLOR_LOCAL;
75-
if (!strcasecmp(var+ofs, "current"))
75+
if (!strcasecmp(slot, "current"))
7676
return BRANCH_COLOR_CURRENT;
77-
if (!strcasecmp(var+ofs, "upstream"))
77+
if (!strcasecmp(slot, "upstream"))
7878
return BRANCH_COLOR_UPSTREAM;
7979
return -1;
8080
}
@@ -88,7 +88,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
8888
return 0;
8989
}
9090
if (starts_with(var, "color.branch.")) {
91-
int slot = parse_branch_color_slot(var, 13);
91+
int slot = parse_branch_color_slot(var + 13);
9292
if (slot < 0)
9393
return 0;
9494
if (!value)

builtin/commit.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,22 +1238,21 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
12381238
return commitable ? 0 : 1;
12391239
}
12401240

1241-
static int parse_status_slot(const char *var, int offset)
1241+
static int parse_status_slot(const char *slot)
12421242
{
1243-
if (!strcasecmp(var+offset, "header"))
1243+
if (!strcasecmp(slot, "header"))
12441244
return WT_STATUS_HEADER;
1245-
if (!strcasecmp(var+offset, "branch"))
1245+
if (!strcasecmp(slot, "branch"))
12461246
return WT_STATUS_ONBRANCH;
1247-
if (!strcasecmp(var+offset, "updated")
1248-
|| !strcasecmp(var+offset, "added"))
1247+
if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added"))
12491248
return WT_STATUS_UPDATED;
1250-
if (!strcasecmp(var+offset, "changed"))
1249+
if (!strcasecmp(slot, "changed"))
12511250
return WT_STATUS_CHANGED;
1252-
if (!strcasecmp(var+offset, "untracked"))
1251+
if (!strcasecmp(slot, "untracked"))
12531252
return WT_STATUS_UNTRACKED;
1254-
if (!strcasecmp(var+offset, "nobranch"))
1253+
if (!strcasecmp(slot, "nobranch"))
12551254
return WT_STATUS_NOBRANCH;
1256-
if (!strcasecmp(var+offset, "unmerged"))
1255+
if (!strcasecmp(slot, "unmerged"))
12571256
return WT_STATUS_UNMERGED;
12581257
return -1;
12591258
}
@@ -1291,7 +1290,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
12911290
return 0;
12921291
}
12931292
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);
12951294
if (slot < 0)
12961295
return 0;
12971296
if (!v)

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
389389
return 0;
390390
}
391391
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);
393393
if (!strcmp(var, "log.mailmap")) {
394394
use_mailmap_config = git_config_bool(var, value);
395395
return 0;

log-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ static int parse_decorate_color_slot(const char *slot)
6666
return -1;
6767
}
6868

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)
7070
{
71-
int slot = parse_decorate_color_slot(var + ofs);
71+
int slot = parse_decorate_color_slot(slot_name);
7272
if (slot < 0)
7373
return 0;
7474
if (!value)

log-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct log_info {
77
struct commit *commit, *parent;
88
};
99

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);
1111
void init_log_tree_opt(struct rev_info *);
1212
int log_tree_diff_flush(struct rev_info *);
1313
int log_tree_commit(struct rev_info *, struct commit *);

0 commit comments

Comments
 (0)