Skip to content

Commit

Permalink
Capture Reference instances' repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Sep 5, 2014
1 parent 4a4d2a9 commit 547daba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LibGit2Sharp/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private Branch ResolveTrackedBranch()
return branch;
}

return new Branch(repo, new VoidReference(trackedReferenceName), trackedReferenceName);
return new Branch(repo, new VoidReference(repo, trackedReferenceName), trackedReferenceName);
}

private static bool IsRemoteBranch(string canonicalName)
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/DirectReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected DirectReference()
{ }

internal DirectReference(string canonicalName, IRepository repo, ObjectId targetId)
: base(canonicalName, targetId.Sha)
: base(repo, canonicalName, targetId.Sha)
{
targetBuilder = new Lazy<GitObject>(() => repo.Lookup(targetId));
}
Expand Down
14 changes: 13 additions & 1 deletion LibGit2Sharp/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class Reference : IEquatable<Reference>
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
new LambdaEqualityHelper<Reference>(x => x.CanonicalName, x => x.TargetIdentifier);

private readonly IRepository repo;
private readonly string canonicalName;
private readonly string targetIdentifier;

Expand All @@ -29,8 +30,19 @@ protected Reference()
/// </summary>
/// <param name="canonicalName">The canonical name.</param>
/// <param name="targetIdentifier">The target identifier.</param>
[Obsolete("This ctor will be removed in a future release.")]
protected Reference(string canonicalName, string targetIdentifier)
: this(null, canonicalName, targetIdentifier)
{
}

/// <remarks>
/// This would be protected+internal, were that supported by C#.
/// Do not use except in subclasses.
/// </remarks>
internal Reference(IRepository repo, string canonicalName, string targetIdentifier)
{
this.repo = repo;
this.canonicalName = canonicalName;
this.targetIdentifier = targetIdentifier;
}
Expand All @@ -48,7 +60,7 @@ internal static T BuildFromPtr<T>(ReferenceSafeHandle handle, Repository repo) w
string targetIdentifier = Proxy.git_reference_symbolic_target(handle);

var targetRef = repo.Refs[targetIdentifier];
reference = new SymbolicReference(name, targetIdentifier, targetRef);
reference = new SymbolicReference(repo, name, targetIdentifier, targetRef);
break;

case GitReferenceType.Oid:
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/SymbolicReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class SymbolicReference : Reference
protected SymbolicReference()
{ }

internal SymbolicReference(string canonicalName, string targetIdentifier, Reference target)
: base(canonicalName, targetIdentifier)
internal SymbolicReference(IRepository repo, string canonicalName, string targetIdentifier, Reference target)
: base(repo, canonicalName, targetIdentifier)
{
this.target = target;
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/VoidReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
internal class VoidReference : Reference
{
internal VoidReference(string canonicalName)
: base(canonicalName, null)
internal VoidReference(IRepository repo, string canonicalName)
: base(repo, canonicalName, null)
{ }

public override DirectReference ResolveToDirectReference()
Expand Down

0 comments on commit 547daba

Please sign in to comment.