-
Notifications
You must be signed in to change notification settings - Fork 899
Continuous if sentence #658
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
Conversation
@@ -415,6 +408,10 @@ internal static IEnumerable<ObjectId> Committishes(this Repository repo, object | |||
/// <returns>An <see cref="ObjectId"/> for a commit object.</returns> | |||
internal static ObjectId Committish(this Repository repo, object identifier) | |||
{ | |||
while (!(identifier is string) && identifier is IEnumerable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop scares me.
How about this? (Patch to be applied on top of your commit)
diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs
index 90b567f..3cb4e8f 100644
--- a/LibGit2Sharp/RepositoryExtensions.cs
+++ b/LibGit2Sharp/RepositoryExtensions.cs
@@ -374,7 +374,14 @@ internal static IEnumerable<ObjectId> Committishes(this Repository repo, object
{
singleReturnValue = DereferenceToCommit(repo, ((Reference) identifier).CanonicalName);
}
- else if (identifier is IEnumerable)
+
+ if (singleReturnValue != null)
+ {
+ yield return singleReturnValue;
+ yield break;
+ }
+
+ if (identifier is IEnumerable)
{
foreach (object entry in (IEnumerable)identifier)
{
@@ -387,16 +394,11 @@ internal static IEnumerable<ObjectId> Committishes(this Repository repo, object
yield break;
}
- if (singleReturnValue != null)
- {
- yield return singleReturnValue;
- yield break;
- }
-
if (throwIfNotFound)
{
throw new LibGit2SharpException(string.Format(CultureInfo.InvariantCulture, "Unexpected kind of identifier '{0}'.", identifier));
}
+
yield return null;
}
@@ -408,10 +410,6 @@ internal static IEnumerable<ObjectId> Committishes(this Repository repo, object
/// <returns>An <see cref="ObjectId"/> for a commit object.</returns>
internal static ObjectId Committish(this Repository repo, object identifier)
{
- while (!(identifier is string) && identifier is IEnumerable)
- {
- identifier = ((IEnumerable)identifier).Cast<object>().FirstOrDefault();
- }
return repo.Committishes(identifier, true).First();
}
}
I think there may exist some way to refactor this further, but I'm not sure how to do it
- while preserving the "mockability" of types
- without over-engineering it
@dahlbyk Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there may exist some way to refactor this further, but I'm not sure how to do it
something like table driven in CommitFilter ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there may exist some way to refactor this further, but I'm not sure how to do it
something like table driven in CommitFilter ?
I was indeed thinking about some Dictionary<Type, Func>
based something, but I'm afraid this would also require a specific IComparer
to allow comparison of derived/mocked types...
@Aimeast Anyway, unless someone comes up with a brilliant and simple idea, let's have this merged. Could you please squash the commits and maybe improve the commit message (eg. |
Extracting And orthogonal to the short-circuiting, 15e5426 includes an OO-ish way to move some of this logic down into the various committish types. With a bit more cleverness that interface could probably be adjusted such that it would apply to |
Done. Long live #667 |
@dahlbyk ❤️ |
A bit of changes.