@@ -13,40 +13,18 @@ namespace LibGit2Sharp
13
13
/// <para>The individual patches for each file can be accessed through the indexer of this class.</para>
14
14
/// </summary>
15
15
[ DebuggerDisplay ( "{DebuggerDisplay,nq}" ) ]
16
- public class PatchStats : IEnumerable < ContentChangeStats >
16
+ public class PatchStats : IEnumerable < ContentChangeStats > , IDiffResult < PatchStats >
17
17
{
18
18
private readonly IDictionary < FilePath , ContentChangeStats > changes = new Dictionary < FilePath , ContentChangeStats > ( ) ;
19
- private readonly int totalLinesAdded ;
20
- private readonly int totalLinesDeleted ;
19
+ private int totalLinesAdded ;
20
+ private int totalLinesDeleted ;
21
21
22
22
/// <summary>
23
23
/// For mocking.
24
24
/// </summary>
25
- protected PatchStats ( )
25
+ public PatchStats ( )
26
26
{ }
27
27
28
- internal PatchStats ( DiffSafeHandle diff )
29
- {
30
- int count = Proxy . git_diff_num_deltas ( diff ) ;
31
- for ( int i = 0 ; i < count ; i ++ )
32
- {
33
- using ( var patch = Proxy . git_patch_from_diff ( diff , i ) )
34
- {
35
- var delta = Proxy . git_diff_get_delta ( diff , i ) ;
36
- var pathPtr = delta . NewFile . Path != IntPtr . Zero ? delta . NewFile . Path : delta . OldFile . Path ;
37
- var newFilePath = LaxFilePathMarshaler . FromNative ( pathPtr ) ;
38
-
39
- var stats = Proxy . git_patch_line_stats ( patch ) ;
40
- int added = stats . Item1 ;
41
- int deleted = stats . Item2 ;
42
- changes . Add ( newFilePath , new ContentChangeStats ( added , deleted ) ) ;
43
- totalLinesAdded += added ;
44
- totalLinesDeleted += deleted ;
45
- }
46
-
47
- }
48
- }
49
-
50
28
#region IEnumerable<ContentChanges> Members
51
29
52
30
/// <summary>
@@ -69,6 +47,32 @@ IEnumerator IEnumerable.GetEnumerator()
69
47
70
48
#endregion
71
49
50
+ #region IDiffResult implementation
51
+
52
+ PatchStats IDiffResult < PatchStats > . FromNative ( DiffSafeHandleProxy diff )
53
+ {
54
+ int count = Proxy . git_diff_num_deltas ( diff . nativeHandle ) ;
55
+ for ( int i = 0 ; i < count ; i ++ )
56
+ {
57
+ using ( var patch = Proxy . git_patch_from_diff ( diff . nativeHandle , i ) )
58
+ {
59
+ var delta = Proxy . git_diff_get_delta ( diff . nativeHandle , i ) ;
60
+ var pathPtr = delta . NewFile . Path != IntPtr . Zero ? delta . NewFile . Path : delta . OldFile . Path ;
61
+ var newFilePath = LaxFilePathMarshaler . FromNative ( pathPtr ) ;
62
+
63
+ var stats = Proxy . git_patch_line_stats ( patch ) ;
64
+ int added = stats . Item1 ;
65
+ int deleted = stats . Item2 ;
66
+ changes . Add ( newFilePath , new ContentChangeStats ( added , deleted ) ) ;
67
+ totalLinesAdded += added ;
68
+ totalLinesDeleted += deleted ;
69
+ }
70
+ }
71
+ return this ;
72
+ }
73
+
74
+ #endregion
75
+
72
76
/// <summary>
73
77
/// Gets the <see cref="ContentChangeStats"/> corresponding to the specified <paramref name="path"/>.
74
78
/// </summary>
0 commit comments