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
Johan Herland <johan@herland.net>
Date
May 9, 2012, 14:09 UTC
Message-ID
<CALKQrgdGCoKooM7KayNMQ_+Fg9=-1YnwNE_9NHzpX0jfoRjT_A@mail.gmail.com>
In-Reply-To
<CACsJy8AfD-N6L6nZNDG3uw4s6jAdYqkuQ8Jt2XRXRGzRwt1ncQ@mail.gmail.com>
On Wed, May 9, 2012 at 10:25 AM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
Show 28 quoted lines
> On Tue, May 8, 2012 at 11:11 PM, Jeff King <peff@peff.net> wrote:
>> On Tue, May 08, 2012 at 08:14:30PM +0700, Nguyen Thai Ngoc Duy wrote:
>>> @@ -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.

IIRC, the initialization loads the top-level notes tree object into memory. Subtrees (if any) are loaded on demand. FTR, if you have less then ~256 notes in the notes tree, there will be no subtrees. As the number of notes grows, the number of subtree levels grow roughly logarithmically with the total number of notes (see determine_fanout() for more details).

...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Previous: Nguyen Thai Ngoc DuyNext: Jeff King
Message 4 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.