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 1/5] remote: don't use remote->{fetch,push}_refspec
Date: Fri, 16 Jun 2017 21:28:33 +0200	[thread overview]
Message-ID: <20170616192837.11035-2-szeder.dev@gmail.com> (raw)
In-Reply-To: <20170616192837.11035-1-szeder.dev@gmail.com>

builtin/remote.c uses remote->fetch_refspec and remote->push_refspec,
i.e. refspecs as strings, in a few places, e.g. in an error message or
to set configuration variables.

Since we are about to eliminate remote->{fetch,push}_refspec, recreate
those strings from the corresponding remote->{fetch,push} entries.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 builtin/remote.c | 22 +++++++++++++++-------
 remote.c         | 20 ++++++++++++++++++++
 remote.h         |  2 ++
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/builtin/remote.c b/builtin/remote.c
index f1a88fe26..7f0072fe5 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -334,7 +334,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
 	for (i = 0; i < states->remote->fetch_refspec_nr; i++)
 		if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1))
 			die(_("Could not get fetch map for refspec %s"),
-				states->remote->fetch_refspec[i]);
+			      refspec_to_string(&states->remote->fetch[i]));
 
 	states->new.strdup_strings = 1;
 	states->tracked.strdup_strings = 1;
@@ -576,7 +576,7 @@ static int read_remote_branches(const char *refname,
 
 static int migrate_file(struct remote *remote)
 {
-	struct strbuf buf = STRBUF_INIT;
+	struct strbuf buf = STRBUF_INIT, refspec = STRBUF_INIT;
 	int i;
 
 	strbuf_addf(&buf, "remote.%s.url", remote->name);
@@ -584,17 +584,25 @@ 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++)
-		git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0);
+	for (i = 0; i < remote->push_refspec_nr; i++) {
+		strbuf_add_refspec(&refspec, &remote->push[i]);
+		git_config_set_multivar(buf.buf, refspec.buf, "^$", 0);
+		strbuf_reset(&refspec);
+	}
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.fetch", remote->name);
-	for (i = 0; i < remote->fetch_refspec_nr; i++)
-		git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0);
+	for (i = 0; i < remote->fetch_refspec_nr; i++) {
+		strbuf_add_refspec(&refspec, &remote->fetch[i]);
+		git_config_set_multivar(buf.buf, refspec.buf, "^$", 0);
+		strbuf_reset(&refspec);
+	}
 	if (remote->origin == REMOTE_REMOTES)
 		unlink_or_warn(git_path("remotes/%s", remote->name));
 	else if (remote->origin == REMOTE_BRANCHES)
 		unlink_or_warn(git_path("branches/%s", remote->name));
 
+	strbuf_release(&buf);
+	strbuf_release(&refspec);
 	return 0;
 }
 
@@ -647,7 +655,7 @@ static int mv(int argc, const char **argv)
 		char *ptr;
 
 		strbuf_reset(&buf2);
-		strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
+		strbuf_add_refspec(&buf2, &oldremote->fetch[i]);
 		ptr = strstr(buf2.buf, old_remote_context.buf);
 		if (ptr) {
 			refspec_updated = 1;
diff --git a/remote.c b/remote.c
index 336db8298..a021decee 100644
--- a/remote.c
+++ b/remote.c
@@ -919,6 +919,26 @@ char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
 	return query.dst;
 }
 
+void strbuf_add_refspec(struct strbuf *sb, const struct refspec *refspec)
+{
+	if (refspec->force)
+		strbuf_addch(sb, '+');
+	if (refspec->src)
+		strbuf_addstr(sb, refspec->src);
+	if (refspec->dst) {
+		strbuf_addch(sb, ':');
+		strbuf_addstr(sb, refspec->dst);
+	} else if (!refspec->src)
+		strbuf_addch(sb, ':');
+}
+
+char *refspec_to_string(const struct refspec *refspec)
+{
+	struct strbuf sb = STRBUF_INIT;
+	strbuf_add_refspec(&sb, refspec);
+	return strbuf_detach(&sb, NULL);
+}
+
 int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 {
 	return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec);
diff --git a/remote.h b/remote.h
index 9619f94dd..ee6c432d0 100644
--- a/remote.h
+++ b/remote.h
@@ -177,6 +177,8 @@ void free_refspec(int nr_refspec, struct refspec *refspec);
 extern int query_refspecs(struct refspec *specs, int nr, struct refspec *query);
 char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
 		     const char *name);
+void strbuf_add_refspec(struct strbuf *sb, const struct refspec *refspec);
+char *refspec_to_string(const struct refspec *refspec);
 
 int check_push_refs(struct ref *src, int nr_refspec, const char **refspec);
 int match_push_refs(struct ref *src, struct ref **dst,
-- 
2.13.1.505.g7cc9fcafb


  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 ` SZEDER Gábor [this message]
2017-06-16 22:00   ` [PATCH 1/5] remote: don't use remote->{fetch,push}_refspec 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 ` [PATCH 5/5] remote.c: eliminate remote->push_refspec SZEDER Gábor
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-2-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).