Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2013-01-09 19:40:43 +0400
committernulltoken <emeric.fermas@gmail.com>2013-01-24 02:16:38 +0400
commitc3f37afe160faf2c684b4551ec7997d7991edee2 (patch)
treeae7c1c50fe50c8499133219c73ae7a6f242a6d59 /LibGit2Sharp/Reference.cs
parent1ccfc718b8e2919430b2942a6c1c14cb1284029d (diff)
Refactor reference building
Diffstat (limited to 'LibGit2Sharp/Reference.cs')
-rw-r--r--LibGit2Sharp/Reference.cs35
1 files changed, 27 insertions, 8 deletions
diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs
index 49d91466..253851e8 100644
--- a/LibGit2Sharp/Reference.cs
+++ b/LibGit2Sharp/Reference.cs
@@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
-using LibGit2Sharp.Core.Compat;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
@@ -16,10 +15,20 @@ namespace LibGit2Sharp
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
new LambdaEqualityHelper<Reference>(x => x.CanonicalName, x => x.TargetIdentifier);
+ private readonly string canonicalName;
+ private readonly string targetIdentifier;
+
/// <summary>
- /// Gets the full name of this reference.
+ /// Needed for mocking purposes.
/// </summary>
- public virtual string CanonicalName { get; protected set; }
+ protected Reference()
+ { }
+
+ protected Reference(string canonicalName, string targetIdentifier)
+ {
+ this.canonicalName = canonicalName;
+ this.targetIdentifier = targetIdentifier;
+ }
internal static T BuildFromPtr<T>(ReferenceSafeHandle handle, Repository repo) where T : Reference
{
@@ -37,20 +46,19 @@ namespace LibGit2Sharp
{
if (resolvedHandle == null)
{
- reference = new SymbolicReference { CanonicalName = name, Target = null, TargetIdentifier = targetIdentifier };
+ reference = new SymbolicReference(name, targetIdentifier, null);
break;
}
var targetRef = BuildFromPtr<DirectReference>(resolvedHandle, repo);
- reference = new SymbolicReference { CanonicalName = name, Target = targetRef, TargetIdentifier = targetIdentifier };
+ reference = new SymbolicReference(name, targetIdentifier, targetRef);
break;
}
case GitReferenceType.Oid:
ObjectId targetOid = Proxy.git_reference_oid(handle);
- var targetBuilder = new Lazy<GitObject>(() => repo.Lookup(targetOid));
- reference = new DirectReference(targetBuilder) { CanonicalName = name, TargetIdentifier = targetOid.Sha };
+ reference = new DirectReference(name, repo, targetOid);
break;
default:
@@ -61,6 +69,14 @@ namespace LibGit2Sharp
}
/// <summary>
+ /// Gets the full name of this reference.
+ /// </summary>
+ public virtual string CanonicalName
+ {
+ get { return canonicalName; }
+ }
+
+ /// <summary>
/// Recursively peels the target of the reference until a direct reference is encountered.
/// </summary>
/// <returns>The <see cref = "DirectReference" /> this <see cref = "Reference" /> points to.</returns>
@@ -74,7 +90,10 @@ namespace LibGit2Sharp
/// </para>
/// </summary>
// TODO: Maybe find a better name for this property.
- public virtual string TargetIdentifier { get; private set; }
+ public virtual string TargetIdentifier
+ {
+ get { return targetIdentifier; }
+ }
/// <summary>
/// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Reference" />.