Skip to content
Newer
Older
100644 138 lines (121 sloc) 5.44 KB
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
1 using System;
8d5db04 @dahlbyk Add RepositoryStatus & StatusEntry DebuggerDisplay
dahlbyk authored Feb 7, 2013
2 using System.Diagnostics;
ac394b4 @nulltoken Fix some issues pinpointed by Code Analysis
nulltoken authored Apr 15, 2014
3 using System.Globalization;
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
4 using LibGit2Sharp.Core;
5
6 namespace LibGit2Sharp
7 {
98ceca5 @nulltoken Fix some missing documentation warnings
nulltoken authored Oct 21, 2011
8 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
9 /// Holds the calculated status of a particular file at a particular instant.
98ceca5 @nulltoken Fix some missing documentation warnings
nulltoken authored Oct 21, 2011
10 /// </summary>
8d5db04 @dahlbyk Add RepositoryStatus & StatusEntry DebuggerDisplay
dahlbyk authored Feb 8, 2013
11 [DebuggerDisplay("{DebuggerDisplay,nq}")]
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
12 public class StatusEntry : IEquatable<StatusEntry>
13 {
14 private readonly string filePath;
15 private readonly FileStatus state;
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 1, 2013
16 private readonly RenameDetails headToIndexRenameDetails;
17 private readonly RenameDetails indexToWorkDirRenameDetails;
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
18
19 private static readonly LambdaEqualityHelper<StatusEntry> equalityHelper =
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
20 new LambdaEqualityHelper<StatusEntry>(x => x.FilePath, x => x.State, x => x.HeadToIndexRenameDetails, x => x.IndexToWorkDirRenameDetails);
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
21
cda8d3f @yorah Make all public types mockable
yorah authored Jun 19, 2012
22 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
23 /// Needed for mocking purposes.
cda8d3f @yorah Make all public types mockable
yorah authored Jun 19, 2012
24 /// </summary>
25 protected StatusEntry()
26 { }
27
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
28 internal StatusEntry(string filePath, FileStatus state, RenameDetails headToIndexRenameDetails = null, RenameDetails indexToWorkDirRenameDetails = null)
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
29 {
30 this.filePath = filePath;
31 this.state = state;
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
32 this.headToIndexRenameDetails = headToIndexRenameDetails;
33 this.indexToWorkDirRenameDetails = indexToWorkDirRenameDetails;
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
34 }
35
98ceca5 @nulltoken Fix some missing documentation warnings
nulltoken authored Oct 21, 2011
36 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
37 /// Gets the <see cref="FileStatus"/> of the file.
98ceca5 @nulltoken Fix some missing documentation warnings
nulltoken authored Oct 21, 2011
38 /// </summary>
cda8d3f @yorah Make all public types mockable
yorah authored Jun 19, 2012
39 public virtual FileStatus State
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
40 {
41 get { return state; }
42 }
43
98ceca5 @nulltoken Fix some missing documentation warnings
nulltoken authored Oct 21, 2011
44 /// <summary>
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
45 /// Gets the relative new filepath to the working directory of the file.
98ceca5 @nulltoken Fix some missing documentation warnings
nulltoken authored Oct 21, 2011
46 /// </summary>
cda8d3f @yorah Make all public types mockable
yorah authored Jun 19, 2012
47 public virtual string FilePath
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
48 {
49 get { return filePath; }
50 }
51
52 /// <summary>
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
53 /// Gets the rename details from the HEAD to the Index, if this <see cref="FileStatus"/> contains <see cref="FileStatus.RenamedInIndex"/>
54 /// </summary>
55 public virtual RenameDetails HeadToIndexRenameDetails
56 {
57 get { return headToIndexRenameDetails; }
58 }
59
60 /// <summary>
79d30b1 @nulltoken Give FileStatus enum entries more meaningful names
nulltoken authored May 9, 2015
61 /// Gets the rename details from the Index to the working directory, if this <see cref="FileStatus"/> contains <see cref="FileStatus.RenamedInWorkdir"/>
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
62 /// </summary>
63 public virtual RenameDetails IndexToWorkDirRenameDetails
64 {
65 get { return indexToWorkDirRenameDetails; }
66 }
67
68 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
69 /// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="StatusEntry"/>.
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
70 /// </summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
71 /// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="StatusEntry"/>.</param>
72 /// <returns>True if the specified <see cref="Object"/> is equal to the current <see cref="StatusEntry"/>; otherwise, false.</returns>
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
73 public override bool Equals(object obj)
74 {
75 return Equals(obj as StatusEntry);
76 }
77
78 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
79 /// Determines whether the specified <see cref="StatusEntry"/> is equal to the current <see cref="StatusEntry"/>.
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
80 /// </summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
81 /// <param name="other">The <see cref="StatusEntry"/> to compare with the current <see cref="StatusEntry"/>.</param>
82 /// <returns>True if the specified <see cref="StatusEntry"/> is equal to the current <see cref="StatusEntry"/>; otherwise, false.</returns>
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
83 public bool Equals(StatusEntry other)
84 {
85 return equalityHelper.Equals(this, other);
86 }
87
88 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
89 /// Returns the hash code for this instance.
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
90 /// </summary>
91 /// <returns>A 32-bit signed integer hash code.</returns>
92 public override int GetHashCode()
93 {
94 return equalityHelper.GetHashCode(this);
95 }
96
97 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
98 /// Tests if two <see cref="StatusEntry"/> are equal.
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
99 /// </summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
100 /// <param name="left">First <see cref="StatusEntry"/> to compare.</param>
101 /// <param name="right">Second <see cref="StatusEntry"/> to compare.</param>
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
102 /// <returns>True if the two objects are equal; false otherwise.</returns>
103 public static bool operator ==(StatusEntry left, StatusEntry right)
104 {
105 return Equals(left, right);
106 }
107
108 /// <summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
109 /// Tests if two <see cref="StatusEntry"/> are different.
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
110 /// </summary>
6fbd65b @yorah Standardize comments style
yorah authored Jul 1, 2013
111 /// <param name="left">First <see cref="StatusEntry"/> to compare.</param>
112 /// <param name="right">Second <see cref="StatusEntry"/> to compare.</param>
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
113 /// <returns>True if the two objects are different; false otherwise.</returns>
114 public static bool operator !=(StatusEntry left, StatusEntry right)
115 {
116 return !Equals(left, right);
117 }
8d5db04 @dahlbyk Add RepositoryStatus & StatusEntry DebuggerDisplay
dahlbyk authored Feb 8, 2013
118
119 private string DebuggerDisplay
120 {
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
121 get
122 {
123 if ((State & FileStatus.RenamedInIndex) == FileStatus.RenamedInIndex ||
79d30b1 @nulltoken Give FileStatus enum entries more meaningful names
nulltoken authored May 9, 2015
124 (State & FileStatus.RenamedInWorkdir) == FileStatus.RenamedInWorkdir)
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
125 {
97256e7 @whoisj Applying consistant formatting across the project
whoisj authored Jun 15, 2015
126 string oldFilePath = ((State & FileStatus.RenamedInIndex) != 0)
127 ? HeadToIndexRenameDetails.OldFilePath
128 : IndexToWorkDirRenameDetails.OldFilePath;
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
129
ac394b4 @nulltoken Fix some issues pinpointed by Code Analysis
nulltoken authored Apr 15, 2014
130 return string.Format(CultureInfo.InvariantCulture, "{0}: {1} -> {2}", State, oldFilePath, FilePath);
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
131 }
132
ac394b4 @nulltoken Fix some issues pinpointed by Code Analysis
nulltoken authored Apr 15, 2014
133 return string.Format(CultureInfo.InvariantCulture, "{0}: {1}", State, FilePath);
974ad99 @ethomson Introduce renames in status
ethomson authored Oct 2, 2013
134 }
8d5db04 @dahlbyk Add RepositoryStatus & StatusEntry DebuggerDisplay
dahlbyk authored Feb 8, 2013
135 }
02dbc31 @nulltoken Add determination of repository status
nulltoken authored Sep 20, 2011
136 }
137 }
Something went wrong with that request. Please try again.