git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] refs: disallow ref components starting with hyphen

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 16, 2012, 17:06 UTC
Message-ID
<7v7gu34ow0.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1342440781-18816-2-git-send-email-mschub@elegosoft.com>
Michael Schubert <mschub@elegosoft.com> writes:
> Currently, we allow refname components to start with a hyphen. There's
> no good reason to do so...

That is way too weak as a justification to potentially break existing repositories.

Refusal upon attempted creation is probably OK, which is why the two checks you removed in your patches are fine. I do not know if it is justifiable to do that in check_refname_component() that is used in the reading codepath.

Show 40 quoted lines
> diff --git a/builtin/tag.c b/builtin/tag.c
> index 7b1be85..c99fb42 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -403,9 +403,6 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
>  
>  static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
>  {
> -	if (name[0] == '-')
> -		return -1;
> -
>  	strbuf_reset(sb);
>  	strbuf_addf(sb, "refs/tags/%s", name);
>  
> diff --git a/refs.c b/refs.c
> index da74a2b..5714681 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -62,6 +62,8 @@ static int check_refname_component(const char *refname, int flags)
>  		if (refname[1] == '\0')
>  			return -1; /* Component equals ".". */
>  	}
> +	if (refname[0] == '-')
> +		return -1; /* Component starts with '-'. */
>  	if (cp - refname >= 5 && !memcmp(cp - 5, ".lock", 5))
>  		return -1; /* Refname ends with ".lock". */
>  	return cp - refname;
> diff --git a/sha1_name.c b/sha1_name.c
> index 5d81ea0..132d369 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -892,8 +892,6 @@ int strbuf_branchname(struct strbuf *sb, const char *name)
>  int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
>  {
>  	strbuf_branchname(sb, name);
> -	if (name[0] == '-')
> -		return -1;
>  	strbuf_splice(sb, 0, 0, "refs/heads/", 11);
>  	return check_refname_format(sb->buf, 0);
>  }
Previous: Michael HaggertyNext: Junio C Hamano
Message 4 of 8 in “refname format cleanup”
  1. refname format cleanupMichael Schubert, Jul 16, 2012
  2. 1/2 refs: disallow ref components starting with hyphenMichael Schubert, Jul 16, 2012
  3. Michael HaggertyJul 16, 2012
  4. Junio C HamanoJul 16, 2012
  5. Junio C HamanoJul 16, 2012
  6. 2/2 symbolic-ref: check format of given refnameMichael Schubert, Jul 16, 2012
  7. Michael HaggertyJul 16, 2012
  8. Junio C HamanoJul 16, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.