Re: [PATCH] sha1_name: support sha1^{note} to return note sha-1
- From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
- Date
- May 9, 2012, 08:25 UTC
- Message-ID
- <CACsJy8AfD-N6L6nZNDG3uw4s6jAdYqkuQ8Jt2XRXRGzRwt1ncQ@mail.gmail.com>
- In-Reply-To
- <20120508161126.GB26838@sigill.intra.peff.net>
On Tue, May 8, 2012 at 11:11 PM, Jeff King <peff@peff.net> wrote:
Show 13 quoted lines
> On Tue, May 08, 2012 at 08:14:30PM +0700, Nguyen Thai Ngoc Duy wrote:
>
>> It may be useful for scripting, and looks nice. Though may be not
>> worth adding if there are no actual users.
>
> There can be many notes refs. So I think to do this right, you would
> want something like:
>
> foo^{note:bar}
>
> which would look in refs/notes/bar (this logic is handled by
> expand_notes_ref). And "foo^{note}" would be a synonym for the default
> note ref.Right. Thanks.
Show 23 quoted lines
>> @@ -473,7 +474,19 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
>> expected_type = OBJ_NONE;
>> else if (sp[0] == '/')
>> expected_type = OBJ_COMMIT;
>> - else
>> + else if (!strncmp("note}", sp, 5)) {
>> + const unsigned char *note;
>> + struct notes_tree t;
>> + if (get_sha1_1(name, sp - name - 2, outer))
>> + return -1;
>> + memset(&t, 0, sizeof(t));
>> + init_notes(&t, NULL, NULL, 0);
>> + note = get_note(&t, outer);
>> + if (note)
>> + hashcpy(sha1, note);
>> + free_notes(&t);
>> + return note ? 0 : -1;
>> + } else
>
> The notes code is relatively expensive to initialize, with the
> assumption that the effort will be amortized across multiple lookups
> (which are made faster). Is it possible to cache this initialized notes
> structure in case many lookups are done?No idea. I have never worked/used notes until yesterday (and these patches were the result). I will look into it.
> It may not be as important as it used to be, either. I think more recent > versions of the code will progressively load the notes tree rather than > filling it all in at initialization time. But it has been a while since > I've done anything with notes.
-- Duy