|
|
|
@ -12,10 +12,15 @@ import org.eclipse.jgit.api.ListBranchCommand;
|
|
|
|
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
|
|
|
import org.eclipse.jgit.diff.DiffFormatter;
|
|
|
|
|
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
|
|
|
|
import org.eclipse.jgit.lib.ObjectId;
|
|
|
|
|
import org.eclipse.jgit.lib.ObjectLoader;
|
|
|
|
|
import org.eclipse.jgit.lib.ObjectReader;
|
|
|
|
|
import org.eclipse.jgit.lib.Repository;
|
|
|
|
|
import org.eclipse.jgit.revwalk.RevCommit;
|
|
|
|
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
|
|
|
|
import ru.ulstu.extractor.model.Author;
|
|
|
|
|
import ru.ulstu.extractor.model.Branch;
|
|
|
|
|
import ru.ulstu.extractor.model.Commit;
|
|
|
|
@ -28,6 +33,7 @@ import java.io.IOException;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@ -44,6 +50,12 @@ public class GitRepositoryService {
|
|
|
|
|
@Value("${extractor.custom-projects-dir}")
|
|
|
|
|
private String customProjectsDir;
|
|
|
|
|
|
|
|
|
|
private final StructuralUnitService structuralUnitService;
|
|
|
|
|
|
|
|
|
|
public GitRepositoryService(StructuralUnitService structuralUnitService) {
|
|
|
|
|
this.structuralUnitService = structuralUnitService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Branch> getRemoteBranches(String url) throws GitAPIException, IOException {
|
|
|
|
|
cloneOrUpdateRepo(url);
|
|
|
|
|
Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
|
|
|
@ -177,10 +189,10 @@ public class GitRepositoryService {
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("Error occurred during diff computation. Message: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return parseOutputDiff(output);
|
|
|
|
|
return parseOutputDiff(output, localRepo, laterCommit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<FileChange> parseOutputDiff(String output) {
|
|
|
|
|
private List<FileChange> parseOutputDiff(String output, Repository repository, RevCommit commit) {
|
|
|
|
|
List<FileChange> changes = new ArrayList<>();
|
|
|
|
|
String[] strings = output.split("\n");
|
|
|
|
|
FileChange fileChange = new FileChange();
|
|
|
|
@ -191,6 +203,9 @@ public class GitRepositoryService {
|
|
|
|
|
if (maybeFileName.isPresent()) {
|
|
|
|
|
fileChange = new FileChange();
|
|
|
|
|
fileChange.setFile(maybeFileName.get());
|
|
|
|
|
fileChange.setContainsEntity(
|
|
|
|
|
structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get()))
|
|
|
|
|
);
|
|
|
|
|
/// вытащить другие изменения из коммита
|
|
|
|
|
changes.add(fileChange);
|
|
|
|
|
}
|
|
|
|
@ -226,6 +241,22 @@ public class GitRepositoryService {
|
|
|
|
|
return changes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getContent(Repository repository, RevCommit commit, String path) {
|
|
|
|
|
try (TreeWalk treeWalk = TreeWalk.forPath(repository, path, commit.getTree())) {
|
|
|
|
|
if (treeWalk != null) {
|
|
|
|
|
ObjectId blobId = treeWalk.getObjectId(0);
|
|
|
|
|
try (ObjectReader objectReader = repository.newObjectReader()) {
|
|
|
|
|
ObjectLoader objectLoader = objectReader.open(blobId);
|
|
|
|
|
byte[] bytes = objectLoader.getBytes();
|
|
|
|
|
return new String(bytes, StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Optional<String> getFileName(String commitString) {
|
|
|
|
|
String startString = "diff --git a/";
|
|
|
|
|
if (commitString.startsWith(startString)) {
|
|
|
|
|