From: Jeff King <peff@peff.net>
To: mhagger@alum.mit.edu
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] create_ref_entry(): move check_refname_format() call to callers
Date: Sun, 29 Apr 2012 07:58:31 -0400 [thread overview]
Message-ID: <20120429115831.GC24254@sigill.intra.peff.net> (raw)
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:
> 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
next prev parent reply other threads:[~2012-04-29 11:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-29 6:18 [PATCH] create_ref_entry(): move check_refname_format() call to callers mhagger
2012-04-29 11:58 ` Jeff King [this message]
2012-04-30 6:15 ` Junio C Hamano
2012-04-30 16:18 ` Michael Haggerty
2012-04-30 17:14 ` Junio C Hamano
2012-04-30 20:29 ` Michael Haggerty
2012-04-30 21:11 ` Junio C Hamano
2012-05-02 15:38 ` Michael Haggerty
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=20120429115831.GC24254@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
/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).