]> git.ipfire.org Git - thirdparty/git.git/commit - unpack-trees.c
unpack-trees: support super-prefix option
authorStefan Beller <sbeller@google.com>
Wed, 18 Jan 2017 01:05:20 +0000 (17:05 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Jan 2017 20:33:33 +0000 (12:33 -0800)
commit3d415425c7b6ca0d2243a4589672369e7a02fc2c
tree5203ddee03812e782602830b3f8862ce62a84900
parent83587d5236cbb4f45d6c0c551d0f0669ba25b176
unpack-trees: support super-prefix option

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 74866d757, 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: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git.c
t/t1001-read-tree-m-2way.sh
unpack-trees.c