diff options
author | Clemens Buchacher <drizzd@aon.at> | 2011-07-30 19:13:47 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-02 14:20:35 -0700 |
commit | 8894d5358095a08c2f700a87ce9fdefb0b6eb61b (patch) | |
tree | 9bb41b5eba638c33b61acb7041817c6b129c0796 /builtin/commit.c | |
parent | 3503b8d0da61d920ebd9294fd6a9a0f758328fd3 (diff) | |
download | git-8894d5358095a08c2f700a87ce9fdefb0b6eb61b.tar.gz git-8894d5358095a08c2f700a87ce9fdefb0b6eb61b.tar.xz |
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>
Diffstat (limited to 'builtin/commit.c')
-rw-r--r-- | builtin/commit.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index e1af9b19f..cb738574f 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -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]; |