using System; using System.Diagnostics; using System.Globalization; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; namespace LibGit2Sharp { /// /// A reference to the paths involved in a rename , /// known by the . /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class IndexNameEntry : IEquatable { private static readonly LambdaEqualityHelper equalityHelper = new LambdaEqualityHelper(x => x.Ancestor, x => x.Ours, x => x.Theirs); /// /// Needed for mocking purposes. /// protected IndexNameEntry() { } internal static unsafe IndexNameEntry BuildFromPtr(git_index_name_entry* entry) { if (entry == null) { return null; } string ancestor = entry->ancestor != null ? LaxFilePathMarshaler.FromNative(entry->ancestor) : null; string ours = entry->ours != null ? LaxFilePathMarshaler.FromNative(entry->ours) : null; string theirs = entry->theirs != null ? LaxFilePathMarshaler.FromNative(entry->theirs) : null; return new IndexNameEntry { Ancestor = ancestor, Ours = ours, Theirs = theirs, }; } /// /// Gets the path of the ancestor side of the conflict. /// public virtual string Ancestor { get; private set; } /// /// Gets the path of the "ours" side of the conflict. /// public virtual string Ours { get; private set; } /// /// Gets the path of the "theirs" side of the conflict. /// public virtual string Theirs { get; private set; } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// True if the specified is equal to the current ; otherwise, false. public override bool Equals(object obj) { return Equals(obj as IndexNameEntry); } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// True if the specified is equal to the current ; otherwise, false. public bool Equals(IndexNameEntry other) { return equalityHelper.Equals(this, other); } /// /// Returns the hash code for this instance. /// /// A 32-bit signed integer hash code. public override int GetHashCode() { return equalityHelper.GetHashCode(this); } /// /// Tests if two are equal. /// /// First to compare. /// Second to compare. /// True if the two objects are equal; false otherwise. public static bool operator ==(IndexNameEntry left, IndexNameEntry right) { return Equals(left, right); } /// /// Tests if two are different. /// /// First to compare. /// Second to compare. /// True if the two objects are different; false otherwise. public static bool operator !=(IndexNameEntry left, IndexNameEntry right) { return !Equals(left, right); } private string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", Ancestor, Ours, Theirs); } } } }