|
|
|
@ -41,7 +41,9 @@ import java.nio.file.Path;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
@ -269,7 +271,7 @@ public class GitRepositoryService {
|
|
|
|
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
|
DiffFormatter diffFormatter = new DiffFormatter(out);
|
|
|
|
|
diffFormatter.setRepository(localRepo);
|
|
|
|
|
diffFormatter.format(earlierCommit.getId(), laterCommit.getId());
|
|
|
|
|
diffFormatter.format(laterCommit.getId(), earlierCommit.getId());
|
|
|
|
|
output = out.toString();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("Error occurred during diff computation. Message: " + e.getMessage());
|
|
|
|
@ -280,66 +282,22 @@ public class GitRepositoryService {
|
|
|
|
|
private List<FileChange> parseOutputDiff(String output, org.eclipse.jgit.lib.Repository repository, RevCommit commit) {
|
|
|
|
|
List<FileChange> changes = new ArrayList<>();
|
|
|
|
|
String[] strings = output.split("\n");
|
|
|
|
|
Map<String, List<String>> filesContent = getFilesContent(strings);
|
|
|
|
|
System.out.println(filesContent);
|
|
|
|
|
for(Map.Entry<String, List<String>> fileSterings: filesContent.entrySet()) {
|
|
|
|
|
FileChange fileChange = new FileChange();
|
|
|
|
|
int stringsLength = strings.length - 1;
|
|
|
|
|
for (int i = 0; i < strings.length; i++) {
|
|
|
|
|
while (i < stringsLength) {
|
|
|
|
|
Optional<String> maybeFileName = getFileName(strings[i]);
|
|
|
|
|
if (maybeFileName.isPresent()) {
|
|
|
|
|
fileChange = new FileChange();
|
|
|
|
|
fileChange.setFile(maybeFileName.get());
|
|
|
|
|
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())));
|
|
|
|
|
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get())));
|
|
|
|
|
fileChange.setFile(fileSterings.getKey());
|
|
|
|
|
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, fileSterings.getKey())));
|
|
|
|
|
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, fileSterings.getKey())));
|
|
|
|
|
try {
|
|
|
|
|
fileChange.setContainsBusinessLogic(futureBL.get());
|
|
|
|
|
fileChange.setContainsEntity(futureEntity.get());
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
LOG.warn(ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
/// вытащить другие изменения из коммита
|
|
|
|
|
fileChange = getChange(fileChange, fileSterings.getValue());
|
|
|
|
|
changes.add(fileChange);
|
|
|
|
|
}
|
|
|
|
|
LineChange lineChange = new LineChange();
|
|
|
|
|
if (strings[i].startsWith("-")) {
|
|
|
|
|
while ((i < stringsLength) && strings[i].startsWith("-")) {
|
|
|
|
|
if (strings[i].startsWith("---")) {
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
if (lineChange.getLineFrom() == null) {
|
|
|
|
|
lineChange.setLineFrom(strings[i]);
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
lineChange.setLineFrom(lineChange.getLineFrom() + "\n" + strings[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lineChange.setRemoved(true);
|
|
|
|
|
}
|
|
|
|
|
if (strings[i].startsWith("+")) {
|
|
|
|
|
while ((i < stringsLength) && strings[i].startsWith("+")) {
|
|
|
|
|
if (strings[i].startsWith("+++")) {
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
if (lineChange.getLineTo() == null) {
|
|
|
|
|
lineChange.setLineTo(strings[i]);
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
lineChange.setLineTo(lineChange.getLineTo() + "\n" + strings[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lineChange.setAdded(true);
|
|
|
|
|
}
|
|
|
|
|
if ((lineChange.getLineTo() != null) || (lineChange.getLineFrom() != null)
|
|
|
|
|
|| ((lineChange.getLineTo() != null) && (lineChange.getLineFrom() != null))) {
|
|
|
|
|
fileChange.getLineChanges().add(lineChange);
|
|
|
|
|
} else {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return changes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -368,6 +326,101 @@ public class GitRepositoryService {
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, List<String>> getFilesContent(String[] commitStrings) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
Map<String, List<String>> result = new HashMap<>();
|
|
|
|
|
while (i < commitStrings.length) {
|
|
|
|
|
Optional<String> maybeFileName = getFileName(commitStrings[i]);
|
|
|
|
|
if (maybeFileName.isEmpty()) {
|
|
|
|
|
i++;
|
|
|
|
|
} else {
|
|
|
|
|
i = skipLinesForNextFile(commitStrings, i);
|
|
|
|
|
result.put(maybeFileName.get(), getFileContent(commitStrings, i));
|
|
|
|
|
i += getFileContent(commitStrings, i).size() - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getFileContent(String[] commitsString, int i) {
|
|
|
|
|
List<String> result = new ArrayList<>();
|
|
|
|
|
while (i < commitsString.length && getFileName(commitsString[i]).isEmpty()) {
|
|
|
|
|
result.add(commitsString[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int skipLinesForNextFile(String[] commitStrings, int index) {
|
|
|
|
|
boolean isFilePrefixSkipped = false;
|
|
|
|
|
while (!isFilePrefixSkipped && (index < commitStrings.length)) {
|
|
|
|
|
if ((commitStrings[index].startsWith("diff --git a/"))
|
|
|
|
|
|| (commitStrings[index].startsWith("delete"))
|
|
|
|
|
|| (commitStrings[index].startsWith("new"))
|
|
|
|
|
|| (commitStrings[index].startsWith("index"))
|
|
|
|
|
|| (commitStrings[index].startsWith("@@"))
|
|
|
|
|
|| (commitStrings[index].startsWith("---"))
|
|
|
|
|
|| (commitStrings[index].startsWith("+++"))) {
|
|
|
|
|
index++;
|
|
|
|
|
} else {
|
|
|
|
|
isFilePrefixSkipped = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FileChange getChange(FileChange fileChange, List<String> fileContent){
|
|
|
|
|
int addedLine = 0;
|
|
|
|
|
int removedLine = 0;
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
boolean isRemoved = false;
|
|
|
|
|
boolean isAdded = false;
|
|
|
|
|
for (String line : fileContent){
|
|
|
|
|
LineChange lineChange = new LineChange();
|
|
|
|
|
if (line.startsWith("-")){
|
|
|
|
|
isRemoved = true;
|
|
|
|
|
if (isAdded) {
|
|
|
|
|
isAdded = false;
|
|
|
|
|
lineChange = setAdded(lineChange, builder);
|
|
|
|
|
builder.setLength(0);
|
|
|
|
|
}
|
|
|
|
|
builder.append(line).append("\n");
|
|
|
|
|
removedLine++;
|
|
|
|
|
} else if(line.startsWith("+")){
|
|
|
|
|
isAdded = true;
|
|
|
|
|
if (isRemoved) {
|
|
|
|
|
isRemoved = false;
|
|
|
|
|
lineChange = setRemoved(lineChange, builder);
|
|
|
|
|
builder.setLength(0);
|
|
|
|
|
}
|
|
|
|
|
builder.append(line).append("\n");
|
|
|
|
|
addedLine++;
|
|
|
|
|
} else {
|
|
|
|
|
if (isRemoved) {
|
|
|
|
|
lineChange = setRemoved(lineChange, builder);
|
|
|
|
|
builder.setLength(0);
|
|
|
|
|
} else if (isAdded){
|
|
|
|
|
lineChange = setAdded(lineChange, builder);
|
|
|
|
|
builder.setLength(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fileChange.setRemoved(removedLine == fileContent.size() - 1);
|
|
|
|
|
fileChange.setAdded(addedLine == fileContent.size() - 1);
|
|
|
|
|
return fileChange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LineChange setRemoved(LineChange lineChange, StringBuilder builder){
|
|
|
|
|
lineChange.setLineFrom(builder.toString());
|
|
|
|
|
lineChange.setRemoved(true);
|
|
|
|
|
return lineChange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LineChange setAdded(LineChange lineChange, StringBuilder builder){
|
|
|
|
|
lineChange.setLineTo(builder.toString());
|
|
|
|
|
lineChange.setAdded(true);
|
|
|
|
|
return lineChange;
|
|
|
|
|
}
|
|
|
|
|
public Page<GitRepository> findAll(Pageable pageable) {
|
|
|
|
|
return gitRepositoryRepository.findAll(pageable);
|
|
|
|
|
}
|
|
|
|
|