All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gummerer <t.gummerer@gmail.com>
To: git@vger.kernel.org, Thomas Gummerer <t.gummerer@gmail.com>
Cc: peff@peff.net, Johannes.Schindelin@gmx.de, gitster@pobox.com
Subject: [PATCH v2 0/4] git remote improvements
Date: Mon, 15 Feb 2016 23:39:40 +0100	[thread overview]
Message-ID: <1455575984-24348-1-git-send-email-t.gummerer@gmail.com> (raw)

Thanks Peff for the review on the previous round ($gmane/286214).

The series now uses parse_config_key() instead of skip_prefix, and I
added REMOTE_UNCONFIGURED to the enum used in the origin field in
struct remote.

Interdiff below:

diff --git a/remote.c b/remote.c
index 3a4ca9b..d10ae00 100644
--- a/remote.c
+++ b/remote.c
@@ -318,90 +318,88 @@ static void read_branches_file(struct remote *remote)
 static int handle_config(const char *key, const char *value, void *cb)
 {
 	const char *name;
+	int namelen;
 	const char *subkey;
 	struct remote *remote;
 	struct branch *branch;
-	if (skip_prefix(key, "branch.", &name)) {
-		subkey = strrchr(name, '.');
-		if (!subkey)
+	if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
+		if (!name)
 			return 0;
-		branch = make_branch(name, subkey - name);
-		if (!strcmp(subkey, ".remote")) {
+		branch = make_branch(name, namelen);
+		if (!strcmp(subkey, "remote")) {
 			return git_config_string(&branch->remote_name, key, value);
-		} else if (!strcmp(subkey, ".pushremote")) {
+		} else if (!strcmp(subkey, "pushremote")) {
 			return git_config_string(&branch->pushremote_name, key, value);
-		} else if (!strcmp(subkey, ".merge")) {
+		} else if (!strcmp(subkey, "merge")) {
 			if (!value)
 				return config_error_nonbool(key);
 			add_merge(branch, xstrdup(value));
 		}
 		return 0;
 	}
-	if (skip_prefix(key, "url.", &name)) {
+	if (parse_config_key(key, "url", &name, &namelen, &subkey) >= 0) {
 		struct rewrite *rewrite;
-		subkey = strrchr(name, '.');
-		if (!subkey)
+		if (!name)
 			return 0;
-		if (!strcmp(subkey, ".insteadof")) {
-			rewrite = make_rewrite(&rewrites, name, subkey - name);
+		if (!strcmp(subkey, "insteadof")) {
+			rewrite = make_rewrite(&rewrites, name, namelen);
 			if (!value)
 				return config_error_nonbool(key);
 			add_instead_of(rewrite, xstrdup(value));
-		} else if (!strcmp(subkey, ".pushinsteadof")) {
-			rewrite = make_rewrite(&rewrites_push, name, subkey - name);
+		} else if (!strcmp(subkey, "pushinsteadof")) {
+			rewrite = make_rewrite(&rewrites_push, name, namelen);
 			if (!value)
 				return config_error_nonbool(key);
 			add_instead_of(rewrite, xstrdup(value));
 		}
 	}
 
-	if (!skip_prefix(key, "remote.", &name))
+	if (parse_config_key(key, "remote", &name, &namelen, &subkey) < 0)
 		return 0;
 
 	/* Handle remote.* variables */
-	if (!strcmp(name, "pushdefault"))
+	if (!strcmp(subkey, "pushdefault"))
 		return git_config_string(&pushremote_name, key, value);
 
 	/* Handle remote.<name>.* variables */
-	if (*name == '/') {
+	if (*(name ? name : subkey) == '/') {
 		warning("Config remote shorthand cannot begin with '/': %s",
-			name);
+			name ? name : subkey);
 		return 0;
 	}
-	subkey = strrchr(name, '.');
-	if (!subkey)
+	if (!name)
 		return 0;
-	remote = make_remote(name, subkey - name);
+	remote = make_remote(name, namelen);
 	remote->origin = REMOTE_CONFIG;
-	if (!strcmp(subkey, ".mirror"))
+	if (!strcmp(subkey, "mirror"))
 		remote->mirror = git_config_bool(key, value);
-	else if (!strcmp(subkey, ".skipdefaultupdate"))
+	else if (!strcmp(subkey, "skipdefaultupdate"))
 		remote->skip_default_update = git_config_bool(key, value);
-	else if (!strcmp(subkey, ".skipfetchall"))
+	else if (!strcmp(subkey, "skipfetchall"))
 		remote->skip_default_update = git_config_bool(key, value);
-	else if (!strcmp(subkey, ".prune"))
+	else if (!strcmp(subkey, "prune"))
 		remote->prune = git_config_bool(key, value);
-	else if (!strcmp(subkey, ".url")) {
+	else if (!strcmp(subkey, "url")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_url(remote, v);
-	} else if (!strcmp(subkey, ".pushurl")) {
+	} else if (!strcmp(subkey, "pushurl")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_pushurl(remote, v);
-	} else if (!strcmp(subkey, ".push")) {
+	} else if (!strcmp(subkey, "push")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_push_refspec(remote, v);
-	} else if (!strcmp(subkey, ".fetch")) {
+	} else if (!strcmp(subkey, "fetch")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_fetch_refspec(remote, v);
-	} else if (!strcmp(subkey, ".receivepack")) {
+	} else if (!strcmp(subkey, "receivepack")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
@@ -409,7 +407,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 			remote->receivepack = v;
 		else
 			error("more than one receivepack given, using the first");
-	} else if (!strcmp(subkey, ".uploadpack")) {
+	} else if (!strcmp(subkey, "uploadpack")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
@@ -417,18 +415,18 @@ static int handle_config(const char *key, const char *value, void *cb)
 			remote->uploadpack = v;
 		else
 			error("more than one uploadpack given, using the first");
-	} else if (!strcmp(subkey, ".tagopt")) {
+	} else if (!strcmp(subkey, "tagopt")) {
 		if (!strcmp(value, "--no-tags"))
 			remote->fetch_tags = -1;
 		else if (!strcmp(value, "--tags"))
 			remote->fetch_tags = 2;
-	} else if (!strcmp(subkey, ".proxy")) {
+	} else if (!strcmp(subkey, "proxy")) {
 		return git_config_string((const char **)&remote->http_proxy,
 					 key, value);
-	} else if (!strcmp(subkey, ".proxyauthmethod")) {
+	} else if (!strcmp(subkey, "proxyauthmethod")) {
 		return git_config_string((const char **)&remote->http_proxy_authmethod,
 					 key, value);
-	} else if (!strcmp(subkey, ".vcs")) {
+	} else if (!strcmp(subkey, "vcs")) {
 		return git_config_string(&remote->foreign_vcs, key, value);
 	}
 	return 0;
diff --git a/remote.h b/remote.h
index 7a5ee77..c21fd37 100644
--- a/remote.h
+++ b/remote.h
@@ -5,7 +5,8 @@
 #include "hashmap.h"
 
 enum {
-	REMOTE_CONFIG = 1,
+	REMOTE_UNCONFIGURED = 0,
+	REMOTE_CONFIG,
 	REMOTE_REMOTES,
 	REMOTE_BRANCHES
 };

Thomas Gummerer (4):
  remote: use parse_config_key
  remote: simplify remote_is_configured()
  remote: actually check if remote exits
  remote: use remote_is_configured() for add and rename

 builtin/fetch.c   |  5 ++--
 builtin/remote.c  | 23 +++++++--------
 remote.c          | 84 +++++++++++++++++++++++--------------------------------
 remote.h          |  3 +-
 t/t5505-remote.sh | 36 ++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 66 deletions(-)

-- 
2.7.1.410.g6faf27b

             reply	other threads:[~2016-02-15 22:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-15 22:39 Thomas Gummerer [this message]
2016-02-15 22:39 ` [PATCH v2 1/4] remote: use parse_config_key Thomas Gummerer
2016-02-15 23:04   ` Jeff King
2016-02-16  0:13     ` Thomas Gummerer
2016-02-15 22:39 ` [PATCH v2 2/4] remote: simplify remote_is_configured() Thomas Gummerer
2016-02-15 22:39 ` [PATCH v2 3/4] remote: actually check if remote exits Thomas Gummerer
2016-02-15 22:39 ` [PATCH v2 4/4] remote: use remote_is_configured() for add and rename Thomas Gummerer
2016-02-15 22:52   ` Eric Sunshine
2016-02-15 23:09     ` Jeff King
2016-02-16  0:16       ` Thomas Gummerer
2016-02-16  9:47 ` [PATCH v3 0/4] git remote improvements Thomas Gummerer
2016-02-16  9:47   ` [PATCH v3 1/4] remote: use parse_config_key Thomas Gummerer
2016-02-16  9:47   ` [PATCH v3 2/4] remote: simplify remote_is_configured() Thomas Gummerer
2016-02-16  9:47   ` [PATCH v3 3/4] remote: actually check if remote exits Thomas Gummerer
2016-02-16  9:47   ` [PATCH v3 4/4] remote: use remote_is_configured() for add and rename Thomas Gummerer
2016-02-16 15:52   ` [PATCH v3 0/4] git remote improvements Jeff King
2016-02-16 21:36   ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=1455575984-24348-1-git-send-email-t.gummerer@gmail.com \
    --to=t.gummerer@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.