From patchwork Fri Jan 24 09:25:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86F68921 for ; Fri, 24 Jan 2020 09:25:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 652C820838 for ; Fri, 24 Jan 2020 09:25:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="cQ+TSAiU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730376AbgAXJZd (ORCPT ); Fri, 24 Jan 2020 04:25:33 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:32794 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728928AbgAXJZc (ORCPT ); Fri, 24 Jan 2020 04:25:32 -0500 Received: by mail-wm1-f66.google.com with SMTP id m10so3118430wmc.0 for ; Fri, 24 Jan 2020 01:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DyHHivxss+vJsvXP+/tp2pYiIergF+KDNzC01hr3fTU=; b=cQ+TSAiUs6lbnGYSI34+PiRrmX650aCZtgA5n5SluPVyU5NOHXNUfodhdpf2ffEm5p 8do7ZelIDkX5D/T5BkvqB7NmEOZosy1AsAs3ERY0ydgSkiZhzEEBsH36FSykLE2QXEj7 IJgyyPdypT7R7C6v/K9IfMyGlM2dTvyyDYcSL09ngN10XxcyV8eCGr0gLMD4P9vla0js 6L9r60v0yAHqzHm2tREzAnna1zhymMbkRnx32UFYLg9CJLa3MyDzni8m+C/S+7B11RrN Fkvw7OKPKGxgT9DZ3WA/hl51rFA+/wF/wUZkaBiZrdLZZdUNs7ZnR5fBX6oNgnllSAKW sPcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DyHHivxss+vJsvXP+/tp2pYiIergF+KDNzC01hr3fTU=; b=REmdpcseQCWw7BS2oh9Y58qt23hUNmAzpx18Gi5CH4nEVeLeXoIykA93cpDAog/tAf AqCddWwIrgBX4bBI3ls8QarPQ1IQxKiFOBpB1Qb3YPKrUwQTmgiSXu1DwZS+GkvNbwIB /Db1LfI2sQg8kD9qtgK0pv9bcHnvqmqnYEUzxaDnkLDhwYkfp4YlupKFun7pgr6UfujZ 6Ho5l2lFxnKOIGTXPFcmpfZAcYS7mQtwDBihqLRwT/dxZV2JYcllrSE5WzUi0fbDjxhE 3sA3VOMcCLGtE1snT6by5eba5r8fh2/GbI6cxPOy+pTrCY2wnFThJHP1FHgDruOreMLR p4ew== X-Gm-Message-State: APjAAAWmI8RupFuuZmjh5Hu1/ZHiVoVotocMrx6s6EmLU2dWczErNiL9 +eTL7T5HYhO+2YAmtZ0= X-Google-Smtp-Source: APXvYqz4ymWx1Y58Pt7lNO3r6zlZTRh7J/sHOccJ1JfemQAMMi19gaWFlLphngPOxI1Sq6CyTb8TEQ== X-Received: by 2002:a1c:5448:: with SMTP id p8mr2543805wmi.159.1579857931256; Fri, 24 Jan 2020 01:25:31 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id q6sm7132821wrx.72.2020.01.24.01.25.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:30 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Junio C Hamano Subject: [PATCH v2 2/7] remote: clean-up by returning early to avoid one indentation Date: Fri, 24 Jan 2020 10:25:22 +0100 Message-Id: X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Bert Wesarg --- Changes since v1: * avoid mixed declarations and statements Cc: Junio C Hamano --- builtin/remote.c | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 6802765e73..4cf929bfc6 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -263,54 +263,56 @@ static const char *abbrev_ref(const char *name, const char *prefix) static int config_read_branches(const char *key, const char *value, void *cb) { - if (starts_with(key, "branch.")) { - const char *orig_key = key; - char *name; - struct string_list_item *item; - struct branch_info *info; - enum { REMOTE, MERGE, REBASE } type; - size_t key_len; - - key += 7; - if (strip_suffix(key, ".remote", &key_len)) { - name = xmemdupz(key, key_len); - type = REMOTE; - } else if (strip_suffix(key, ".merge", &key_len)) { - name = xmemdupz(key, key_len); - type = MERGE; - } else if (strip_suffix(key, ".rebase", &key_len)) { - name = xmemdupz(key, key_len); - type = REBASE; - } else - return 0; + const char *orig_key = key; + char *name; + struct string_list_item *item; + struct branch_info *info; + enum { REMOTE, MERGE, REBASE } type; + size_t key_len; - item = string_list_insert(&branch_list, name); + if (!starts_with(key, "branch.")) + return 0; + + key += 7; + if (strip_suffix(key, ".remote", &key_len)) { + name = xmemdupz(key, key_len); + type = REMOTE; + } else if (strip_suffix(key, ".merge", &key_len)) { + name = xmemdupz(key, key_len); + type = MERGE; + } else if (strip_suffix(key, ".rebase", &key_len)) { + name = xmemdupz(key, key_len); + type = REBASE; + } else + return 0; + + item = string_list_insert(&branch_list, name); + + if (!item->util) + item->util = xcalloc(1, sizeof(struct branch_info)); + info = item->util; + if (type == REMOTE) { + if (info->remote_name) + warning(_("more than one %s"), orig_key); + info->remote_name = xstrdup(value); + } else if (type == MERGE) { + char *space = strchr(value, ' '); + value = abbrev_branch(value); + while (space) { + char *merge; + merge = xstrndup(value, space - value); + string_list_append(&info->merge, merge); + value = abbrev_branch(space + 1); + space = strchr(value, ' '); + } + string_list_append(&info->merge, xstrdup(value)); + } else + /* + * Consider invalid values as false and check the + * truth value with >= REBASE_TRUE. + */ + info->rebase = rebase_parse_value(value); - if (!item->util) - item->util = xcalloc(1, sizeof(struct branch_info)); - info = item->util; - if (type == REMOTE) { - if (info->remote_name) - warning(_("more than one %s"), orig_key); - info->remote_name = xstrdup(value); - } else if (type == MERGE) { - char *space = strchr(value, ' '); - value = abbrev_branch(value); - while (space) { - char *merge; - merge = xstrndup(value, space - value); - string_list_append(&info->merge, merge); - value = abbrev_branch(space + 1); - space = strchr(value, ' '); - } - string_list_append(&info->merge, xstrdup(value)); - } else - /* - * Consider invalid values as false and check the - * truth value with >= REBASE_TRUE. - */ - info->rebase = rebase_parse_value(value); - } return 0; }