git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elia Pinto <gitter.spiros@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Michael Haggerty <mhagger@alum.mit.edu>,
	Jeff King <peff@peff.net>, Git Mailing List <git@vger.kernel.org>
Subject: Re: Bug in "git rev-parse --verify"
Date: Sat, 30 Mar 2013 09:14:02 +0100	[thread overview]
Message-ID: <CA+EOSBnXPgLhaCgDp5t94eFUXxiA-iufuJR8KCCvOTgczLCtWw@mail.gmail.com> (raw)
In-Reply-To: <7vhajtpdtc.fsf@alter.siamese.dyndns.org>

Fwiw, look very a sound idea for me.

Best

2013/3/30, Junio C Hamano <gitster@pobox.com>:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> What we may want is another type peeling operator, ^{object}.
>> that makes sure it is an object, like this:
>>
>>     rev-parse --verify 572a535454612a046e7dd7404dcca94d6243c788^{object}
>>
>> It asks "I have this 40-hex; I want an object out of it", just like
>> frotz^{tree} is "I have 'frotz'; I want a tree-ish" for any value of
>> 'frotz'.
>>
>> With that, a use case that it wants to see _any_ object can safely
>> use 'rev-parse --verify "$userinput^{object}' without an annotated
>> tag getting in the way.
>>
>> How does that sound?
>
> Perhaps something like this.  Note that the last hunk is unrelated
> thinko-fix I noticed while browsing the code.
>
> -- >8 --
> Subject: sha1_name.c: ^{object} peeler
>
> A string that names an object can be suffixed with ^{type} peeler to
> say "I have this object name; peel it until you get this type. If
> you cannot do so, it is an error".  v1.8.2^{commit} asks for a commit
> that is pointed at an annotated tag v1.8.2; v1.8.2^{tree} unwraps it
> further to the top-level tree object.  A special suffix ^{} (i.e. no
> type specified) means "I do not care what it unwraps to; just peel
> annotated tag until you get something that is not a tag".
>
> When you have a random user-supplied string, you can turn it to a
> bare 40-hex object name, and cause it to error out if such an object
> does not exist, with:
>
> 	git rev-parse --verify "$userstring^{}"
>
> for most objects, but this does not yield the tag object name when
> $userstring refers to an annotated tag.
>
> Introduce a new suffix, ^{object}, that only makes sure the given
> name refers to an existing object.  Then
>
> 	git rev-parse --verify "$userstring^{object}"
>
> becomes a way to make sure $userstring refers to an existing object.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  sha1_name.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index c50630a..85b6e75 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -594,7 +594,7 @@ struct object *peel_to_type(const char *name, int
> namelen,
>  	while (1) {
>  		if (!o || (!o->parsed && !parse_object(o->sha1)))
>  			return NULL;
> -		if (o->type == expected_type)
> +		if (expected_type == OBJ_ANY || o->type == expected_type)
>  			return o;
>  		if (o->type == OBJ_TAG)
>  			o = ((struct tag*) o)->tagged;
> @@ -645,6 +645,8 @@ static int peel_onion(const char *name, int len,
> unsigned char *sha1)
>  		expected_type = OBJ_TREE;
>  	else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
>  		expected_type = OBJ_BLOB;
> +	else if (!prefixcmp(sp, "object}"))
> +		expected_type = OBJ_ANY;
>  	else if (sp[0] == '}')
>  		expected_type = OBJ_NONE;
>  	else if (sp[0] == '/')
> @@ -654,6 +656,8 @@ static int peel_onion(const char *name, int len,
> unsigned char *sha1)
>
>  	if (expected_type == OBJ_COMMIT)
>  		lookup_flags = GET_SHA1_COMMITTISH;
> +	else if (expected_type == OBJ_TREE)
> +		lookup_flags = GET_SHA1_TREEISH;
>
>  	if (get_sha1_1(name, sp - name - 2, outer, lookup_flags))
>  		return -1;
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
Inviato dal mio dispositivo mobile

  parent reply	other threads:[~2013-03-30  8:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 13:04 Bug in "git rev-parse --verify" Michael Haggerty
2013-03-28 14:05 ` Jeff King
2013-03-28 14:55   ` Junio C Hamano
     [not found] ` <CAPc5daUqzz=9TBmj2Q0MHqEc6gMHxXoGr9+JV3hq76zDKJAyCw@mail.gmail.com>
2013-03-28 15:34   ` Michael Haggerty
2013-03-28 15:38     ` Jeff King
2013-03-28 15:52       ` Michael Haggerty
2013-03-28 16:38         ` Jeff King
2013-03-28 16:52       ` Junio C Hamano
2013-03-30  3:44         ` Michael Haggerty
2013-03-30  4:09           ` Junio C Hamano
2013-03-30  4:15             ` Junio C Hamano
2013-03-30  5:29             ` Michael Haggerty
2013-03-30  6:38               ` Junio C Hamano
2013-03-30  7:05                 ` Junio C Hamano
2013-03-30  8:09                   ` Michael Haggerty
2013-03-30  8:14                   ` Elia Pinto [this message]
2013-03-31 22:38                   ` [PATCH 1/2] peel_onion: disambiguate to favor tree-ish when we want a tree-ish Junio C Hamano
2013-03-31 22:38                   ` [PATCH 2/2] peel_onion(): teach $foo^{object} peeler Junio C Hamano
2013-04-02  8:20                     ` Michael Haggerty
2013-04-02 15:45                       ` Junio C Hamano
2013-04-02 16:32                         ` Michael Haggerty
2013-04-02 16:56                           ` Junio C Hamano

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=CA+EOSBnXPgLhaCgDp5t94eFUXxiA-iufuJR8KCCvOTgczLCtWw@mail.gmail.com \
    --to=gitter.spiros@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    --cc=peff@peff.net \
    /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).