From b7aa1ca3ffa363caf0ed4966433da99032761b3c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 9 Feb 2009 01:49:32 +0100 Subject: [PATCH] Move setting of remote branch from repo config to separate function --- tig.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tig.c b/tig.c index c9370d0..b1804aa 100644 --- a/tig.c +++ b/tig.c @@ -6677,6 +6677,23 @@ load_refs(void) return run_io_load(ls_remote_argv, "\t", read_ref); } +static void +set_remote_branch(const char *name, const char *value, size_t valuelen) +{ + if (!strcmp(name, ".remote")) { + string_ncopy(opt_remote, value, valuelen); + + } else if (*opt_remote && !strcmp(name, ".merge")) { + size_t from = strlen(opt_remote); + + if (!prefixcmp(value, "refs/heads/")) + value += STRING_SIZE("refs/heads/"); + + if (!string_format_from(opt_remote, &from, "/%s", value)) + opt_remote[0] = 0; + } +} + static void set_repo_config_option(char *name, char *value, int (*cmd)(int, const char **)) { @@ -6711,27 +6728,9 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen else if (!prefixcmp(name, "tig.")) set_repo_config_option(name + 4, value, option_set_command); - /* branch..remote */ - if (*opt_head && - !strncmp(name, "branch.", 7) && - !strncmp(name + 7, opt_head, strlen(opt_head)) && - !strcmp(name + 7 + strlen(opt_head), ".remote")) - string_ncopy(opt_remote, value, valuelen); - - if (*opt_head && *opt_remote && - !strncmp(name, "branch.", 7) && - !strncmp(name + 7, opt_head, strlen(opt_head)) && - !strcmp(name + 7 + strlen(opt_head), ".merge")) { - size_t from = strlen(opt_remote); - - if (!prefixcmp(value, "refs/heads/")) { - value += STRING_SIZE("refs/heads/"); - valuelen -= STRING_SIZE("refs/heads/"); - } - - if (!string_format_from(opt_remote, &from, "/%s", value)) - opt_remote[0] = 0; - } + else if (*opt_head && !prefixcmp(name, "branch.") && + !strncmp(name + 7, opt_head, strlen(opt_head))) + set_remote_branch(name + 7 + strlen(opt_head), value, valuelen); return OK; } -- 2.32.0.93.g670b81a890