-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathGitFilePatch.cs
More file actions
105 lines (91 loc) · 3.4 KB
/
GitFilePatch.cs
File metadata and controls
105 lines (91 loc) · 3.4 KB
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
namespace PullRequestQuantifier.Abstractions.Git
{
using System.Collections.Generic;
using System.Linq;
using PullRequestQuantifier.Abstractions.Git.DiffParser;
using PullRequestQuantifier.Abstractions.Git.DiffParser.Models;
public sealed class GitFilePatch
{
private string diffContent;
/// <summary>
/// Contains parsed value of <see cref="DiffContent"/>.
/// Only for internal use.
/// </summary>
private FileDiff fileDiff;
/// <summary>
/// Initializes a new instance of the <see cref="GitFilePatch"/> class.
/// </summary>
/// <param name="filePath">Relative path to the file. </param>
/// <param name="fileExtension">File extension.</param>
public GitFilePatch(
string filePath,
string fileExtension)
{
FilePath = filePath;
FileExtension = fileExtension;
}
/// <summary>
/// Initializes a new instance of the <see cref="GitFilePatch"/> class.
/// Block parameter less constructor.
/// </summary>
private GitFilePatch()
{
}
/// <summary>
/// Gets or sets the absolute total number of lines added in this diff.
/// </summary>
public int AbsoluteLinesAdded { get; set; }
/// <summary>
/// Gets or sets the absolute total number of lines deleted in this diff.
/// </summary>
public int AbsoluteLinesDeleted { get; set; }
/// <summary>
/// Gets or sets the quantified total number of lines added in this diff.
/// Will be determined in the specific context.
/// </summary>
public int QuantifiedLinesAdded { get; set; }
/// <summary>
/// Gets or sets the quantified total number of lines deleted in this diff.
/// Will be determined in the specific context.
/// </summary>
public int QuantifiedLinesDeleted { get; set; }
/// <summary>
/// Gets or sets the full patch file of this diff.
/// </summary>
public string DiffContent
{
get => diffContent;
set
{
diffContent = value;
fileDiff = DiffParserHelper.Parse(value).First();
DiffLines = fileDiff.Chunks.SelectMany(c => c.Changes);
AbsoluteLinesAdded = fileDiff.Additions;
AbsoluteLinesDeleted = fileDiff.Deletions;
}
}
/// <summary>
/// Gets or sets the path of the changed file.
/// </summary>
public string FilePath { get; set; }
/// <summary>
/// Gets or sets the file extension.
/// </summary>
public string FileExtension { get; set; }
/// <summary>
/// Gets or sets the kind of change reported by diff.
/// </summary>
public GitChangeType ChangeType { get; set; }
/// <summary>
/// Gets or sets a value indicating whether discard from counting.
/// In case we want to remove this file from the final counting mark this as true.
/// </summary>
public bool DiscardFromCounting { get; set; }
/// <summary>
/// Parsed line diffs.
/// Used for change counting.
/// Only for internal use.
/// </summary>
internal IEnumerable<LineDiff> DiffLines { get; set; }
}
}