refs: consolidate remote name validation

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Sean Barag
2020-10-01 03:46:13 +00:00
committed by Junio C Hamano
parent 444825c7c1
commit f2c6fda886
3 changed files with 13 additions and 5 deletions

View File

@ -201,6 +201,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)
{