Skip to content

Commit 21dfa23

Browse files
author
Vladimir Kotal
committed
avoid using SubmoduleWalk
1 parent f2f07fb commit 21dfa23

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -680,49 +680,24 @@ private String getGitDirValue(File dotGit) {
680680
}
681681

682682
private org.eclipse.jgit.lib.Repository getJGitRepository(String directory) throws IOException {
683-
File dotGit = Paths.get(directory, Constants.DOT_GIT).toFile();
684-
if (dotGit.isDirectory()) {
685-
return FileRepositoryBuilder.create(dotGit);
683+
File dotGitFile = Paths.get(directory, Constants.DOT_GIT).toFile();
684+
if (dotGitFile.isDirectory()) {
685+
return FileRepositoryBuilder.create(dotGitFile);
686686
}
687687

688-
// Assume this is a sub-module so dotGit is a file.
688+
// Assume this is a sub-module so dotGitFile is a file.
689689
String gitDirValue;
690-
if ((gitDirValue = getGitDirValue(dotGit)) == null) {
691-
throw new IOException("cannot get gitDir value from " + dotGit);
690+
if ((gitDirValue = getGitDirValue(dotGitFile)) == null) {
691+
throw new IOException("cannot get gitDir value from " + dotGitFile);
692692
}
693693

694-
int dotGitIndex = gitDirValue.indexOf(Constants.DOT_GIT);
695-
if (dotGitIndex == -1) {
696-
throw new IOException("no .git in " + gitDirValue);
694+
// If the gitDir value is relative path, make it absolute. This is necessary for the
695+
File gitDirFile = new File(gitDirValue);
696+
if (!gitDirFile.isAbsolute()) {
697+
gitDirFile = new File(directory, gitDirValue);
697698
}
698699

699-
String parentAbsPath;
700-
if (Paths.get(gitDirValue).isAbsolute()) {
701-
parentAbsPath = gitDirValue.substring(0, dotGitIndex - 1);
702-
} else {
703-
File parent = new File(directory, gitDirValue.substring(0, dotGitIndex + Constants.DOT_GIT.length()));
704-
parentAbsPath = parent.getCanonicalPath();
705-
int indexDotGitParent = parentAbsPath.indexOf(File.separator + Constants.DOT_GIT);
706-
if (indexDotGitParent == -1) {
707-
throw new IOException("not .git in " + parentAbsPath);
708-
}
709-
710-
parentAbsPath = parentAbsPath.substring(0, indexDotGitParent);
711-
if (!directory.startsWith(parentAbsPath)) {
712-
throw new IOException(directory + " does not start with " + parentAbsPath);
713-
}
714-
}
715-
716-
// Assumes directory is canonical path too.
717-
String directoryRelative = directory.substring(parentAbsPath.length() + 1);
718-
719-
Repository parentRepository = FileRepositoryBuilder.
720-
create(Paths.get(parentAbsPath, Constants.DOT_GIT).toFile());
721-
if (parentRepository == null) {
722-
throw new IOException("cannot create parent repository from " + parentAbsPath);
723-
}
724-
725-
return SubmoduleWalk.getSubmoduleRepository(parentRepository, directoryRelative);
700+
return new FileRepositoryBuilder().setWorkTree(new File(directory)).setGitDir(gitDirFile).build();
726701
}
727702

728703
private void rebuildTagList(File directory) {

0 commit comments

Comments
 (0)