Skip to content

Introduce internal ICommittish #670

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/MetaFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void LibGit2SharpInterfacesCoverAllPublicMembers()
var methodsMissingFromInterfaces =
from t in Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
where !t.IsInterface
where t.GetInterfaces().Any(i => i.Namespace == typeof(IRepository).Namespace)
where t.GetInterfaces().Any(i => i.IsPublic && i.Namespace == typeof(IRepository).Namespace)
let interfaceTargetMethods = from i in t.GetInterfaces()
from im in t.GetInterfaceMap(i).TargetMethods
select im
Expand Down
4 changes: 3 additions & 1 deletion LibGit2Sharp/ObjectId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LibGit2Sharp
/// <summary>
/// Uniquely identifies a <see cref="GitObject"/>.
/// </summary>
public sealed class ObjectId : IEquatable<ObjectId>
public sealed class ObjectId : IEquatable<ObjectId>, ICommittish
{
private readonly GitOid oid;
private const int rawSize = 20;
Expand Down Expand Up @@ -320,5 +320,7 @@ public bool StartsWith(string shortSha)

return Sha.StartsWith(shortSha, StringComparison.OrdinalIgnoreCase);
}

string ICommittish.Identifier { get { return Sha; } }
}
}
4 changes: 3 additions & 1 deletion LibGit2Sharp/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LibGit2Sharp
/// A Reference to another git object
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public abstract class Reference : IEquatable<Reference>
public abstract class Reference : IEquatable<Reference>, ICommittish
{
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
new LambdaEqualityHelper<Reference>(x => x.CanonicalName, x => x.TargetIdentifier);
Expand Down Expand Up @@ -179,5 +179,7 @@ private string DebuggerDisplay
"{0} => \"{1}\"", CanonicalName, TargetIdentifier);
}
}

string ICommittish.Identifier { get { return CanonicalName; } }
}
}
25 changes: 7 additions & 18 deletions LibGit2Sharp/RepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Linq;
using LibGit2Sharp.Core;
using LibGit2Sharp.Handlers;

namespace LibGit2Sharp
{
Expand Down Expand Up @@ -377,24 +376,14 @@ private static ObjectId SingleCommittish(this Repository repo, object identifier
return DereferenceToCommit(repo, (string)identifier);
}

if (identifier is ObjectId)
{
return DereferenceToCommit(repo, ((ObjectId)identifier).Sha);
}

if (identifier is Commit)
{
return ((Commit)identifier).Id;
}

if (identifier is TagAnnotation)
{
return DereferenceToCommit(repo, ((TagAnnotation)identifier).Target.Id.Sha);
}

if (identifier is Tag)
if (identifier is ICommittish)
{
return DereferenceToCommit(repo, ((Tag)identifier).Target.Id.Sha);
return DereferenceToCommit(repo, ((ICommittish)identifier).Identifier);
}

var branch = identifier as Branch;
Expand All @@ -407,11 +396,6 @@ private static ObjectId SingleCommittish(this Repository repo, object identifier
}
}

if (identifier is Reference)
{
return DereferenceToCommit(repo, ((Reference)identifier).CanonicalName);
}

return null;
}

Expand Down Expand Up @@ -463,4 +447,9 @@ internal static ObjectId Committish(this Repository repo, object identifier)
return repo.Committishes(identifier, true).First();
}
}

internal interface ICommittish
{
string Identifier { get; }
}
}
4 changes: 3 additions & 1 deletion LibGit2Sharp/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// A Tag
/// </summary>
public class Tag : ReferenceWrapper<GitObject>
public class Tag : ReferenceWrapper<GitObject>, ICommittish
{
/// <summary>
/// Needed for mocking purposes.
Expand Down Expand Up @@ -57,5 +57,7 @@ protected override string Shorten()
{
return CanonicalName.Substring(Reference.TagPrefix.Length);
}

string ICommittish.Identifier { get { return Target.Id.Sha; } }
}
}
4 changes: 3 additions & 1 deletion LibGit2Sharp/TagAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace LibGit2Sharp
/// <summary>
/// A TagAnnotation
/// </summary>
public class TagAnnotation : GitObject
public class TagAnnotation : GitObject, ICommittish
{
private readonly GitObjectLazyGroup group;
private readonly ILazy<GitObject> lazyTarget;
Expand Down Expand Up @@ -50,5 +50,7 @@ internal TagAnnotation(Repository repo, ObjectId id)
/// Gets the tagger.
/// </summary>
public virtual Signature Tagger { get { return lazyTagger.Value; } }

string ICommittish.Identifier { get { return Target.Id.Sha; } }
}
}