Extended RemoteUpdater to update refspecs#567
Conversation
@Yogu GitStrArrayIn might be what you're looking for. Few things to consider:
|
LibGit2Sharp.Tests/RefSpecFixture.cs
Outdated
There was a problem hiding this comment.
This is ugly. Do you know how to ass a string array here? int[] works, but string[] triggers the following error:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
There was a problem hiding this comment.
This is ugly. Do you know how to ass a string array here?
int[]works, butstring[]triggers the following error:An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
This is the closest hack I can think of. See also this StackOverflow question where a string array is being yield.
There was a problem hiding this comment.
If you try to specify a string array as the only argument it seems to get confused, but InlineData(new[] { "one", "two" }, new[] { "three", "four" }) works for me at least.
There was a problem hiding this comment.
@dahlbyk Great! I had only one parameter at first, it works fine with two.
|
@nulltoken Thanks, Implemented setters, added tests, squashed and rebased. |
|
What do you think of it? Anything to improve? Ready to go? Once we've merged this, I can start on #572. The Travis build has passed (just click on detalis); somehow GitHub did not update the status. |
LibGit2Sharp/RemoteUpdater.cs
Outdated
There was a problem hiding this comment.
This is never used. I think we can safely drop it.
I have thought about this for days, but I still don't really feel at ease with the full blown refspecs collection ( I was rather thinking about a replace only setter (with However, adding a single refspec would require a full list containing all the existing specs and the new one. @dahlbyk @carlosmn @ben @ethomson @jamill @yorah Guys, what's your feedback about this? |
LibGit2Sharp/RemoteUpdater.cs
Outdated
There was a problem hiding this comment.
Rather than replace list, I would Clear() and AddRange().
There was a problem hiding this comment.
I think, this would decrease performance if you only want to replace the list, because it would have to retrieve the list first. And as I understand, just replacing is a common use case.
There was a problem hiding this comment.
We immediately Save(), which will evaluate the Lazy<> and enumerate newValues.
As I see it, the tradeoff is between allocating a new Lazy<>, a new List<>, and one more more new inner arrays (depending on size); or reusing all three (at worst allocating additional storage, though that would have been necessary anyway). Not to mention that letting list be readonly makes the internals rather cleaner.
There was a problem hiding this comment.
Ok, there would would be less overhead in the managed scope. However, we would save the call to git_remote_get_fetch_refspecs() which is a result of the original lazy evaluating. As the list would normally be small, and the remote is already loaded in memory, it is probably not a big deal. So I am not sure which of these alternatives would perform better.
I agree that your proposal would be more readable, though.
There was a problem hiding this comment.
I tend to favor readability until concrete performance issues are raised 😉
That sounds about right. There is no reason for the refspecs to behave like a collection, as they're something which 99% of the time you simply want to set (e.g. |
LibGit2Sharp.Tests/RefSpecFixture.cs
Outdated
There was a problem hiding this comment.
I think you want Concat here instead of Union.
|
I'll support the "opposing side" - even if the common use case is just replacement (which is simply supported by this API), there are other common-enough use cases that treating it as a collection doesn't seem like a terrible idea (even if most of the collection API surface area is never used - such is life with .NET too-big list/collection APIs). Especially in the context of an "updater". |
Ok. Let's go down this road. @Yogu Thanks for this nice piece of work! Can you please update the code according to the review comments and rebase this on top of vNext so that we can merge this? |
Done. Great do have this worked out, now I can use official versions in my software again... until the next new feature new is required ;) |
LibGit2Sharp/RemoteUpdater.cs
Outdated
There was a problem hiding this comment.
I think that @dahlbyk was rather after something like
public virtual ICollection<string> FetchRefSpecs
{
get { return fetchRefSpecs; }
set { fetchRefSpecs.ReplaceAll(value); }
}|
Last nitpick: Can you please drop all the code beautification related changes? |
I'm eager to get this merged!
And this one as well ;-) |
There was a problem hiding this comment.
An there maybe
public virtual IEnumerable<RefSpec> FetchRefSpecs
{
get { return refSpecs.Where(r => r.Direction == RefSpecDirection.Fetch); }
}Push/Pull Ref Specs can be updated via Remotes.Update(). The collections can either be manipulated or replaced completely. Any changes are saved immediately.
I hope I found them all. It was only |
|
And that's a meeerrrgeee! Thanks a lot for this 💎 |
Push/Pull Ref Specs can be updated via Remotes.Update(). The collections
can either be manipulated or replaced completely. Any changes are saved
immediately.
This is the place for a discussion about the API to manipulate push/fetch refspecs. In the end, there should be two options:
repo.Network.Fetch()to accept an optional refspec #572)The second option requires a lot of changes, because libgit2sharp currently creates a
RemoteSafeHandlebased on a remote name in many places (e.g. inNetwork.Fetch).As the first option should be relatively simple to implement, I only addressed this one.
I extended the
RemoteUpdaterinstead ofRefSpecCollectionbecause that way, theRemotes and itsRefSpecsproperties stay immutable.