From a73b3680c4910866e3e215c3927a0c71f0b9229d Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Sat, 26 May 2018 15:55:21 +0200 Subject: Add and use generic name->id mapping code for color slot parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- builtin/commit.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'builtin/commit.c') diff --git a/builtin/commit.c b/builtin/commit.c index 5240f11225..f96755aa4b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -66,6 +66,18 @@ N_("If you wish to skip this commit, use:\n" "Then \"git cherry-pick --continue\" will resume cherry-picking\n" "the remaining commits.\n"); +static const char *color_status_slots[] = { + [WT_STATUS_HEADER] = "header", + [WT_STATUS_UPDATED] = "updated", + [WT_STATUS_CHANGED] = "changed", + [WT_STATUS_UNTRACKED] = "untracked", + [WT_STATUS_NOBRANCH] = "noBranch", + [WT_STATUS_UNMERGED] = "unmerged", + [WT_STATUS_LOCAL_BRANCH] = "localBranch", + [WT_STATUS_REMOTE_BRANCH] = "remoteBranch", + [WT_STATUS_ONBRANCH] = "branch", +}; + static const char *use_message_buffer; static struct lock_file index_lock; /* real index */ static struct lock_file false_lock; /* used only for partial commits */ @@ -1175,25 +1187,10 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix, static int parse_status_slot(const char *slot) { - if (!strcasecmp(slot, "header")) - return WT_STATUS_HEADER; - if (!strcasecmp(slot, "branch")) - return WT_STATUS_ONBRANCH; - if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added")) + if (!strcasecmp(slot, "added")) return WT_STATUS_UPDATED; - if (!strcasecmp(slot, "changed")) - return WT_STATUS_CHANGED; - if (!strcasecmp(slot, "untracked")) - return WT_STATUS_UNTRACKED; - if (!strcasecmp(slot, "nobranch")) - return WT_STATUS_NOBRANCH; - if (!strcasecmp(slot, "unmerged")) - return WT_STATUS_UNMERGED; - if (!strcasecmp(slot, "localBranch")) - return WT_STATUS_LOCAL_BRANCH; - if (!strcasecmp(slot, "remoteBranch")) - return WT_STATUS_REMOTE_BRANCH; - return -1; + + return LOOKUP_CONFIG(color_status_slots, slot); } static int git_status_config(const char *k, const char *v, void *cb) -- cgit v1.2.3