Using renamed file hints improves processIdenticalFiles() performance
@@ -142,7 +142,7 @@ public class GitHistoryRefactoringMinerImpl implements GitHistoryRefactoringMine
RevCommit parentCommit = currentCommit.getParent(0);
populateFileContents(repository, parentCommit, filePathsBefore, fileContentsBefore, repositoryDirectoriesBefore);
populateFileContents(repository, currentCommit, filePathsCurrent, fileContentsCurrent, repositoryDirectoriesCurrent);
- List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = processIdenticalFiles(fileContentsBefore, fileContentsCurrent);
+ List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = processIdenticalFiles(fileContentsBefore, fileContentsCurrent, renamedFilesHint);
UMLModel parentUMLModel = createModel(fileContentsBefore, repositoryDirectoriesBefore);
UMLModel currentUMLModel = createModel(fileContentsCurrent, repositoryDirectoriesCurrent);
@@ -161,9 +161,19 @@ public class GitHistoryRefactoringMinerImpl implements GitHistoryRefactoringMine
return refactoringsAtRevision;
}
- public static List<MoveSourceFolderRefactoring> processIdenticalFiles(Map<String, String> fileContentsBefore, Map<String, String> fileContentsCurrent) throws IOException {
+ public static List<MoveSourceFolderRefactoring> processIdenticalFiles(Map<String, String> fileContentsBefore, Map<String, String> fileContentsCurrent,
+ Map<String, String> renamedFilesHint) throws IOException {
Map<String, String> identicalFiles = new HashMap<String, String>();
for(String key : fileContentsBefore.keySet()) {
+ //take advantage of renamed file hints, if available
+ if(renamedFilesHint.containsKey(key)) {
+ String renamedFile = renamedFilesHint.get(key);
+ String fileBefore = fileContentsBefore.get(key);
+ String fileAfter = fileContentsCurrent.get(renamedFile);
+ if(fileBefore.equals(fileAfter) || StringDistance.trivialCommentChange(fileBefore, fileAfter)) {
+ identicalFiles.put(key, renamedFile);
+ }
+ }
if(fileContentsCurrent.containsKey(key)) {
String fileBefore = fileContentsBefore.get(key);
String fileAfter = fileContentsCurrent.get(key);
@@ -327,7 +337,7 @@ public class GitHistoryRefactoringMinerImpl implements GitHistoryRefactoringMine
if (currentFolder.exists() && parentFolder.exists()) {
populateFileContents(currentFolder, filesCurrent, fileContentsCurrent, repositoryDirectoriesCurrent);
populateFileContents(parentFolder, filesBefore, fileContentsBefore, repositoryDirectoriesBefore);
- List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = processIdenticalFiles(fileContentsBefore, fileContentsCurrent);
+ List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = processIdenticalFiles(fileContentsBefore, fileContentsCurrent, renamedFilesHint);
UMLModel parentUMLModel = createModel(fileContentsBefore, repositoryDirectoriesBefore);
UMLModel currentUMLModel = createModel(fileContentsCurrent, repositoryDirectoriesCurrent);
// Diff between currentModel e parentModel
@@ -677,7 +687,7 @@ public class GitHistoryRefactoringMinerImpl implements GitHistoryRefactoringMine
Map<String, String> fileContentsCurrent = new ConcurrentHashMap<String, String>();
Map<String, String> renamedFilesHint = new ConcurrentHashMap<String, String>();
populateWithGitHubAPI(gitURL, currentCommitId, fileContentsBefore, fileContentsCurrent, renamedFilesHint, repositoryDirectoriesBefore, repositoryDirectoriesCurrent);
- List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = processIdenticalFiles(fileContentsBefore, fileContentsCurrent);
+ List<MoveSourceFolderRefactoring> moveSourceFolderRefactorings = processIdenticalFiles(fileContentsBefore, fileContentsCurrent, renamedFilesHint);
UMLModel currentUMLModel = createModel(fileContentsCurrent, repositoryDirectoriesCurrent);
UMLModel parentUMLModel = createModel(fileContentsBefore, repositoryDirectoriesBefore);
// Diff between currentModel e parentModel
