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

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
Previous: Jeff KingNext: Johan Herland
Message 3 of 5 in “sha1_name: support sha1^{note} to return note sha-1”
  1. sha1_name: support sha1^{note} to return note sha-1Nguyễn Thái Ngọc Duy, May 8, 2012
  2. Jeff KingMay 8, 2012
  3. Nguyen Thai Ngoc DuyMay 9, 2012
  4. Johan HerlandMay 9, 2012
  5. Jeff KingMay 9, 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.