-
Notifications
You must be signed in to change notification settings - Fork 899
Return a Repository instance when doing Init #101
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
Comments
I fear there's neither an easy nor a definitive answer to this question. Below are some random thoughts about it:
As I wrote earlier, I have no firm position and I'm open to discussion on this subject. |
I don't quite understand your last point. What's the difference between a GUI and a non-GUI client? I do plan to write a Web client using the library. But I still don't know exactly how I'm going to use it, meaning the exact sequence of operations. I however, discovered a (minor) friction while writing a test, and a (minor) surprise point, so, my suggestion is based solely on listening to the tests. |
In my mind, it'd be better to return the repo object. Can you ever imagine an app that wouldnt immediately new up the repo? |
This is why I suggested you to open a request :)
Sorry, I was unclear. I was opposing a unit test to a full blown desktop client. When running a cloning test, the code is focused on asserting the result of the cloning. This is the main goal of the test. Returning a Repository instead of a path would allow to reduce the number of lines and start asserting "sooner". However, when using a desktop client, I'd like not to be blocked while cloning a repository, especially a large one. I may even want to clone several ones at a time, in parallel (with a progress bar for each or a notification system (ding "Linux" successfully cloned). While my repos are being cloned, I might be editing the Markdown of a Readme file from another repo. In this perspective, chances are than the browsing the commits of one the cloned repositories will be the result of an explicit action of mine and not an automatic reaction of the application upon a successful clone. I wouldn't start "using" it immediately. |
@xpaulbettsx That's a +1, then ;) IIRC @tclem was also in favor of this approach. |
@uluhonolulu scratch my last comment. We're talking about syntactic sugar here, not its impact on a software architecture. |
@uluhonolulu @xpaulbettsx I've given some more thought to this matter. Nice thing about being in v0.x.x is that API is considered unstable, isn't it? ;) So, let's try this. |
I remember talking about this a while back. I actually don't care either way. So far when I've used |
I try to avoid returning an One alternative is an optional callback: dahlbyk/libgit2sharp@cd96c50 |
@nulltoken Now I see your point. Still, your notification system will probably need more info than just the path to the cloned repo => it'll still have to create a new Repository instance in order to If someone forgets to Dispose of Repository.Init(), then he will surely forget to dispose of new Repository(), no? |
@uluhonolulu This is what the *"I've given some more thought to this matter."` part was about. :)
You may be right. My goal, by not multiplying the number of method returning an IDisposable, was to reduce the surface of exposure to this risk. The only way I see to mitigate this would be to create some code samples and tutorials (cf. RavenDB) in order to raise the probability of having good code being copied/pasted. |
So, in order to make everybody happy, I'd create two overloads: one that returns a Repository instance, the other is with a callback like @dahlbyk suggested. As I was the one who initiated this issue, I suggest I do the pull request. |
@nulltoken I volunteer to contribute to the Samples section when the API is stabilized. Until then, I hope folks will look at our tests for the samples. |
@dahlbyk Wow! You just blew my mind. I really like this functional approach. This would lead to some JQuery-like code/syntax. We could even ditch the public constructor. Repository.Open(path, repositoryOptions, repo => {
repo.Stage("a.xtx);
repo.Commit(...);
}); The only downside I see is that some desktop GUI clients might require to store the
Would you have some use cases in mind? |
@tclem ACK. If we go this way, I sincerely hope we won't have to rollback. Even if semver is on our side, switching back and forth would be... hmm....how to say this politely... well... less than pleasant :p |
Awesome!
@uluhonolulu Could we wait for @dahlbyk 's feedback on my comment? ^^ Beside this, I'm really not in favor of proposing two different ways of opening/initializing/cloning a repo. As those are two really different approaches, I'd really prefer to select one and stick with it. Less doc to write, less explanation to give, easier to support...
Beware, I'll remind you of this ;p |
The first example that jumps to mind is the GUI scenario. "New Repository" dialog opens, user types path, repo gets created... It seems unlikely to me that rendering the new repo is now that dialog's responsibility. More likely you would just return "success" and move on to an existing repo viewer that would likely need to create its own
Correct. I think it makes sense for there to be two ways we expose
Since the approach might feel foreign to some .NET devs, we could emphasize the former in documentation/examples, but provide the latter (always with |
One other thought: documentation needs to be clear that the callback is the usable scope both for the
That being said, it might be handy to provide two overloads, |
With all respect, now I see that the callback version gives much more possibilities to shoot yourself in a leg. |
No more so than this common antipattern:
Ultimately working with stuff that depends on an |
@dahlbyk @uluhonolulu @tclem @xpaulbettsx Although, I still feel a bit uneasy adding some more In order to provide (aside from the unit tests) some additional guidance, the xml documentation should be updated as well in order to emphasise that the returned type should be disposed, either by a call to the @uluhonolulu If you're still up to implement this, could you please change the Thank you all, guys, for your feedback! 👍 |
Guys, sorry to dig up this thread, but I'd like you to peek at #453. This new PR directly impacts back on this issue. |
Why do you want to return the path to the new repository instead of the repository object? I find the actual repo path not as relevant as a reference to the actual repo instance. Instead of doing
why not just
Same with
Clone
, don't you think it would be more convenient to return the instance of the repository (which is being created inside the method anyway)?The text was updated successfully, but these errors were encountered: