using System; using LibGit2Sharp.Core; namespace LibGit2Sharp { /// /// Holds information about the potential ancestor /// and distance from it and two specified s. /// public class HistoryDivergence { private readonly Lazy commonAncestor; /// /// Needed for mocking purposes. /// protected HistoryDivergence() { } internal HistoryDivergence(Repository repo, Commit one, Commit another) { commonAncestor = new Lazy(() => repo.ObjectDatabase.FindMergeBase(one, another)); Tuple div = Proxy.git_graph_ahead_behind(repo.Handle, one, another); One = one; Another = another; AheadBy = div.Item1; BehindBy = div.Item2; } /// /// Gets the being used as a reference. /// public virtual Commit One { get; private set; } /// /// Gets the being compared against . /// public virtual Commit Another { get; private set; } /// /// Gets the number of commits that are reachable from , /// but not from . /// /// This property will return null when /// and do not share a common ancestor. /// /// public virtual int? AheadBy { get; private set; } /// /// Gets the number of commits that are reachable from , /// but not from . /// /// This property will return null when /// and do not share a common ancestor. /// /// public virtual int? BehindBy { get; private set; } /// /// Returns the best possible common ancestor of /// and or null if none found. /// public virtual Commit CommonAncestor { get { return commonAncestor.Value; } } } internal class NullHistoryDivergence : HistoryDivergence { public override Commit CommonAncestor { get { return null; } } } }