Skip to content

iterator/diff: allow trailing / on start/end paths to match submodules - #3724

Merged
carlosmn merged 2 commits into
libgit2:masterfrom
ethomson:submodule_start_supports_silly_slashes
Apr 3, 2016
Merged

iterator/diff: allow trailing / on start/end paths to match submodules#3724
carlosmn merged 2 commits into
libgit2:masterfrom
ethomson:submodule_start_supports_silly_slashes

Conversation

@ethomson

@ethomson ethomson commented Apr 2, 2016

Copy link
Copy Markdown
Member

In the great iterator refactor of 2016, we made clear that submodules should not have trailing slashes for the start and end paths. This regressed some expected behavior.

Unfortunately, this does not quite jive with diff's pathspec matching, which will happily accept foo/ if foo is a submodule. This is problematic because diff will set the iterator's start and end paths to the longest common substring of the pathspecs. (Which may be nothing, but it may be something, and if it is that would speed up the diff.)

Therefore, if you are asking about a bunch of paths, and you've foolishly added a trailing slash to a submodule, the behavior is different than if you ask about just that one path:

If you diff with pathspecs = { "a", "b", "submod/", "z" }, then there is no common substring and so the diff cannot provide a start and end prefix to the iterator. Thus, diff looks at all the paths coming back from the iterator and so its logic about whether submod/ should match a submodule named submod is used. (And that does match, according to diff.)

However, if you diff the same entries with pathspecs = { "submod/" } then now diff notices that it can use a start and end prefix - and it does, of submod/. So now, the iterators must treat this the same way that diff did for consistency. So submod/ must match a submodule named submod in iterator, so that diff can do its thing.

This change is really quite minor, but it's a bit annoying, since I was very careful to treat submodules differently than directories and thought I was actually righting the behavior here. :)

Edward Thomson added 2 commits April 2, 2016 13:02
Test that submodules are found when the are included in a pathspec
but have a trailing slash.
Allow callers to specify a start path with a trailing slash to match
a submodule, instead of just a directory.  This is for some legacy
behavior that's sort of dumb, but there it is.
@carlosmn
carlosmn merged commit 381caf5 into libgit2:master Apr 3, 2016
@ethomson
ethomson deleted the submodule_start_supports_silly_slashes branch April 7, 2016 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants