using System;
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// Holds the rename details of a particular file.
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RenameDetails : IEquatable
{
private readonly string oldFilePath;
private readonly string newFilePath;
private readonly int similarity;
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(x => x.OldFilePath, x => x.NewFilePath, x => x.Similarity);
///
/// Needed for mocking purposes.
///
protected RenameDetails()
{ }
internal RenameDetails(string oldFilePath, string newFilePath, int similarity)
{
this.oldFilePath = oldFilePath;
this.newFilePath = newFilePath;
this.similarity = similarity;
}
///
/// Gets the relative filepath to the working directory of the old file (the rename source).
///
public virtual string OldFilePath
{
get { return oldFilePath; }
}
///
/// Gets the relative filepath to the working directory of the new file (the rename target).
///
public virtual string NewFilePath
{
get { return newFilePath; }
}
///
/// Gets the similarity between the old file an the new file (0-100).
///
public virtual int Similarity
{
get { return similarity; }
}
///
/// 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 RenameDetails);
}
///
/// 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(RenameDetails 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 ==(RenameDetails left, RenameDetails 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 !=(RenameDetails left, RenameDetails right)
{
return !Equals(left, right);
}
private string DebuggerDisplay
{
get
{
return string.Format(
CultureInfo.InvariantCulture,
"{0} -> {1} [{2}%]", OldFilePath, NewFilePath, Similarity);
}
}
}
}