Skip to content
  • Jeff King's avatar
    get_sha1_with_context: dynamically allocate oc->path · dc944b65
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    When a sha1 lookup returns the tree path via "struct
    object_context", it just copies it into a fixed-size buffer.
    This means the result can be truncated, and it means our
    "struct object_context" consumes a lot of stack space.
    
    Instead, let's allocate a string on the heap. Because most
    callers don't care about this information, we'll avoid doing
    it by default (so they don't all have to start calling
    free() on the result). There are basically two options for
    the caller to signal to us that it's interested:
    
      1. By setting a pointer to storage in the object_context.
    
      2. By passing a flag in another parameter.
    
    Doing (1) would match the way that sha1_object_info_extended()
    works. But it would mean that every caller would have to
    initialize the object_context, which they don't currently
    have to do.
    
    This patch does (2), and adds a new bit to the function's
    flags field. All of the callers that look at the "path"
    field are updated to pass the new flag.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    dc944b65