Skip to content

Don't load an object just to check its ID #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion LibGit2Sharp/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ public virtual BranchTrackingDetails TrackingDetails
/// </value>
public virtual bool IsCurrentRepositoryHead
{
get { return repo.Head == this; }
get
{
if (this is DetachedHead)
{
return repo.Head.reference.TargetIdentifier == this.reference.TargetIdentifier;
}

return repo.Head.reference.TargetIdentifier == this.CanonicalName;
}
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion LibGit2Sharp/ReferenceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public abstract class ReferenceWrapper<TObject> : IEquatable<ReferenceWrapper<TO
/// The repository.
/// </summary>
protected readonly Repository repo;
protected readonly Reference reference;
private readonly Lazy<TObject> objectBuilder;

private static readonly LambdaEqualityHelper<ReferenceWrapper<TObject>> equalityHelper =
new LambdaEqualityHelper<ReferenceWrapper<TObject>>(x => x.CanonicalName, x => x.TargetObject);
new LambdaEqualityHelper<ReferenceWrapper<TObject>>(x => x.CanonicalName, x => x.reference.TargetIdentifier);

private readonly string canonicalName;

Expand All @@ -40,6 +41,7 @@ protected internal ReferenceWrapper(Repository repo, Reference reference, Func<R

this.repo = repo;
canonicalName = canonicalNameSelector(reference);
this.reference = reference;
objectBuilder = new Lazy<TObject>(() => RetrieveTargetObject(reference));
}

Expand Down