using System;
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
///
/// A reference to a resolved ,
/// known by the .
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class IndexReucEntry : IEquatable
{
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(x => x.Path,
x => x.AncestorId, x => x.AncestorMode,
x => x.OurId, x => x.OurMode,
x => x.TheirId, x => x.TheirMode);
///
/// Needed for mocking purposes.
///
protected IndexReucEntry()
{ }
internal static IndexReucEntry BuildFromPtr(IndexReucEntrySafeHandle handle)
{
if (handle == null || handle.IsZero)
{
return null;
}
GitIndexReucEntry entry = handle.MarshalAsGitIndexReucEntry();
FilePath path = LaxFilePathMarshaler.FromNative(entry.Path);
return new IndexReucEntry
{
Path = path.Native,
AncestorId = entry.AncestorId,
AncestorMode = (Mode)entry.AncestorMode,
OurId = entry.OurId,
OurMode = (Mode)entry.OurMode,
TheirId = entry.TheirId,
TheirMode = (Mode)entry.TheirMode,
};
}
///
/// Gets the path of this conflict.
///
public virtual string Path { get; private set; }
///
/// Gets the that was the ancestor of this
/// conflict.
///
public virtual ObjectId AncestorId { get; private set; }
///
/// Gets the of the file that was the ancestor of
/// conflict.
///
public virtual Mode AncestorMode { get; private set; }
///
/// Gets the that was "our" side of this
/// conflict.
///
public virtual ObjectId OurId { get; private set; }
///
/// Gets the of the file that was "our" side of
/// the conflict.
///
public virtual Mode OurMode { get; private set; }
///
/// Gets the that was "their" side of this
/// conflict.
///
public virtual ObjectId TheirId { get; private set; }
///
/// Gets the of the file that was "their" side of
/// the conflict.
///
public virtual Mode TheirMode { 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 IndexReucEntry);
}
///
/// 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(IndexReucEntry 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 ==(IndexReucEntry left, IndexReucEntry 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 !=(IndexReucEntry left, IndexReucEntry right)
{
return !Equals(left, right);
}
private string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture,
"{0}: {1} {2} {3}", Path, AncestorId, OurId, TheirId);
}
}
}
}