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

Re: [PATCH] Make object contents optionally available

From
Junio C Hamano <junkio@cox.net>
Date
May 17, 2005, 17:12 UTC
Message-ID
<7vfywlhj3h.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.21.0505171130460.30848-100000@iabervon.org>
>>>>> "DB" == Daniel Barkalow <barkalow@iabervon.org> writes:

DB> I'm already going to add a per-type global to have the parse functions DB> also unpack the object contents user-visibly, for the case that Junio DB> pointed out. (Making it: parse_* doesn't change whether the contents are DB> unpacked, unless you tell it to unpack objects.)

That sounds better than the patch you sent last night, but are we sure that callers would be satisfied if you just make some _types_ more special than others?

Parse functions need to unpack anyway, so it might make more sense to add an optional callback just after where unpacking happens to ask the main program if it wants the unpacked raw data to be kept. So you would do something like:

    struct object *parse_object(unsigned char *sha1)
    {
   ...
                    unsigned long size;
                    void *buffer = unpack_sha1_file(map, mapsize, type, &size);
                    munmap(map, mapsize);
                    if (!buffer)
                            return NULL;
   ...             
                    } else {
                            obj = NULL;
                    }
+		    if (obj && keep_object_raw_data(sha1, type, size, buffer)) {
+                           obj.raw_data = buffer;
+                           obj.raw_size = size;
+                   } else 
                            free(buffer);
                    return obj;
            }
            return NULL;
    }

And put a dummy implementation of keep_object_raw_data() that says "I do not want anything to be kept" in the libgit.a. Main programs that _care_ about raw data can implement their own keep_object_raw_data() callback that is more intelligent. In addition you give them the interface to free raw data you already have.

DB> I think the only likely bug would be unpacking objects after parsing DB> them, instead of before, which is correct but inefficient. It should be DB> clear to a user whether the raw contents are available at any point in the DB> user code.

Another possibility is not to make double unpacking too costly by having an LRU of unpack_sha1_file(), but I am not sure how effective that would be.

Previous: Daniel BarkalowNext: Daniel Barkalow
Message 4 of 7 in “Make object contents optionally available”
  1. Make object contents optionally availableDaniel Barkalow, May 17, 2005
  2. Linus TorvaldsMay 17, 2005
  3. Daniel BarkalowMay 17, 2005
  4. Junio C HamanoMay 17, 2005
  5. Daniel BarkalowMay 17, 2005
  6. Junio C HamanoMay 17, 2005
  7. Daniel BarkalowMay 17, 2005

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.