diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-11-14 01:24:36 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-12-06 03:53:35 +0400 |
commit | a845db98d9eff7fe16a371d7c08b9f2715801d94 (patch) | |
tree | 40637aae49b8f03265315c2a991d8bdb977e0b7b /LibGit2Sharp/BranchTrackingDetails.cs | |
parent | 442f7a80502ed919d94891400f7766b8415f106d (diff) |
Introduce ObjectDatabase.CalculateHistoryDivergence()
Fix #562
Diffstat (limited to 'LibGit2Sharp/BranchTrackingDetails.cs')
-rw-r--r-- | LibGit2Sharp/BranchTrackingDetails.cs | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/LibGit2Sharp/BranchTrackingDetails.cs b/LibGit2Sharp/BranchTrackingDetails.cs index 0acce526..ad7153c8 100644 --- a/LibGit2Sharp/BranchTrackingDetails.cs +++ b/LibGit2Sharp/BranchTrackingDetails.cs @@ -1,5 +1,4 @@ -using LibGit2Sharp.Core; -using LibGit2Sharp.Core.Compat; +using System; namespace LibGit2Sharp { @@ -8,10 +7,7 @@ namespace LibGit2Sharp /// </summary> public class BranchTrackingDetails { - private readonly Repository repo; - private readonly Branch branch; - private readonly Lazy<Tuple<int?, int?>> aheadBehind; - private readonly Lazy<Commit> commonAncestor; + private readonly HistoryDivergence historyDivergence; /// <summary> /// Needed for mocking purposes. @@ -21,11 +17,13 @@ namespace LibGit2Sharp internal BranchTrackingDetails(Repository repo, Branch branch) { - this.repo = repo; - this.branch = branch; + if (!branch.IsTracking || branch.Tip == null || branch.TrackedBranch.Tip == null) + { + historyDivergence = new NullHistoryDivergence(); + return; + } - aheadBehind = new Lazy<Tuple<int?, int?>>(ResolveAheadBehind); - commonAncestor = new Lazy<Commit>(ResolveCommonAncestor); + historyDivergence = repo.ObjectDatabase.CalculateHistoryDivergence(branch.Tip, branch.TrackedBranch.Tip); } /// <summary> @@ -37,7 +35,7 @@ namespace LibGit2Sharp /// </summary> public virtual int? AheadBy { - get { return aheadBehind.Value.Item1; } + get { return historyDivergence.AheadBy; } } /// <summary> @@ -49,7 +47,7 @@ namespace LibGit2Sharp /// </summary> public virtual int? BehindBy { - get { return aheadBehind.Value.Item2; } + get { return historyDivergence.BehindBy; } } /// <summary> @@ -61,29 +59,7 @@ namespace LibGit2Sharp /// </summary> public virtual Commit CommonAncestor { - get { return commonAncestor.Value; } - } - - private Tuple<int?, int?> ResolveAheadBehind() - { - return branch.IsTracking - ? Proxy.git_graph_ahead_behind(repo.Handle, branch.TrackedBranch.Tip, branch.Tip) - : new Tuple<int?, int?>(null, null); - } - - private Commit ResolveCommonAncestor() - { - if (!branch.IsTracking) - { - return null; - } - - if (branch.Tip == null || branch.TrackedBranch.Tip == null) - { - return null; - } - - return repo.Commits.FindCommonAncestor(branch.Tip, branch.TrackedBranch.Tip); + get { return historyDivergence.CommonAncestor; } } } } |