git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>,
	"Jonathan Nieder" <jrnieder@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH 5/5] remote.c: eliminate remote->push_refspec
Date: Fri, 16 Jun 2017 21:28:37 +0200	[thread overview]
Message-ID: <20170616192837.11035-6-szeder.dev@gmail.com> (raw)
In-Reply-To: <20170616192837.11035-1-szeder.dev@gmail.com>

Do the same as in the previous patch, but for push refspecs, i.e. with
remote->push_refspec, remote->push and add_push_refspec().

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 builtin/push.c   | 12 +++++++-----
 builtin/remote.c | 19 ++++++++++++-------
 remote.c         | 29 +++++++++++------------------
 remote.h         | 10 ++++------
 4 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/builtin/push.c b/builtin/push.c
index 258648d5f..9a721fe8a 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -47,11 +47,11 @@ static const char *map_refspec(const char *ref,
 	if (count_refspec_match(ref, local_refs, &matched) != 1)
 		return ref;
 
-	if (remote->push) {
+	if (remote->push.rs) {
 		struct refspec query;
 		memset(&query, 0, sizeof(struct refspec));
 		query.src = matched->name;
-		if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) &&
+		if (!query_refspecs(remote->push.rs, remote->push.nr, &query) &&
 		    query.dst) {
 			struct strbuf buf = STRBUF_INIT;
 			strbuf_addf(&buf, "%s%s:%s",
@@ -401,9 +401,11 @@ static int do_push(const char *repo, int flags,
 	}
 
 	if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
-		if (remote->push_refspec_nr) {
-			refspec = remote->push_refspec;
-			refspec_nr = remote->push_refspec_nr;
+		if (remote->push.nr) {
+			ALLOC_ARRAY(refspec, remote->push.nr);
+			for (i = 0; i < remote->push.nr; i++)
+				refspec[i] = refspec_to_string(&remote->push.rs[i]);
+			refspec_nr = remote->push.nr;
 		} else if (!(flags & TRANSPORT_PUSH_MIRROR))
 			setup_default_push_refspecs(remote);
 	}
diff --git a/builtin/remote.c b/builtin/remote.c
index d61daa5e8..c04dec0e1 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -380,14 +380,19 @@ static int get_push_ref_states(const struct ref *remote_refs,
 {
 	struct remote *remote = states->remote;
 	struct ref *ref, *local_refs, *push_map;
+	const char **refspec;
+	int i;
 	if (remote->mirror)
 		return 0;
 
 	local_refs = get_local_heads();
 	push_map = copy_ref_list(remote_refs);
 
-	match_push_refs(local_refs, &push_map, remote->push_refspec_nr,
-			remote->push_refspec, MATCH_REFS_NONE);
+	ALLOC_ARRAY(refspec, remote->push.nr);
+	for (i = 0; i < remote->push.nr; i++)
+		refspec[i] = refspec_to_string(&remote->push.rs[i]);
+	match_push_refs(local_refs, &push_map, remote->push.nr,
+			refspec, MATCH_REFS_NONE);
 
 	states->push.strdup_strings = 1;
 	for (ref = push_map; ref; ref = ref->next) {
@@ -433,14 +438,14 @@ static int get_push_ref_states_noquery(struct ref_states *states)
 		return 0;
 
 	states->push.strdup_strings = 1;
-	if (!remote->push_refspec_nr) {
+	if (!remote->push.nr) {
 		item = string_list_append(&states->push, _("(matching)"));
 		info = item->util = xcalloc(1, sizeof(struct push_info));
 		info->status = PUSH_STATUS_NOTQUERIED;
 		info->dest = xstrdup(item->string);
 	}
-	for (i = 0; i < remote->push_refspec_nr; i++) {
-		struct refspec *spec = remote->push + i;
+	for (i = 0; i < remote->push.nr; i++) {
+		struct refspec *spec = remote->push.rs + i;
 		if (spec->matching)
 			item = string_list_append(&states->push, _("(matching)"));
 		else if (strlen(spec->src))
@@ -584,8 +589,8 @@ static int migrate_file(struct remote *remote)
 		git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.push", remote->name);
-	for (i = 0; i < remote->push_refspec_nr; i++) {
-		strbuf_add_refspec(&refspec, &remote->push[i]);
+	for (i = 0; i < remote->push.nr; i++) {
+		strbuf_add_refspec(&refspec, &remote->push.rs[i]);
 		git_config_set_multivar(buf.buf, refspec.buf, "^$", 0);
 		strbuf_reset(&refspec);
 	}
diff --git a/remote.c b/remote.c
index 952000b61..9dfe3e9a6 100644
--- a/remote.c
+++ b/remote.c
@@ -86,14 +86,6 @@ static const char *alias_url(const char *url, struct rewrites *r)
 	return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len);
 }
 
-static void add_push_refspec(struct remote *remote, const char *ref)
-{
-	ALLOC_GROW(remote->push_refspec,
-		   remote->push_refspec_nr + 1,
-		   remote->push_refspec_alloc);
-	remote->push_refspec[remote->push_refspec_nr++] = strdup(ref);
-}
-
 static void add_url(struct remote *remote, const char *url)
 {
 	ALLOC_GROW(remote->url, remote->url_nr + 1, remote->url_alloc);
@@ -257,7 +249,7 @@ static void read_remotes_file(struct remote *remote)
 		if (skip_prefix(buf.buf, "URL:", &v))
 			add_url_alias(remote, xstrdup(skip_spaces(v)));
 		else if (skip_prefix(buf.buf, "Push:", &v))
-			add_push_refspec(remote, skip_spaces(v));
+			add_push_refspec(remote, skip_spaces(v), 1);
 		else if (skip_prefix(buf.buf, "Pull:", &v))
 			add_fetch_refspec(remote, skip_spaces(v), 1);
 	}
@@ -308,7 +300,7 @@ static void read_branches_file(struct remote *remote)
 	 * (master if missing)
 	 */
 	strbuf_addf(&buf, "HEAD:refs/heads/%s", frag);
-	add_push_refspec(remote, buf.buf);
+	add_push_refspec(remote, buf.buf, 1);
 	remote->fetch_tags = 1; /* always auto-follow */
 
 	strbuf_release(&buf);
@@ -394,7 +386,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
-		add_push_refspec(remote, v);
+		add_push_refspec(remote, v, 1);
 		free((char*)v);
 	} else if (!strcmp(subkey, "fetch")) {
 		const char *v;
@@ -625,7 +617,7 @@ struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec)
 static int add_refspec(struct remote *remote, const char *refspec,
 		       int fetch, int gently)
 {
-	struct refspec_array *rsa = fetch ? &remote->fetch : NULL;
+	struct refspec_array *rsa = fetch ? &remote->fetch : &remote->push;
 
 	ALLOC_GROW(rsa->rs, rsa->nr + 1, rsa->alloc);
 
@@ -651,6 +643,11 @@ struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
 	return parse_refspec_internal(nr_refspec, refspec, 0, 0);
 }
 
+int add_push_refspec(struct remote *remote, const char *refspec, int gently)
+{
+	return add_refspec(remote, refspec, 0, gently);
+}
+
 void free_refspec(int nr_refspec, struct refspec *refspec)
 {
 	int i;
@@ -730,7 +727,6 @@ static struct remote *remote_get_1(const char *name,
 		return NULL;
 	if (ret->bogus_refspec)
 		die("Invalid refspec '%s'", ret->bogus_refspec);
-	ret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec);
 	return ret;
 }
 
@@ -763,9 +759,6 @@ int for_each_remote(each_remote_fn fn, void *priv)
 			continue;
 		if (r->bogus_refspec)
 			die("Invalid refspec '%s'", r->bogus_refspec);
-		if (!r->push)
-			r->push = parse_push_refspec(r->push_refspec_nr,
-						     r->push_refspec);
 		result = fn(r, priv);
 	}
 	return result;
@@ -1777,11 +1770,11 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
 				 _("branch '%s' has no remote for pushing"),
 				 branch->name);
 
-	if (remote->push_refspec_nr) {
+	if (remote->push.nr) {
 		char *dst;
 		const char *ret;
 
-		dst = apply_refspecs(remote->push, remote->push_refspec_nr,
+		dst = apply_refspecs(remote->push.rs, remote->push.nr,
 				     branch->refname);
 		if (!dst)
 			return error_buf(err,
diff --git a/remote.h b/remote.h
index 416a08501..eba06bacb 100644
--- a/remote.h
+++ b/remote.h
@@ -32,14 +32,10 @@ struct remote {
 	int pushurl_nr;
 	int pushurl_alloc;
 
-	const char **push_refspec;
-	struct refspec *push;
-	int push_refspec_nr;
-	int push_refspec_alloc;
-
+	struct refspec_array push;
 	struct refspec_array fetch;
 
-	/* Copy of the first bogus fetch refspec we couldn't parse */
+	/* Copy of the first bogus refspec we couldn't parse */
 	const char *bogus_refspec;
 
 	/*
@@ -184,6 +180,8 @@ struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
  */
 int add_fetch_refspec(struct remote *remote, const char *refspec, int gently);
 extern struct refspec *parse_push_refspec(int nr_refspec, const char **refspec);
+/* The same as add_fetch_refspec() above, but for push refspecs. */
+int add_push_refspec(struct remote *remote, const char *refspec, int gently);
 
 void free_refspec(int nr_refspec, struct refspec *refspec);
 
-- 
2.13.1.505.g7cc9fcafb


  parent reply	other threads:[~2017-06-16 19:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-16 19:28 [RFC/PATCH 0/5] remote: eliminate remote->{fetch,push}_refspec and lazy parsing of refspecs SZEDER Gábor
2017-06-16 19:28 ` [PATCH 1/5] remote: don't use remote->{fetch,push}_refspec SZEDER Gábor
2017-06-16 22:00   ` Junio C Hamano
2017-06-16 19:28 ` [PATCH 2/5] remote.c: don't pass copies of refspecs to add_{fetch,push}_refspec() SZEDER Gábor
2017-06-16 19:28 ` [PATCH 3/5] remote.c: extract a helper function to parse a single refspec SZEDER Gábor
2017-06-16 19:28 ` [PATCH 4/5] remote.c: eliminate remote->fetch_refspec SZEDER Gábor
2017-06-16 19:28 ` SZEDER Gábor [this message]
2017-06-16 21:55 ` [RFC/PATCH 0/5] remote: eliminate remote->{fetch,push}_refspec and lazy parsing of refspecs Junio C Hamano
2017-06-17 12:25   ` SZEDER Gábor
2017-06-17 12:33     ` Jeff King
2017-06-17 11:55 ` Jeff King
2017-06-19 20:07   ` 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=20170616192837.11035-6-szeder.dev@gmail.com \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.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 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 NNTP newsgroup(s).