git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Bert Wesarg <bert.wesarg@googlemail.com>
To: git@vger.kernel.org
Cc: Bert Wesarg <bert.wesarg@googlemail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 2/7] remote: clean-up by returning early to avoid one indentation
Date: Fri, 24 Jan 2020 10:25:22 +0100	[thread overview]
Message-ID: <f8f3fd1f2151866891c4ba9cd4e3080fec3c9e9c.1579857394.git.bert.wesarg@googlemail.com> (raw)
In-Reply-To: <cover.1579857394.git.bert.wesarg@googlemail.com>

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>

---
Changes since v1:
 * avoid mixed declarations and statements

Cc: Junio C Hamano <gitster@pobox.com>
---
 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;
 }
 
-- 
2.24.1.497.g9abd7b20b4.dirty


  parent reply	other threads:[~2020-01-24  9:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24  9:25 [PATCH v2 0/7] remote rename/remove: improve handling of configuration values Bert Wesarg
2020-01-24  9:25 ` [PATCH v2 1/7] pull --rebase/remote rename: document and honor single-letter abbreviations rebase types Bert Wesarg
2020-01-24  9:25 ` Bert Wesarg [this message]
2020-01-24  9:25 ` [PATCH 3/7] remote: clean-up config callback Bert Wesarg
2020-01-24  9:25 ` [PATCH v4 4/7] remote rename/remove: handle branch.<name>.pushRemote config values Bert Wesarg
2020-01-25  0:46   ` Johannes Schindelin
2020-01-25  7:29     ` Bert Wesarg
2020-01-26  9:30       ` Johannes Schindelin
2020-01-24  9:25 ` [RFC PATCH 5/7] config: make `scope_name` global as `config_scope_name` Bert Wesarg
2020-01-24  9:25 ` [PATCH 6/7] config: provide access to the current line number Bert Wesarg
2020-01-24  9:25 ` [PATCH v2 7/7] remote rename/remove: gently handle remote.pushDefault config Bert Wesarg
2020-01-24 21:00 ` [PATCH v2 0/7] remote rename/remove: improve handling of configuration values Junio C Hamano
2020-01-25  0:39   ` Matt Rogers
2020-01-27  6:50     ` Bert Wesarg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8f3fd1f2151866891c4ba9cd4e3080fec3c9e9c.1579857394.git.bert.wesarg@googlemail.com \
    --to=bert.wesarg@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).