Skip to content
  • Stefan Beller's avatar
    unpack-trees: support super-prefix option · 3d415425
    Stefan Beller authored and Junio C Hamano's avatar Junio C Hamano committed
    In the future we want to support working tree operations within submodules,
    e.g. "git checkout --recurse-submodules", which will update the submodule
    to the commit as recorded in its superproject. In the submodule the
    unpack-tree operation is carried out as usual, but the reporting to the
    user needs to prefix any path with the superproject. The mechanism for
    this is the super-prefix. (see 74866d75
    
    , git: make super-prefix option)
    
    Add support for the super-prefix option for commands that unpack trees
    by wrapping any path output in unpacking trees in the newly introduced
    super_prefixed function. This new function prefixes any path with the
    super-prefix if there is one.  Assuming the submodule case doesn't happen
    in the majority of the cases, we'd want to have a fast behavior for no
    super prefix, i.e. no reallocation/copying, but just returning path.
    
    Another aspect of introducing the `super_prefixed` function is to consider
    who owns the memory and if this is the right place where the path gets
    modified. As the super prefix ought to change the output behavior only and
    not the actual unpack tree part, it is fine to be that late in the line.
    As we get passed in 'const char *path', we cannot change the path itself,
    which means in case of a super prefix we have to copy over the path.
    We need two static buffers in that function as the error messages
    contain at most two paths.
    
    For testing purposes enable it in read-tree, which has no output
    of paths other than an unpack-trees.c. These are all converted in
    this patch.
    
    Signed-off-by: default avatarStefan Beller <sbeller@google.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    3d415425