-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPatchDiff.java
More file actions
131 lines (113 loc) · 3.62 KB
/
PatchDiff.java
File metadata and controls
131 lines (113 loc) · 3.62 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package org.variantsync.diffdetective.diff.git;
import org.apache.commons.io.FilenameUtils;
import org.eclipse.jgit.diff.DiffEntry;
import org.variantsync.diffdetective.variation.DiffLinesLabel;
import org.variantsync.diffdetective.variation.diff.Time;
import org.variantsync.diffdetective.variation.diff.VariationDiff;
/**
* Data class containing information about a single patch (i.e., the differences in a single file).
*
* Contains a VariationDiff of the patch.
*
* @author Sören Viegener, Paul Bittner
*/
public class PatchDiff implements GitPatch {
private final String fullDiff;
private final VariationDiff<DiffLinesLabel> variationDiff;
/**
* The commit the patch belongs to.
*/
private final CommitDiff commitDiff;
/**
* The general change type of a single file. See {@link DiffEntry.ChangeType Type}.
*/
private final DiffEntry.ChangeType changeType;
/**
* Path of the file before modification.
*/
private final String oldPath;
/**
* Path of the file after modification.
*/
private final String newPath;
/**
* Creates a new PatchDiff.
* @param commitDiff The changes of a commit this patch belongs to.
* @param diffEntry The diff entry from jgit from which this PatchDiff was produced.
* @param fullDiff The diff of this patch as text. Might be empty.
* @param variationDiff The {@link VariationDiff} that describes this patch.
*/
public PatchDiff(CommitDiff commitDiff, DiffEntry diffEntry, String fullDiff,
VariationDiff<DiffLinesLabel> variationDiff) {
this.commitDiff = commitDiff;
this.changeType = diffEntry.getChangeType();
this.oldPath = diffEntry.getOldPath();
this.newPath = diffEntry.getNewPath();
this.fullDiff = fullDiff;
this.variationDiff = variationDiff;
if (this.variationDiff != null) {
this.variationDiff.setSource(this);
}
}
/**
* Returns the corresponding CommitDiff, which this patch is part of.
*/
public CommitDiff getCommitDiff() {
return this.commitDiff;
}
/**
* Returns the extension of the file this patch is modifying.
*/
public String getFileExtension(Time time) {
return FilenameUtils.getExtension(getFileName(time)).toLowerCase();
}
@Override
public DiffEntry.ChangeType getChangeType() {
return changeType;
}
@Override
public String getFileName(Time time) {
if (time == Time.BEFORE) {
return oldPath;
}else {
return newPath;
}
}
@Override
public String getCommitHash() {
return commitDiff.getCommitHash();
}
@Override
public String getParentCommitHash() {
return commitDiff.getParentCommitHash();
}
@Override
public String getDiff() {
return fullDiff;
}
/**
* Returns the VariationDiff for this patch.
*/
public VariationDiff<DiffLinesLabel> getVariationDiff() {
return variationDiff;
}
/**
* Returns whether this PatchDiff is a valid patch.
* A patch is valid if it has a VariationDiff.
*/
public boolean isValid() {
return variationDiff != null;
}
@Override
public String toString() {
return newPath + "@ " + commitDiff;
}
@Override
public GitPatch shallowClone() {
return new GitPatch.SimpleGitPatch(getDiff(), getChangeType(), getFileName(Time.BEFORE), getFileName(Time.AFTER), getCommitHash(), getParentCommitHash());
}
@Override
public String getSourceExplanation() {
return "PatchDiff";
}
}