Make change types explicit

Without explicit change types, we cannot tell copy and rename apart.
This commit is contained in:
René Pfeuffer
2020-05-19 23:08:19 +02:00
parent 5c7491c254
commit 054f320455
5 changed files with 81 additions and 28 deletions

View File

@@ -57,7 +57,7 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
formatter.setRepository(repository);
for (DiffEntry e : diff.getEntries()) {
if (!e.getOldId().equals(e.getNewId()) || !e.getNewPath().equals(e.getOldPath())) {
if (idOrPathChanged(e)) {
formatter.format(e);
}
}
@@ -67,6 +67,10 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
};
}
private boolean idOrPathChanged(DiffEntry e) {
return !e.getOldId().equals(e.getNewId()) || !e.getNewPath().equals(e.getOldPath());
}
static class DequoteOutputStream extends OutputStream {
private static final String[] DEQUOTE_STARTS = {

View File

@@ -108,6 +108,24 @@ public class GitDiffResultCommand extends AbstractGitCommand implements DiffResu
return diffEntry.getNewPath();
}
@Override
public ChangeType getChangeType() {
switch (diffEntry.getChangeType()) {
case ADD:
return ChangeType.ADD;
case MODIFY:
return ChangeType.MODIFY;
case RENAME:
return ChangeType.RENAME;
case DELETE:
return ChangeType.DELETE;
case COPY:
return ChangeType.COPY;
default:
throw new IllegalArgumentException("Unknown change type: " + diffEntry.getChangeType());
}
}
@Override
public Iterator<Hunk> iterator() {
String content = format(repository, diffEntry);