-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGitPatch.java
More file actions
85 lines (73 loc) · 2.95 KB
/
GitPatch.java
File metadata and controls
85 lines (73 loc) · 2.95 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
package org.variantsync.diffdetective.diff.git;
import java.util.List;
import org.eclipse.jgit.diff.DiffEntry;
import org.variantsync.diffdetective.diff.text.TextBasedDiff;
import org.variantsync.diffdetective.util.Source;
import org.variantsync.diffdetective.variation.diff.Time;
import org.variantsync.diffdetective.variation.diff.VariationDiff; // For Javadoc
/**
* Interface for patches from a git repository.
* A git patch is a {@link TextBasedDiff} from which {@link VariationDiff}s can be created.
*
*/
public interface GitPatch extends Source, TextBasedDiff {
/**
* Minimal default implementation of {@link GitPatch}
* @param getDiff The diff in text form.
* @param getChangeType The change type of this patch (e.g., file insertion or modification).
* @param oldFileName The name of the patched file before the edit.
* @param newFileName The name of the patched file after the edit.
* @param getCommitHash The hash of the commit introducing the change.
* @param getParentCommitHash The hash of the parent commit regarding which the diff was created.
*/
record SimpleGitPatch(String getDiff, DiffEntry.ChangeType getChangeType, String oldFileName, String newFileName, String getCommitHash, String getParentCommitHash)
implements GitPatch {
@Override
public String getFileName(Time time) {
if (time == Time.BEFORE) {
return oldFileName;
} else {
return newFileName;
}
}
@Override
public GitPatch shallowClone() {
return new SimpleGitPatch(getDiff, getChangeType, oldFileName, newFileName, getCommitHash, getParentCommitHash);
}
@Override
public String toString() {
return oldFileName + "@ " + getParentCommitHash + " (parent) to " + newFileName + " @ " + getCommitHash + " (child)";
}
@Override
public String getSourceExplanation() {
return "SimpleGitPatch";
}
@Override
public List<Object> getSourceArguments() {
return List.of(getChangeType(), oldFileName(), newFileName(), getCommitHash(), getParentCommitHash());
}
}
/**
* Returns the change type of this patch (e.g., file insertion or modification).
*/
DiffEntry.ChangeType getChangeType();
/**
* Returns the name of the patched file at the given time.
*/
String getFileName(Time time);
/**
* Returns the hash of the commit introducing the change.
*/
String getCommitHash();
/**
* Returns the hash of the parent commit regarding which the diff was created.
*/
String getParentCommitHash();
/**
* Creates a shallow clone.
* A shallow clone should return the very same values for the methods of this interface.
* Other behaviour is unspecified.
* @return A clone that acts equal with respect to this interface.
*/
GitPatch shallowClone();
}