mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Make change types explicit
Without explicit change types, we cannot tell copy and rename apart.
This commit is contained in:
@@ -26,7 +26,6 @@ package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.github.sdorra.spotter.ContentTypes;
|
||||
import com.github.sdorra.spotter.Language;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.DiffFile;
|
||||
@@ -42,7 +41,7 @@ import java.util.OptionalInt;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
/**
|
||||
* TODO conflicts, copy and rename
|
||||
* TODO conflicts
|
||||
*/
|
||||
class DiffResultToDiffResultDtoMapper {
|
||||
|
||||
@@ -83,21 +82,29 @@ class DiffResultToDiffResultDtoMapper {
|
||||
String oldPath = file.getOldPath();
|
||||
|
||||
String path;
|
||||
if (isFilePath(newPath) && isFileNull(oldPath)) {
|
||||
path = newPath;
|
||||
dto.setType("add");
|
||||
} else if (isFileNull(newPath) && isFilePath(oldPath)) {
|
||||
path = oldPath;
|
||||
dto.setType("delete");
|
||||
} else if (!newPath.equals(oldPath)) {
|
||||
path = newPath;
|
||||
dto.setType("rename");
|
||||
} else if (isFilePath(newPath) && isFilePath(oldPath)) {
|
||||
path = newPath;
|
||||
dto.setType("modify");
|
||||
} else {
|
||||
// TODO copy?
|
||||
throw new IllegalStateException("no file without path");
|
||||
switch (file.getChangeType()) {
|
||||
case ADD:
|
||||
path = newPath;
|
||||
dto.setType("add");
|
||||
break;
|
||||
case DELETE:
|
||||
path = oldPath;
|
||||
dto.setType("delete");
|
||||
break;
|
||||
case RENAME:
|
||||
path = newPath;
|
||||
dto.setType("rename");
|
||||
break;
|
||||
case MODIFY:
|
||||
path = newPath;
|
||||
dto.setType("modify");
|
||||
break;
|
||||
case COPY:
|
||||
path = newPath;
|
||||
dto.setType("copy");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown change type: " + file.getChangeType());
|
||||
}
|
||||
|
||||
dto.setNewPath(newPath);
|
||||
@@ -119,14 +126,6 @@ class DiffResultToDiffResultDtoMapper {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private boolean isFilePath(String path) {
|
||||
return !isFileNull(path);
|
||||
}
|
||||
|
||||
private boolean isFileNull(String path) {
|
||||
return Strings.isNullOrEmpty(path) || "/dev/null".equals(path);
|
||||
}
|
||||
|
||||
private DiffResultDto.HunkDto mapHunk(Hunk hunk) {
|
||||
DiffResultDto.HunkDto dto = new DiffResultDto.HunkDto();
|
||||
dto.setContent(hunk.getRawHeader());
|
||||
|
||||
Reference in New Issue
Block a user