Skip to content

Commit 15e5426

Browse files
committed
Introduce internal ICommittish
1 parent a41f87a commit 15e5426

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void LibGit2SharpInterfacesCoverAllPublicMembers()
114114
var methodsMissingFromInterfaces =
115115
from t in Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
116116
where !t.IsInterface
117-
where t.GetInterfaces().Any(i => i.Namespace == typeof(IRepository).Namespace)
117+
where t.GetInterfaces().Any(i => i.IsPublic && i.Namespace == typeof(IRepository).Namespace)
118118
let interfaceTargetMethods = from i in t.GetInterfaces()
119119
from im in t.GetInterfaceMap(i).TargetMethods
120120
select im

LibGit2Sharp/ObjectId.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace LibGit2Sharp
88
/// <summary>
99
/// Uniquely identifies a <see cref="GitObject"/>.
1010
/// </summary>
11-
public sealed class ObjectId : IEquatable<ObjectId>
11+
public sealed class ObjectId : IEquatable<ObjectId>, ICommittish
1212
{
1313
private readonly GitOid oid;
1414
private const int rawSize = 20;
@@ -320,5 +320,7 @@ public bool StartsWith(string shortSha)
320320

321321
return Sha.StartsWith(shortSha, StringComparison.OrdinalIgnoreCase);
322322
}
323+
324+
string ICommittish.Identifier { get { return Sha; } }
323325
}
324326
}

LibGit2Sharp/Reference.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace LibGit2Sharp
1010
/// A Reference to another git object
1111
/// </summary>
1212
[DebuggerDisplay("{DebuggerDisplay,nq}")]
13-
public abstract class Reference : IEquatable<Reference>
13+
public abstract class Reference : IEquatable<Reference>, ICommittish
1414
{
1515
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
1616
new LambdaEqualityHelper<Reference>(x => x.CanonicalName, x => x.TargetIdentifier);
@@ -179,5 +179,7 @@ private string DebuggerDisplay
179179
"{0} => \"{1}\"", CanonicalName, TargetIdentifier);
180180
}
181181
}
182+
183+
string ICommittish.Identifier { get { return CanonicalName; } }
182184
}
183185
}

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO;
66
using System.Linq;
77
using LibGit2Sharp.Core;
8-
using LibGit2Sharp.Handlers;
98

109
namespace LibGit2Sharp
1110
{
@@ -342,24 +341,14 @@ private static ObjectId SingleCommittish(this Repository repo, object identifier
342341
return DereferenceToCommit(repo, (string)identifier);
343342
}
344343

345-
if (identifier is ObjectId)
346-
{
347-
return DereferenceToCommit(repo, ((ObjectId)identifier).Sha);
348-
}
349-
350344
if (identifier is Commit)
351345
{
352346
return ((Commit)identifier).Id;
353347
}
354348

355-
if (identifier is TagAnnotation)
356-
{
357-
return DereferenceToCommit(repo, ((TagAnnotation)identifier).Target.Id.Sha);
358-
}
359-
360-
if (identifier is Tag)
349+
if (identifier is ICommittish)
361350
{
362-
return DereferenceToCommit(repo, ((Tag)identifier).Target.Id.Sha);
351+
return DereferenceToCommit(repo, ((ICommittish)identifier).Identifier);
363352
}
364353

365354
var branch = identifier as Branch;
@@ -372,11 +361,6 @@ private static ObjectId SingleCommittish(this Repository repo, object identifier
372361
}
373362
}
374363

375-
if (identifier is Reference)
376-
{
377-
return DereferenceToCommit(repo, ((Reference)identifier).CanonicalName);
378-
}
379-
380364
return null;
381365
}
382366

@@ -428,4 +412,9 @@ internal static ObjectId Committish(this Repository repo, object identifier)
428412
return repo.Committishes(identifier, true).First();
429413
}
430414
}
415+
416+
internal interface ICommittish
417+
{
418+
string Identifier { get; }
419+
}
431420
}

LibGit2Sharp/Tag.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// A Tag
55
/// </summary>
6-
public class Tag : ReferenceWrapper<GitObject>
6+
public class Tag : ReferenceWrapper<GitObject>, ICommittish
77
{
88
/// <summary>
99
/// Needed for mocking purposes.
@@ -57,5 +57,7 @@ protected override string Shorten()
5757
{
5858
return CanonicalName.Substring(Reference.TagPrefix.Length);
5959
}
60+
61+
string ICommittish.Identifier { get { return Target.Id.Sha; } }
6062
}
6163
}

LibGit2Sharp/TagAnnotation.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace LibGit2Sharp
55
/// <summary>
66
/// A TagAnnotation
77
/// </summary>
8-
public class TagAnnotation : GitObject
8+
public class TagAnnotation : GitObject, ICommittish
99
{
1010
private readonly GitObjectLazyGroup group;
1111
private readonly ILazy<GitObject> lazyTarget;
@@ -50,5 +50,7 @@ internal TagAnnotation(Repository repo, ObjectId id)
5050
/// Gets the tagger.
5151
/// </summary>
5252
public virtual Signature Tagger { get { return lazyTagger.Value; } }
53+
54+
string ICommittish.Identifier { get { return Target.Id.Sha; } }
5355
}
5456
}

0 commit comments

Comments
 (0)