-
Notifications
You must be signed in to change notification settings - Fork 892
/
Copy pathRenameDetails.cs
121 lines (108 loc) · 4.45 KB
/
RenameDetails.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Holds the rename details of a particular file.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RenameDetails : IEquatable<RenameDetails>
{
private readonly string oldFilePath;
private readonly string newFilePath;
private readonly int similarity;
private static readonly LambdaEqualityHelper<RenameDetails> equalityHelper =
new LambdaEqualityHelper<RenameDetails>(x => x.OldFilePath, x => x.NewFilePath, x => x.Similarity);
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected RenameDetails()
{ }
internal RenameDetails(string oldFilePath, string newFilePath, int similarity)
{
this.oldFilePath = oldFilePath;
this.newFilePath = newFilePath;
this.similarity = similarity;
}
/// <summary>
/// Gets the relative filepath to the working directory of the old file (the rename source).
/// </summary>
public virtual string OldFilePath
{
get { return oldFilePath; }
}
/// <summary>
/// Gets the relative filepath to the working directory of the new file (the rename target).
/// </summary>
public virtual string NewFilePath
{
get { return newFilePath; }
}
/// <summary>
/// Gets the similarity between the old file an the new file (0-100).
/// </summary>
public virtual int Similarity
{
get { return similarity; }
}
/// <summary>
/// Determines whether the specified <see cref="object"/> is equal to the current <see cref="RenameDetails"/>.
/// </summary>
/// <param name="obj">The <see cref="object"/> to compare with the current <see cref="RenameDetails"/>.</param>
/// <returns>True if the specified <see cref="object"/> is equal to the current <see cref="RenameDetails"/>; otherwise, false.</returns>
public override bool Equals(object obj)
{
return Equals(obj as RenameDetails);
}
/// <summary>
/// Determines whether the specified <see cref="RenameDetails"/> is equal to the current <see cref="RenameDetails"/>.
/// </summary>
/// <param name="other">The <see cref="RenameDetails"/> to compare with the current <see cref="RenameDetails"/>.</param>
/// <returns>True if the specified <see cref="RenameDetails"/> is equal to the current <see cref="RenameDetails"/>; otherwise, false.</returns>
public bool Equals(RenameDetails other)
{
return equalityHelper.Equals(this, other);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return equalityHelper.GetHashCode(this);
}
/// <summary>
/// Tests if two <see cref="RenameDetails"/> are equal.
/// </summary>
/// <param name="left">First <see cref="RenameDetails"/> to compare.</param>
/// <param name="right">Second <see cref="RenameDetails"/> to compare.</param>
/// <returns>True if the two objects are equal; false otherwise.</returns>
public static bool operator ==(RenameDetails left, RenameDetails right)
{
return Equals(left, right);
}
/// <summary>
/// Tests if two <see cref="RenameDetails"/> are different.
/// </summary>
/// <param name="left">First <see cref="RenameDetails"/> to compare.</param>
/// <param name="right">Second <see cref="RenameDetails"/> to compare.</param>
/// <returns>True if the two objects are different; false otherwise.</returns>
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);
}
}
}
}