* [PATCH] commit: allow partial commits with relative paths @ 2018-04-03 17:57 Brandon Williams 0 siblings, 0 replies; 5+ messages in thread From: Brandon Williams @ 2018-04-03 17:57 UTC (permalink / raw) To: git, bmwill; +Cc: Brandon Williams Commit 8894d53580 (commit: allow partial commits with relative paths, 2011-07-30) ensured that partial commits were allowed when a user supplies a relative pathspec but then this was regressed in 5879f5684c (remove prefix argument from pathspec_prefix, 2011-09-04) when the prefix argument to 'pathspec_prefix' removed and the 'list_paths' function wasn't properly adjusted to cope with the change, resulting in over-eager pruning of the tree that is overlayed on the index. This fixes the regression and adds a regression test so this can be prevented in the future. Signed-off-by: Brandon Williams <bmwill@google.com> --- builtin/commit.c | 3 +-- t/t7501-commit.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 37fcb55ab0..5571d4a3e2 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -218,8 +218,7 @@ static int list_paths(struct string_list *list, const char *with_tree, if (with_tree) { char *max_prefix = common_prefix(pattern); - overlay_tree_on_index(&the_index, with_tree, - max_prefix ? max_prefix : prefix); + overlay_tree_on_index(&the_index, with_tree, max_prefix); free(max_prefix); } diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index fa61b1a4ee..9dbbd01fc0 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -52,6 +52,18 @@ test_expect_success PERL 'can use paths with --interactive' ' git reset --hard HEAD^ ' +test_expect_success 'removed files and relative paths' ' + test_when_finished "rm -rf foo" && + git init foo && + >foo/foo.txt && + git -C foo add foo.txt && + git -C foo commit -m first && + git -C foo rm foo.txt && + + mkdir -p foo/bar && + git -C foo/bar commit -m second ../foo.txt +' + test_expect_success 'using invalid commit with -C' ' test_must_fail git commit --allow-empty -C bogus ' -- 2.17.0.rc1.321.gba9d0f2565-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Possible bug @ 2011-07-23 20:25 Reuben Thomas 2011-07-25 7:42 ` [RFC/PATCH] commit: allow partial commits with relative paths Michael J Gruber 0 siblings, 1 reply; 5+ messages in thread From: Reuben Thomas @ 2011-07-23 20:25 UTC (permalink / raw) To: git Observe the following exchange with git 1.7.4.1, which I found rather perplexing: $ cat ~/reportbug-git $ git rm -f ../INSTALL rm 'INSTALL' $ git ci -m "INSTALL is now provided by gnulib." ../INSTALL error: pathspec 'ALL' did not match any file(s) known to git. $ cd .. $ git ci -m "INSTALL is now provided by gnulib." INSTALL [master 0895314] INSTALL is now provided by gnulib. 1 files changed, 0 insertions(+), 1 deletions(-) delete mode 120000 INSTALL Is this a bug, or merely some magic I don't know about? -- http://rrt.sc3d.org ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC/PATCH] commit: allow partial commits with relative paths 2011-07-23 20:25 Possible bug Reuben Thomas @ 2011-07-25 7:42 ` Michael J Gruber 2011-07-29 13:35 ` [PATCH] " Clemens Buchacher 0 siblings, 1 reply; 5+ messages in thread From: Michael J Gruber @ 2011-07-25 7:42 UTC (permalink / raw) To: git; +Cc: Reuben Thomas 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). Overlay the full tree instead. Reported-by: Reuben Thomas <rrt@sc3d.org> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> --- RFC because lack of test, and also because I'm not sure we want this, and what to do about git add which has the same problem, but would need a different fix. --- builtin/commit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index e1af9b1..431590c 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -257,7 +257,7 @@ 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); + overlay_tree_on_cache(with_tree, NULL); for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; -- 1.7.6.336.gdf067 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] commit: allow partial commits with relative paths 2011-07-25 7:42 ` [RFC/PATCH] commit: allow partial commits with relative paths Michael J Gruber @ 2011-07-29 13:35 ` Clemens Buchacher 2011-07-30 16:45 ` Michael J Gruber 0 siblings, 1 reply; 5+ messages in thread From: Clemens Buchacher @ 2011-07-29 13:35 UTC (permalink / raw) To: Michael J Gruber; +Cc: git, Reuben Thomas, Junio C Hamano 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). Instead, determine the maximal common prefix for all specified paths using the pathspec_prefix() routine from ls-files.c. 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> On Mon, Jul 25, 2011 at 09:42:10AM +0200, Michael J Gruber wrote: > > Overlay the full tree instead. That is one option. On the other hand, ls-files already provides the function we need to do this properly. With your permission I am stealing your commit message. Clemens --- builtin/commit.c | 6 ++++-- builtin/ls-files.c | 38 ++------------------------------------ cache.h | 1 + setup.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index a16d00b..c2db12a 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]; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 72b986f..fef5642 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -276,41 +276,6 @@ static void prune_cache(const char *prefix) active_nr = last; } -static const char *pathspec_prefix(const char *prefix) -{ - const char **p, *n, *prev; - unsigned long max; - - if (!pathspec) { - max_prefix_len = prefix ? strlen(prefix) : 0; - return prefix; - } - - 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; - } - } - - max_prefix_len = max; - return max ? xmemdupz(prev, max) : NULL; -} - static void strip_trailing_slash_from_submodules(void) { const char **p; @@ -581,7 +546,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) strip_trailing_slash_from_submodules(); /* Find common prefix for all pathspec's */ - max_prefix = pathspec_prefix(prefix); + max_prefix = pathspec_prefix(prefix, pathspec); + max_prefix_len = max_prefix ? strlen(max_prefix) : 0; /* Treat unmatching pathspec elements as errors */ if (pathspec && error_unmatch) { diff --git a/cache.h b/cache.h index 86518fb..dd3edaa 100644 --- a/cache.h +++ b/cache.h @@ -441,6 +441,7 @@ extern void set_git_work_tree(const char *tree); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" extern const char **get_pathspec(const char *prefix, const char **pathspec); +extern const char *pathspec_prefix(const char *prefix, const char **pathspec); extern void setup_work_tree(void); extern const char *setup_git_directory_gently(int *); extern const char *setup_git_directory(void); diff --git a/setup.c b/setup.c index 5ea5502..2c51a9a 100644 --- a/setup.c +++ b/setup.c @@ -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: -- 1.7.3.1.105.g84915 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] commit: allow partial commits with relative paths 2011-07-29 13:35 ` [PATCH] " Clemens Buchacher @ 2011-07-30 16:45 ` Michael J Gruber 2011-07-30 17:00 ` Clemens Buchacher 0 siblings, 1 reply; 5+ messages in thread From: Michael J Gruber @ 2011-07-30 16:45 UTC (permalink / raw) To: Clemens Buchacher; +Cc: git, Reuben Thomas, Junio C Hamano Clemens Buchacher venit, vidit, dixit 29.07.2011 15:35: > 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). > > Instead, determine the maximal common prefix for all specified > paths using the pathspec_prefix() routine from ls-files.c. 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> > > On Mon, Jul 25, 2011 at 09:42:10AM +0200, Michael J Gruber wrote: >> >> Overlay the full tree instead. > > That is one option. On the other hand, ls-files already provides > the function we need to do this properly. > How is this huge patch more "proper" then what I proposed? > With your permission I am stealing your commit message. I don't care about the message but don't see the point of this patch. Using the same message certainly won't explain the difference... > > Clemens > --- > builtin/commit.c | 6 ++++-- > builtin/ls-files.c | 38 ++------------------------------------ > cache.h | 1 + > setup.c | 32 ++++++++++++++++++++++++++++++++ > 4 files changed, 39 insertions(+), 38 deletions(-) > > diff --git a/builtin/commit.c b/builtin/commit.c > index a16d00b..c2db12a 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]; > diff --git a/builtin/ls-files.c b/builtin/ls-files.c > index 72b986f..fef5642 100644 > --- a/builtin/ls-files.c > +++ b/builtin/ls-files.c > @@ -276,41 +276,6 @@ static void prune_cache(const char *prefix) > active_nr = last; > } > > -static const char *pathspec_prefix(const char *prefix) > -{ > - const char **p, *n, *prev; > - unsigned long max; > - > - if (!pathspec) { > - max_prefix_len = prefix ? strlen(prefix) : 0; > - return prefix; > - } > - > - 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; > - } > - } > - > - max_prefix_len = max; > - return max ? xmemdupz(prev, max) : NULL; > -} > - > static void strip_trailing_slash_from_submodules(void) > { > const char **p; > @@ -581,7 +546,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) > strip_trailing_slash_from_submodules(); > > /* Find common prefix for all pathspec's */ > - max_prefix = pathspec_prefix(prefix); > + max_prefix = pathspec_prefix(prefix, pathspec); > + max_prefix_len = max_prefix ? strlen(max_prefix) : 0; > > /* Treat unmatching pathspec elements as errors */ > if (pathspec && error_unmatch) { > diff --git a/cache.h b/cache.h > index 86518fb..dd3edaa 100644 > --- a/cache.h > +++ b/cache.h > @@ -441,6 +441,7 @@ extern void set_git_work_tree(const char *tree); > #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" > > extern const char **get_pathspec(const char *prefix, const char **pathspec); > +extern const char *pathspec_prefix(const char *prefix, const char **pathspec); > extern void setup_work_tree(void); > extern const char *setup_git_directory_gently(int *); > extern const char *setup_git_directory(void); > diff --git a/setup.c b/setup.c > index 5ea5502..2c51a9a 100644 > --- a/setup.c > +++ b/setup.c > @@ -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: ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] commit: allow partial commits with relative paths 2011-07-30 16:45 ` Michael J Gruber @ 2011-07-30 17:00 ` Clemens Buchacher 2011-07-30 17:04 ` Michael J Gruber 0 siblings, 1 reply; 5+ messages in thread From: Clemens Buchacher @ 2011-07-30 17:00 UTC (permalink / raw) To: Michael J Gruber; +Cc: git, Reuben Thomas, Junio C Hamano On Sat, Jul 30, 2011 at 06:45:40PM +0200, Michael J Gruber wrote: > > > With your permission I am stealing your commit message. > > I don't care about the message but don't see the point of this patch. > Using the same message certainly won't explain the difference... Well, to be fair I did add to your message, explaining what I did. The point of providing a prefix at all is performance optimization. If you say there is no common prefix for the files of interest, then you cannot leave any files out and you 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. I merely copied that idea from ls-tree. And considering that most of my patch the almost verbatim move of a function from one file to another, I think my change is not that big: > > 4 files changed, 39 insertions(+), 38 deletions(-) Clemens ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] commit: allow partial commits with relative paths 2011-07-30 17:00 ` Clemens Buchacher @ 2011-07-30 17:04 ` Michael J Gruber 0 siblings, 0 replies; 5+ messages in thread From: Michael J Gruber @ 2011-07-30 17:04 UTC (permalink / raw) To: Clemens Buchacher; +Cc: git, Reuben Thomas, Junio C Hamano Clemens Buchacher venit, vidit, dixit 30.07.2011 19:00: > On Sat, Jul 30, 2011 at 06:45:40PM +0200, Michael J Gruber wrote: >> >>> With your permission I am stealing your commit message. >> >> I don't care about the message but don't see the point of this patch. >> Using the same message certainly won't explain the difference... > > Well, to be fair I did add to your message, explaining what I did. > > The point of providing a prefix at all is performance optimization. > If you say there is no common prefix for the files of interest, > then you cannot leave any files out and you 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. I merely copied that idea from ls-tree. > That's the kind of explanation that I meant. Thanks. Michael > And considering that most of my patch the almost verbatim move of a > function from one file to another, I think my change is not that > big: > >>> 4 files changed, 39 insertions(+), 38 deletions(-) > > Clemens ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-03 17:57 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-04-03 17:57 [PATCH] commit: allow partial commits with relative paths Brandon Williams -- strict thread matches above, loose matches on Subject: below -- 2011-07-23 20:25 Possible bug Reuben Thomas 2011-07-25 7:42 ` [RFC/PATCH] commit: allow partial commits with relative paths Michael J Gruber 2011-07-29 13:35 ` [PATCH] " Clemens Buchacher 2011-07-30 16:45 ` Michael J Gruber 2011-07-30 17:00 ` Clemens Buchacher 2011-07-30 17:04 ` Michael J Gruber
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).