Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add unmatched pathspecs options #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Add unmatched pathspecs options #343

wants to merge 3 commits into from

Conversation

yorah
Copy link
Contributor

@yorah yorah commented Feb 19, 2013

This is related to #274

  • πŸ’€ Implementation in progress
  • πŸ”¦ Ready for review
  • 🎱 more work
  • ⭐ Really ready for review this time

Points of attention:

  • Remove() is not included in this PR.
  • This PR includes some bug fixing related to Remove unnecessary finalizersΒ #330 (the bugs were there before, they were just put into light by the aforementionned PR)

@yorah
Copy link
Contributor Author

yorah commented Feb 19, 2013

/cc @jamill

@yorah
Copy link
Contributor Author

yorah commented Feb 19, 2013

As a bonus, the build is now πŸ’š

For Stage(), I had to include Unmodified records, to differentiate between:

  • a non-existent file
  • a removed file
  • an unaltered file (which acts as an unmatched pathspec when we don't include Unmodified files)
  • a file that was already added to the index (same thing)

I have the feeling I'm missing some other edge cases though, but can't figure out which ones...

@@ -253,7 +253,7 @@ public static Signature git_commit_committer(GitObjectSafeHandle obj)
{
using (ThreadAffinity())
using (var treePtr = new ObjectSafeWrapper(tree.Id, repo))
using (var parentObjectPtrs = new DisposableEnumerable<ObjectSafeWrapper>(parentIds.Select(id => new ObjectSafeWrapper(id, repo))))
using (var parentObjectPtrs = new DisposableEnumerable<ObjectSafeWrapper>(parentIds.Select(id => new ObjectSafeWrapper(id, repo)).ToArray()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ToList() here would avoid an extra array allocation for the final result.

Based on usage of parentObjectPtrs.Count() below, should DisposableEnumerable be converted to DisposableCollection to avoid an extra enumeration?

@yorah
Copy link
Contributor Author

yorah commented Feb 21, 2013

Latest changes:

  • implemented @dahlbyk proposal regarding DisposableEnumerable (actually, I just exposed a Count property to avoid the extra enumeration => I did not feel like implementing the whole ICollection<T> interface as we don't need it).
  • by default, pathspec validation is now strict. This means that unless you specify otherwise, an exception will be thrown if one of the passed path/pathspec doesn't match.

@dahlbyk
Copy link
Member

dahlbyk commented Feb 21, 2013

actually, I just exposed a Count property to avoid the extra enumeration => I did not feel like implementing the whole ICollection interface as we don't need it

πŸ‘

@nulltoken
Copy link
Member

@yorah I cherry picked the first five commits and pushed them into vNext. Could you please rebase this PR to drop them?

by default, pathspec validation is now strict. This means that unless you specify otherwise, an exception will be thrown if one of the passed path/pathspec doesn't match.

I'm in favor of this approach. And the code looks pretty clean.

However, as this is quite a breaking change, I'd like to wait for some days to see if the other contributors have anything to say about this.

@yorah
Copy link
Contributor Author

yorah commented Feb 22, 2013

Rebased and running.

As a bonus, I will also add some test coverage related to accepting globs as pathspecs for staging/unstaging. In the next few days.

@yorah
Copy link
Contributor Author

yorah commented Feb 26, 2013

Added some tests related to accepting globs as pathspecs. Passing "*" is currently broken, waiting for feedback on libgit2/libgit2#1367.

Does anyone have an opinion related to the change of behaviour (strict vs lax)? Please? 🐱

@yorah
Copy link
Contributor Author

yorah commented Mar 11, 2013

Proposal as of now (current code)

Only throw/notify for explicit paths (renamed the PathspecsOptions class to ExplicitPathsOptions to match what it does).

Advantages I see:

  • simple and predictable behavior
  • no breaking changes with what was previously there (if you don't pass an ExplicitPathsOptions instance, no notify/throw is done, and you get standard pathspec matching)

@dahlbyk regarding the proposal you made in libgit2/libgit2#1367, I think checking if offending pathspecs match any of the already found files in libgit2sharp is not easily feasible. This would mean either exposing the _fnmatch functionality implemented in libgit2 (which doesn't feel right), or re-implementing our own fnmatch. We would also have to take the ignore_case flag into account.

RFC

Before going further, I would like to make a request for comments.

Basically, the initial question this PR tries to address boils down to:
Is it ok to stage/unstage (and remove/move) a file which doesn't exist?

I think there are two main cases:

  • the client passes a list of pathspecs
  • the client passes a list of explicit paths
  • the client passes a mix of both (unlikely corner case, excluded on purpose => this looks like a "slippery slope"β„’, as the result will depend on the way the list is being sorted)

So the question can also be reformulated as:
What should be the expected behavior when a path/pathspec is unmatched?
Silently ignore? Notify? Throw?

@haacked @dahlbyk @jamill @ethomson

@dahlbyk
Copy link
Member

dahlbyk commented Mar 14, 2013

@nulltoken would it be possible to cherry-pick 144ac99 and 5675ea0 so it's easier to read the core PR?

What should be the expected behavior when a path/pathspec is unmatched?

I'll defer to people that are actually building clients that need to Stage/Unstage.

@nulltoken
Copy link
Member

@nulltoken would it be possible to cherry-pick 144ac99 and 5675ea0 so it's easier to read the core PR?

@dahlbyk Done!

@nulltoken
Copy link
Member

@yorah Could you please rebase this PR on top of vNext?

@yorah
Copy link
Contributor Author

yorah commented Mar 18, 2013

Could you please rebase this PR on top of vNext?

Done!

@haacked @jamill whenever you have time, I would really appreciate your feedback.

*/
[Theory]
[InlineData("*u*", 0)]
//[InlineData("*", 0)] TODO: waiting for https://github.com/libgit2/libgit2/pull/1367
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the current status of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working with my latest proposal, uncommenting.

yorah added 3 commits April 9, 2013 16:07
All the overloads can now report and/or fail upon unmatched explicit paths.
By default, the passed list of paths will be treated as a list of pathspecs.

When an ExplicitPathsOptions is passed to the overloads, this list of paths
will be treated as explicit paths. In that case, the default behavior is to
throw when one of this explicit path is unmatched.
@nulltoken
Copy link
Member

πŸ‘ Merged

@nulltoken nulltoken closed this Apr 9, 2013
@yorah
Copy link
Contributor Author

yorah commented Apr 9, 2013

Cool!

@dahlbyk I think this impacts your submodule PR (for the Stage() method, where we now rely on diff). Unless you beat me to it, I will have a look tomorrow to see if there is an easy way to make it work nicely with your PR!

@yorah yorah deleted the topic/unmatched-pathspecs branch April 9, 2013 19:25
@dahlbyk dahlbyk mentioned this pull request Apr 10, 2013
13 tasks
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.

3 participants