From: "Sean Barag via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Derrick Stolee <stolee@gmail.com>, Jeff King <peff@peff.net>,
Eric Sunshine <sunshine@sunshineco.com>,
Taylor Blau <me@ttaylorr.com>, Sean Barag <sean@barag.org>,
Andrei Rybak <rybak.a.v@gmail.com>, Sean Barag <sean@barag.org>,
Sean Barag <sean@barag.org>
Subject: [PATCH v3 4/7] refs: consolidate remote name validation
Date: Thu, 01 Oct 2020 03:46:13 +0000 [thread overview]
Message-ID: <cb686b4129902335ef98c83c8cfbcac1c88da856.1601523977.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.727.v3.git.1601523977.gitgitgadget@gmail.com>
From: Sean Barag <sean@barag.org>
In preparation for a future patch, extract from remote.c a function that
validates possible remote names so that its rules can be used
consistently in other places.
Helped-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Sean Barag <sean@barag.org>
---
builtin/remote.c | 7 ++-----
refspec.c | 10 ++++++++++
refspec.h | 1 +
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 64b4b551eb..63f2b46c3d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -194,8 +194,7 @@ static int add(int argc, const char **argv)
if (remote_is_configured(remote, 1))
die(_("remote %s already exists."), name);
- strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
- if (!valid_fetch_refspec(buf2.buf))
+ if (!valid_remote_name(name))
die(_("'%s' is not a valid remote name"), name);
strbuf_addf(&buf, "remote.%s.url", name);
@@ -696,11 +695,9 @@ static int mv(int argc, const char **argv)
if (remote_is_configured(newremote, 1))
die(_("remote %s already exists."), rename.new_name);
- strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name);
- if (!valid_fetch_refspec(buf.buf))
+ if (!valid_remote_name(rename.new_name))
die(_("'%s' is not a valid remote name"), rename.new_name);
- strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s", rename.old_name);
strbuf_addf(&buf2, "remote.%s", rename.new_name);
if (git_config_rename_section(buf.buf, buf2.buf) < 1)
diff --git a/refspec.c b/refspec.c
index 8d0affc34a..3056ffdfb8 100644
--- a/refspec.c
+++ b/refspec.c
@@ -215,6 +215,16 @@ int valid_fetch_refspec(const char *fetch_refspec_str)
return ret;
}
+int valid_remote_name(const char *name)
+{
+ int result;
+ struct strbuf refspec = STRBUF_INIT;
+ strbuf_addf(&refspec, "refs/heads/test:refs/remotes/%s/test", name);
+ result = valid_fetch_refspec(refspec.buf);
+ strbuf_release(&refspec);
+ return result;
+}
+
void refspec_ref_prefixes(const struct refspec *rs,
struct strvec *ref_prefixes)
{
diff --git a/refspec.h b/refspec.h
index 7569248d11..bbb25968a8 100644
--- a/refspec.h
+++ b/refspec.h
@@ -62,6 +62,7 @@ void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
void refspec_clear(struct refspec *rs);
int valid_fetch_refspec(const char *refspec);
+int valid_remote_name(const char *name);
struct strvec;
/*
--
gitgitgadget
next prev parent reply other threads:[~2020-10-01 3:46 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-11 18:25 [PATCH 0/4] clone: allow configurable default for -o/--origin Sean Barag via GitGitGadget
2020-09-11 18:25 ` [PATCH 1/4] clone: add tests for --template and some disallowed option pairs Sean Barag via GitGitGadget
2020-09-11 18:57 ` Derrick Stolee
2020-09-11 19:56 ` Jeff King
2020-09-11 20:07 ` Eric Sunshine
2020-09-16 3:15 ` [PATCH 0/4] clone: allow configurable default for -o/--origin Sean Barag
2020-09-12 3:17 ` [PATCH 1/4] clone: add tests for --template and some disallowed option pairs Taylor Blau
2020-09-15 16:09 ` Sean Barag
2020-09-16 16:36 ` Jeff King
2020-09-11 21:02 ` Junio C Hamano
2020-09-12 0:41 ` Derrick Stolee
2020-09-11 18:25 ` [PATCH 2/4] clone: call git_config before parse_options Sean Barag via GitGitGadget
2020-09-11 18:59 ` Derrick Stolee
2020-09-11 20:26 ` Junio C Hamano
2020-09-16 16:12 ` Sean Barag
2020-09-11 18:25 ` [PATCH 3/4] clone: validate --origin option before use Sean Barag via GitGitGadget
2020-09-11 19:24 ` Derrick Stolee
2020-09-16 16:28 ` Sean Barag
2020-09-11 20:39 ` Junio C Hamano
2020-09-16 17:11 ` Sean Barag
2020-09-21 16:13 ` Sean Barag
2020-09-11 18:25 ` [PATCH 4/4] clone: allow configurable default for `-o`/`--origin` Sean Barag via GitGitGadget
2020-09-11 19:13 ` Derrick Stolee
2020-09-28 16:04 ` Sean Barag
2020-09-11 21:00 ` Junio C Hamano
2020-09-28 16:02 ` Sean Barag
2020-09-17 15:25 ` Andrei Rybak
2020-09-11 19:25 ` [PATCH 0/4] clone: allow configurable default for -o/--origin Derrick Stolee
2020-09-11 19:34 ` Junio C Hamano
2020-09-29 3:36 ` [PATCH v2 0/7] " Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 1/7] clone: add tests for --template and some disallowed option pairs Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 2/7] clone: use more conventional config/option layering Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 3/7] remote: add tests for add and rename with invalid names Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 4/7] refs: consolidate remote name validation Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 5/7] clone: validate --origin option before use Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 6/7] clone: read new remote name from remote_name instead of option_origin Sean Barag via GitGitGadget
2020-09-29 3:36 ` [PATCH v2 7/7] clone: allow configurable default for `-o`/`--origin` Sean Barag via GitGitGadget
2020-09-29 19:59 ` Junio C Hamano
2020-09-29 23:47 ` [PATCH] clone: add remote.cloneDefault config option Sean Barag
2020-09-29 3:44 ` [PATCH v2 0/7] clone: allow configurable default for -o/--origin Sean Barag
2020-10-01 3:46 ` [PATCH v3 " Sean Barag via GitGitGadget
2020-10-01 3:46 ` [PATCH v3 1/7] clone: add tests for --template and some disallowed option pairs Sean Barag via GitGitGadget
2020-10-01 3:46 ` [PATCH v3 2/7] clone: use more conventional config/option layering Sean Barag via GitGitGadget
2020-10-01 3:46 ` [PATCH v3 3/7] remote: add tests for add and rename with invalid names Sean Barag via GitGitGadget
2020-10-01 3:46 ` Sean Barag via GitGitGadget [this message]
2020-10-01 3:46 ` [PATCH v3 5/7] clone: validate --origin option before use Sean Barag via GitGitGadget
2020-10-01 3:46 ` [PATCH v3 6/7] clone: read new remote name from remote_name instead of option_origin Sean Barag via GitGitGadget
2020-10-01 3:46 ` [PATCH v3 7/7] clone: allow configurable default for `-o`/`--origin` Sean Barag via GitGitGadget
2020-10-02 12:56 ` [PATCH v3 0/7] clone: allow configurable default for -o/--origin Derrick Stolee
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=cb686b4129902335ef98c83c8cfbcac1c88da856.1601523977.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=me@ttaylorr.com \
--cc=peff@peff.net \
--cc=rybak.a.v@gmail.com \
--cc=sean@barag.org \
--cc=stolee@gmail.com \
--cc=sunshine@sunshineco.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.
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).