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 /setup.c | |
parent | 3503b8d0da61d920ebd9294fd6a9a0f758328fd3 (diff) | |
download | git-8894d5358095a08c2f700a87ce9fdefb0b6eb61b.tar.gz |
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 'setup.c')
-rw-r--r-- | setup.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -264,6 +264,38 @@ const char **get_pathspec(const char *prefix, const char **pathspec) return pathspec; } +const char *pathspec_prefix(const char *prefix, const char **pathspec) +{ + const char **p, *n, *prev; + unsigned long max; + + if (!pathspec) + return prefix ? xmemdupz(prefix, strlen(prefix)) : NULL; + + prev = NULL; + max = PATH_MAX; + for (p = pathspec; (n = *p) != NULL; p++) { + int i, len = 0; + for (i = 0; i < max; i++) { + char c = n[i]; + if (prev && prev[i] != c) + break; + if (!c || c == '*' || c == '?') + break; + if (c == '/') + len = i+1; + } + prev = n; + if (len < max) { + max = len; + if (!max) + break; + } + } + + return max ? xmemdupz(prev, max) : NULL; +} + /* * Test if it looks like we're at a git directory. * We want to see: |