Skip to content

Commit 3b520f1

Browse files
committed
Introduce internal ICommittish
1 parent 5a1fa41 commit 3b520f1

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
{
@@ -377,24 +376,14 @@ private static ObjectId SingleCommittish(this Repository repo, object identifier
377376
return DereferenceToCommit(repo, (string)identifier);
378377
}
379378

380-
if (identifier is ObjectId)
381-
{
382-
return DereferenceToCommit(repo, ((ObjectId)identifier).Sha);
383-
}
384-
385379
if (identifier is Commit)
386380
{
387381
return ((Commit)identifier).Id;
388382
}
389383

390-
if (identifier is TagAnnotation)
391-
{
392-
return DereferenceToCommit(repo, ((TagAnnotation)identifier).Target.Id.Sha);
393-
}
394-
395-
if (identifier is Tag)
384+
if (identifier is ICommittish)
396385
{
397-
return DereferenceToCommit(repo, ((Tag)identifier).Target.Id.Sha);
386+
return DereferenceToCommit(repo, ((ICommittish)identifier).Identifier);
398387
}
399388

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

410-
if (identifier is Reference)
411-
{
412-
return DereferenceToCommit(repo, ((Reference)identifier).CanonicalName);
413-
}
414-
415399
return null;
416400
}
417401

@@ -463,4 +447,9 @@ internal static ObjectId Committish(this Repository repo, object identifier)
463447
return repo.Committishes(identifier, true).First();
464448
}
465449
}
450+
451+
internal interface ICommittish
452+
{
453+
string Identifier { get; }
454+
}
466455
}

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)