commit: allow partial commits with relative paths

In order to do partial commits, git-commit overlays a tree on the
cache and checks pathspecs against the result. Currently, the
overlaying is done using "prefix" which prevents relative pathspecs
with ".." and absolute pathspec from matching when they refer to
files not under "prefix" and absent from the index, but still in
the tree (i.e.  files staged for removal).

The point of providing a prefix at all is performance optimization.
If we say there is no common prefix for the files of interest, then
we have to read the entire tree into the index.

But even if we cannot use the working directory as a prefix, we can
still figure out if there is a common prefix for all given paths,
and use that instead. The pathspec_prefix() routine from ls-files.c
does exactly that.

Any use of global variables is removed from pathspec_prefix() so
that it can be called from commit.c.

Reported-by: Reuben Thomas <rrt@sc3d.org>
Analyzed-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Clemens Buchacher
2011-07-30 19:13:47 +02:00
committed by Junio C Hamano
parent 3503b8d0da
commit 8894d53580
4 changed files with 39 additions and 38 deletions

View File

@ -256,8 +256,10 @@ static int list_paths(struct string_list *list, const char *with_tree,
;
m = xcalloc(1, i);
if (with_tree)
overlay_tree_on_cache(with_tree, prefix);
if (with_tree) {
const char *max_prefix = pathspec_prefix(prefix, pattern);
overlay_tree_on_cache(with_tree, max_prefix);
}
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i];