Skip to content

Commit 547daba

Browse files
committed
Capture Reference instances' repo
1 parent 4a4d2a9 commit 547daba

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

LibGit2Sharp/Branch.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private Branch ResolveTrackedBranch()
260260
return branch;
261261
}
262262

263-
return new Branch(repo, new VoidReference(trackedReferenceName), trackedReferenceName);
263+
return new Branch(repo, new VoidReference(repo, trackedReferenceName), trackedReferenceName);
264264
}
265265

266266
private static bool IsRemoteBranch(string canonicalName)

LibGit2Sharp/DirectReference.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected DirectReference()
1616
{ }
1717

1818
internal DirectReference(string canonicalName, IRepository repo, ObjectId targetId)
19-
: base(canonicalName, targetId.Sha)
19+
: base(repo, canonicalName, targetId.Sha)
2020
{
2121
targetBuilder = new Lazy<GitObject>(() => repo.Lookup(targetId));
2222
}

LibGit2Sharp/Reference.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public abstract class Reference : IEquatable<Reference>
1515
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
1616
new LambdaEqualityHelper<Reference>(x => x.CanonicalName, x => x.TargetIdentifier);
1717

18+
private readonly IRepository repo;
1819
private readonly string canonicalName;
1920
private readonly string targetIdentifier;
2021

@@ -29,8 +30,19 @@ protected Reference()
2930
/// </summary>
3031
/// <param name="canonicalName">The canonical name.</param>
3132
/// <param name="targetIdentifier">The target identifier.</param>
33+
[Obsolete("This ctor will be removed in a future release.")]
3234
protected Reference(string canonicalName, string targetIdentifier)
35+
: this(null, canonicalName, targetIdentifier)
3336
{
37+
}
38+
39+
/// <remarks>
40+
/// This would be protected+internal, were that supported by C#.
41+
/// Do not use except in subclasses.
42+
/// </remarks>
43+
internal Reference(IRepository repo, string canonicalName, string targetIdentifier)
44+
{
45+
this.repo = repo;
3446
this.canonicalName = canonicalName;
3547
this.targetIdentifier = targetIdentifier;
3648
}
@@ -48,7 +60,7 @@ internal static T BuildFromPtr<T>(ReferenceSafeHandle handle, Repository repo) w
4860
string targetIdentifier = Proxy.git_reference_symbolic_target(handle);
4961

5062
var targetRef = repo.Refs[targetIdentifier];
51-
reference = new SymbolicReference(name, targetIdentifier, targetRef);
63+
reference = new SymbolicReference(repo, name, targetIdentifier, targetRef);
5264
break;
5365

5466
case GitReferenceType.Oid:

LibGit2Sharp/SymbolicReference.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class SymbolicReference : Reference
1717
protected SymbolicReference()
1818
{ }
1919

20-
internal SymbolicReference(string canonicalName, string targetIdentifier, Reference target)
21-
: base(canonicalName, targetIdentifier)
20+
internal SymbolicReference(IRepository repo, string canonicalName, string targetIdentifier, Reference target)
21+
: base(repo, canonicalName, targetIdentifier)
2222
{
2323
this.target = target;
2424
}

LibGit2Sharp/VoidReference.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{
33
internal class VoidReference : Reference
44
{
5-
internal VoidReference(string canonicalName)
6-
: base(canonicalName, null)
5+
internal VoidReference(IRepository repo, string canonicalName)
6+
: base(repo, canonicalName, null)
77
{ }
88

99
public override DirectReference ResolveToDirectReference()

0 commit comments

Comments
 (0)