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

Re: [PATCH] create_ref_entry(): move check_refname_format() call to callers

From
Jeff King <peff@peff.net>
Date
Apr 29, 2012, 11:58 UTC
Message-ID
<20120429115831.GC24254@sigill.intra.peff.net>
In-Reply-To
<1335680288-5128-1-git-send-email-mhagger@alum.mit.edu>
On Sun, Apr 29, 2012 at 08:18:08AM +0200, mhagger@alum.mit.edu wrote:
Show 8 quoted lines
> I will work on providing more infrastructure for checking refnames at
> varying levels of strictness, but I don't know enough about the code
> paths to be able to find the places where the strictness levels need
> tweaking.
> 
> For this to work, the various callers of check_refname_format() will
> have to be able to influence the level of strictness that they want to
> enforce.  This patch is one trivial step in that direction.

It seems like the create_ref_entry code paths should _always_ just be issuing warnings, as they are about reading existing refs, no? The die() side should only come when we are writing refs.

So something like this patch:
diff --git a/refs.c b/refs.c
index a5802e1..3dba205 100644
--- a/refs.c
+++ b/refs.c
@@ -180,7 +180,7 @@ static struct ref_entry *create_ref_entry(const char *refname,
 
 	if (check_name &&
 	    check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
-		die("Reference has invalid format: '%s'", refname);
+		warning("Reference has invalid format: '%s'", refname);
 	len = strlen(refname) + 1;
 	ref = xmalloc(sizeof(struct ref_entry) + len);
 	hashcpy(ref->u.value.sha1, sha1);
@@ -926,7 +926,7 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
 	if (flag)
 		*flag = 0;
 
-	if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
+	if (!reading && check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
 		return NULL;
 
 	for (;;) {

which gives me the following behavior on the snippet I posted earlier:

  $ git fsck
  warning: Reference has invalid format: 'refs/tags/foo^?bar'

  $ git rev-parse --verify "$evil"
  711078d8c4c0d26b02afee9f385a64455fe4cccd

  $ git for-each-ref
  warning: Reference has invalid format: 'refs/tags/foo^?bar'
  711078d8c4c0d26b02afee9f385a64455fe4cccd commit refs/heads/master
  711078d8c4c0d26b02afee9f385a64455fe4cccd commit refs/tags/foobar

  $ git tag -l
  warning: Reference has invalid format: 'refs/tags/foo^?bar'
  foo^?bar

  $ git tag fixed "$evil"
  warning: Reference has invalid format: 'refs/tags/foo^?bar'
  $ git rev-parse fixed
  711078d8c4c0d26b02afee9f385a64455fe4cccd
  $ git tag -d "$evil"
  Deleted tag 'foo^?bar' (was 711078d)

-Peff
Previous: mhagger@alum.mit.eduNext: Junio C Hamano
Message 2 of 8 in “create_ref_entry(): move check_refname_format() call to callers”
  1. create_ref_entry(): move check_refname_format() call to callersmhagger@alum.mit.edu, Apr 29, 2012
  2. Jeff KingApr 29, 2012
  3. Junio C HamanoApr 30, 2012
  4. Michael HaggertyApr 30, 2012
  5. Junio C HamanoApr 30, 2012
  6. Michael HaggertyApr 30, 2012
  7. Junio C HamanoApr 30, 2012
  8. Michael HaggertyMay 2, 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.