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

Re: [PATCH v3 1/4] replace: add --graft option

From
Jeff King <peff@peff.net>
Date
Jun 8, 2014, 11:23 UTC
Message-ID
<20140608112333.GA9691@sigill.intra.peff.net>
In-Reply-To
<CAP8UFD344NFECqtO-uK-2wHA7XEko3XMJWuhW9+KGBdaiqGq+w@mail.gmail.com>
On Sun, Jun 08, 2014 at 08:49:45AM +0200, Christian Couder wrote:
Show 8 quoted lines
> On Fri, Jun 6, 2014 at 5:44 PM, Christian Couder
> <christian.couder@gmail.com> wrote:
> >
> >         /* find existing parents */
> >         strbuf_addstr(&buf, commit->buffer);
> 
> Unfortunately, it looks like the above will not work if the commit->buffer
> contains an embedded NUL. I wonder if it is a real problem or not.

I ran into a similar problem recently[1] and have been pondering solutions to know the size of commit->buffer. What I've been come up with is:

  1. Look up the object size via sha1_object_info. Besides being
     inefficient (which probably does not matter for you here, but might
     for using commit->buffer in a traversal), it strikes me as
     inelegant; is it possible for commit->buffer to ever disagree in
     size with the results of sha1_object_info, and if so, what happens?
  2. Add an extra member "len" to "struct commit". This is simple, but
     bloats "struct commit", which may have a performance impact for
     things like rev-list, where the field will be unused.
  3. Store the length of objects as a size_t, exactly sizeof(size_t)
     bytes before the object buffer. Provide a macro:
       #define OBJECT_SIZE(buf) (((size_t *)(buf))[-1])
     to access it. Most callers can just use the buffer as-is, but
     anybody who calls free() would need to be adjusted to use a special
     "object_free".
  4. Keep a static commit_slab that points to the length for each parsed
     commit. We pay the same memory cost as (2), but as it's not part of
     the struct, the cache effects are minimized.
-Peff
[1] http://article.gmane.org/gmane.comp.version-control.git/250480
Previous: Christian CouderNext: Jeff King
Message 7 of 19 in “Add --graft option to git replace”
  1. 0/4 Add --graft option to git replaceChristian Couder, Jun 4, 2014
  2. 1/4 replace: add --graft optionChristian Couder, Jun 4, 2014
  3. Junio C HamanoJun 5, 2014
  4. Christian CouderJun 6, 2014
  5. Christian CouderJun 6, 2014
  6. Christian CouderJun 8, 2014
  7. Jeff KingJun 8, 2014
  8. Jeff KingJun 8, 2014
  9. Jeff KingJun 8, 2014
  10. Junio C HamanoJun 9, 2014
  11. Junio C HamanoJun 6, 2014
  12. 2/4 replace: add test for --graftChristian Couder, Jun 4, 2014
  13. 3/4 Documentation: replace: add --graft optionChristian Couder, Jun 4, 2014
  14. 4/4 contrib: add convert-grafts-to-replace-refs.shChristian Couder, Jun 4, 2014
  15. Junio C HamanoJun 5, 2014
  16. Christian CouderJun 6, 2014
  17. Christian CouderJun 29, 2014
  18. Junio C HamanoJun 30, 2014
  19. Christian CouderJun 30, 2014

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.