Brandon Williams <[email protected]> writes:
> - /* Find common prefix for all pathspec's */
> - max_prefix = common_prefix(&pathspec);
> + /*
> + * Find common prefix for all pathspec's
> + * This is used as a performance optimization which unfortunately cannot
> + * be done when recursing into submodules
> + */
> + if (recurse_submodules)
> + max_prefix = NULL;
> + else
> + max_prefix = common_prefix(&pathspec);
> max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
This is OK for now, but for a future enhancement, I think we could
do better than this. In a superproject with a submodule at "sub/",
the current implementation of the common_prefix() helper would yield
"sub/a/" when given "sub/a/x" and "sub/a/y" (a pathspec with two
elements), which we want to avoid.
But somebody should be able to notice, before "sub/a/" is given to
max_prefix here, that "sub/" is the leaf level in our repository and
reduce the max_prefix to it. dir.c::common_prefix_len() might be
a place we could do so, but I didn't think about the ramifications
of doing so for other callers of common_prefix() or when we are not
recursing into submodules. Doing it in the caller here, i.e.
max_prefix = common_prefix(&pathspec);
if (recurse_submodules)
max_prefix = chomp_at_submodule_boundary(max_prefix);
is certainly safer.
If the superproject has submodules at "a/b/{sub1,sub2,...}", this
matters more. We do want to notice that we won't have to scan
outside "a/b/" of the index given "a/b/sub1" and "a/b/sub2" as a
pathspec.
The common_prefix_len() function also looks beyond symbolic links,
which is another thing that we may want to think about. In a
repository with a symbolic link "link" pointing somewhere else, when
you give "link/a/x" and "link/a/y" (a pathspec with two elements),
we would get "link/a/" as a common prefix, but we won't find
anything underneath "link" in our index. In such a case, leaving
the common prefix to "link/a/" _might_ allow us to notice that no
pathspec elements can ever match, so not noticing that the common
prefix points beyond a symbolic link might be a feature. I dunno.