Skip to content

Commit f2f07fb

Browse files
author
Vladimir Kotal
committed
avoid null
1 parent 4d0d417 commit f2f07fb

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

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

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -683,48 +683,46 @@ private org.eclipse.jgit.lib.Repository getJGitRepository(String directory) thro
683683
File dotGit = Paths.get(directory, Constants.DOT_GIT).toFile();
684684
if (dotGit.isDirectory()) {
685685
return FileRepositoryBuilder.create(dotGit);
686-
} else if (dotGit.isFile()) {
687-
// Assume this is a sub-module.
688-
String gitDirValue;
689-
if ((gitDirValue = getGitDirValue(dotGit)) == null) {
690-
return null;
691-
}
686+
}
692687

693-
int dotGitIndex = gitDirValue.indexOf(Constants.DOT_GIT);
694-
if (dotGitIndex == -1) {
695-
return null;
696-
}
688+
// Assume this is a sub-module so dotGit is a file.
689+
String gitDirValue;
690+
if ((gitDirValue = getGitDirValue(dotGit)) == null) {
691+
throw new IOException("cannot get gitDir value from " + dotGit);
692+
}
697693

698-
String parentAbsPath;
699-
if (Paths.get(gitDirValue).isAbsolute()) {
700-
parentAbsPath = gitDirValue.substring(0, dotGitIndex - 1);
701-
} else {
702-
File parent = new File(directory, gitDirValue.substring(0, dotGitIndex + Constants.DOT_GIT.length()));
703-
parentAbsPath = parent.getCanonicalPath();
704-
int indexDotGitParent = parentAbsPath.indexOf(File.separator + Constants.DOT_GIT);
705-
if (indexDotGitParent == -1) {
706-
return null;
707-
}
694+
int dotGitIndex = gitDirValue.indexOf(Constants.DOT_GIT);
695+
if (dotGitIndex == -1) {
696+
throw new IOException("no .git in " + gitDirValue);
697+
}
708698

709-
parentAbsPath = parentAbsPath.substring(0, indexDotGitParent);
710-
if (!directory.startsWith(parentAbsPath)) {
711-
return null;
712-
}
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);
713708
}
714709

715-
// Assumes directory is canonical path too.
716-
String directoryRelative = directory.substring(parentAbsPath.length() + 1);
717-
718-
Repository parentRepository = FileRepositoryBuilder.
719-
create(Paths.get(parentAbsPath, Constants.DOT_GIT).toFile());
720-
if (parentRepository == null) {
721-
return null;
710+
parentAbsPath = parentAbsPath.substring(0, indexDotGitParent);
711+
if (!directory.startsWith(parentAbsPath)) {
712+
throw new IOException(directory + " does not start with " + parentAbsPath);
722713
}
714+
}
715+
716+
// Assumes directory is canonical path too.
717+
String directoryRelative = directory.substring(parentAbsPath.length() + 1);
723718

724-
return SubmoduleWalk.getSubmoduleRepository(parentRepository, directoryRelative);
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);
725723
}
726724

727-
return null;
725+
return SubmoduleWalk.getSubmoduleRepository(parentRepository, directoryRelative);
728726
}
729727

730728
private void rebuildTagList(File directory) {

0 commit comments

Comments
 (0)