vcs: remove unnecessary nullability checks

GitOrigin-RevId: c111201e1318f48bc196b31fcc48787aba34fc91
This commit is contained in:
Aleksey Pivovarov
2019-07-08 17:02:17 +03:00
committed by intellij-monorepo-bot
parent 841bcde75c
commit a7cbe46394
14 changed files with 30 additions and 50 deletions
@@ -221,13 +221,10 @@ private fun openRelativePath(path: String, request: OpenFileRequest): Boolean {
if (virtualFile == null) {
for (openedProject in projects) {
for (vcsRoot in ProjectLevelVcsManager.getInstance(openedProject).allVcsRoots) {
val root = vcsRoot.path
if (root != null) {
virtualFile = root.findFileByRelativePath(path)
if (virtualFile != null) {
project = openedProject
break
}
virtualFile = vcsRoot.path.findFileByRelativePath(path)
if (virtualFile != null) {
project = openedProject
break
}
}
}
@@ -264,7 +264,7 @@ public class VcsRepositoryManager implements Disposable, VcsListener {
Map<VirtualFile, Repository> newRootsMap = new HashMap<>();
for (VcsRoot root : myVcsManager.getAllVcsRoots()) {
VirtualFile rootPath = root.getPath();
if (rootPath != null && !knownRoots.contains(rootPath)) {
if (!knownRoots.contains(rootPath)) {
AbstractVcs vcs = root.getVcs();
VcsRepositoryCreator repositoryCreator = getRepositoryCreator(vcs);
if (repositoryCreator == null) continue;
@@ -9,7 +9,7 @@ open class CommonCheckinProjectAction : AbstractCommonCheckinAction() {
override fun getRoots(dataContext: VcsContext): Array<FilePath> =
ProjectLevelVcsManager.getInstance(dataContext.project!!).allVcsRoots
.filter { it.vcs!!.checkinEnvironment != null }
.map { getFilePath(it.path!!) }
.map { getFilePath(it.path) }
.toTypedArray()
override fun approximatelyHasRoots(dataContext: VcsContext): Boolean = true
@@ -427,19 +427,17 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope {
}
final VirtualFile vcsRoot = rootObject.getPath();
if (vcsRoot != null) {
boolean pathIsRoot = vcsRoot.equals(path.getVirtualFile());
for (VirtualFile contentRoot : myAffectedContentRoots) {
// since we don't know exact dirty mechanics, maybe we have 3 nested mappings like:
// /root -> vcs1, /root/child -> vcs2, /root/child/inner -> vcs1, and we have file /root/child/inner/file,
// mapping is detected as vcs1 with root /root/child/inner, but we could possibly have in scope
// "affected root" -> /root with scope = /root recursively
boolean strict = pathIsRoot && !myVcs.areDirectoriesVersionedItems();
if (VfsUtilCore.isAncestor(contentRoot, vcsRoot, strict)) {
THashSet<FilePath> dirsByRoot = myDirtyDirectoriesRecursively.get(contentRoot);
if (dirsByRoot != null && hasAncestor(dirsByRoot, path)) {
return true;
}
boolean pathIsRoot = vcsRoot.equals(path.getVirtualFile());
for (VirtualFile contentRoot : myAffectedContentRoots) {
// since we don't know exact dirty mechanics, maybe we have 3 nested mappings like:
// /root -> vcs1, /root/child -> vcs2, /root/child/inner -> vcs1, and we have file /root/child/inner/file,
// mapping is detected as vcs1 with root /root/child/inner, but we could possibly have in scope
// "affected root" -> /root with scope = /root recursively
boolean strict = pathIsRoot && !myVcs.areDirectoriesVersionedItems();
if (VfsUtilCore.isAncestor(contentRoot, vcsRoot, strict)) {
THashSet<FilePath> dirsByRoot = myDirtyDirectoriesRecursively.get(contentRoot);
if (dirsByRoot != null && hasAncestor(dirsByRoot, path)) {
return true;
}
}
}
@@ -240,7 +240,7 @@ public class VcsDirtyScopeManagerImpl extends VcsDirtyScopeManager implements Pr
for (VcsRoot root : roots) {
AbstractVcs vcs = root.getVcs();
VirtualFile path = root.getPath();
if (vcs != null && path != null) {
if (vcs != null) {
dirtyRoots.putValue(vcs, VcsUtil.getFilePath(path));
}
}
@@ -87,12 +87,9 @@ public class VcsRootIterator {
for (VcsRoot root : allRoots) {
final AbstractVcs vcs = root.getVcs();
if (vcs == null || Comparing.equal(vcs.getName(), myVcsName)) continue;
final VirtualFile path = root.getPath();
if (path != null) {
final String url = path.getUrl();
if (url.startsWith(ourPath)) {
myExcludedByOthers.add(url);
}
final String url = root.getPath().getUrl();
if (url.startsWith(ourPath)) {
myExcludedByOthers.add(url);
}
}
@@ -6,7 +6,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -51,11 +50,7 @@ public class VcsRootErrorsFinder {
Collection<VcsRootError> errors = new ArrayList<>();
List<String> mappedPaths = mappingsToPathsWithSelectedVcs(mappings);
for (VcsRoot root : vcsRoots) {
VirtualFile virtualFileFromRoot = root.getPath();
if (virtualFileFromRoot == null) {
continue;
}
String vcsPath = virtualFileFromRoot.getPath();
String vcsPath = root.getPath().getPath();
if (root.getVcs() != null && !mappedPaths.contains(vcsPath)) {
errors.add(new VcsRootErrorImpl(VcsRootError.Type.UNREGISTERED_ROOT, vcsPath, root.getVcs().getName()));
}
@@ -61,7 +61,7 @@ class VcsUsagesCollector : ProjectUsagesCollector() {
val projectMappedRoots = vcsManager.allVcsRoots
.filter { it.vcs == defaultVcs }
.filter { it.path != null && !explicitRoots.contains(it.path) }
.filter { !explicitRoots.contains(it.path) }
for (vcsRoot in projectMappedRoots) {
val metric = newMetric("project.mapped.root")
@@ -108,7 +108,7 @@ class AmendCommitHandlerImpl(private val workflowHandler: AbstractCommitWorkflow
override fun compute(indicator: ProgressIndicator): List<String> = roots.mapNotNull { vcsRoot ->
val amendAware = vcsRoot.vcs?.checkinEnvironment as? AmendCommitAware ?: return@mapNotNull null
vcsRoot.path?.let { amendAware.getLastCommitMessage(it) }
amendAware.getLastCommitMessage(vcsRoot.path)
}
}
}
@@ -145,7 +145,7 @@ public class VcsLogManager implements Disposable {
for (VcsRoot root : roots) {
AbstractVcs vcs = root.getVcs();
VirtualFile path = root.getPath();
if (vcs == null || path == null) {
if (vcs == null) {
LOG.debug("Skipping invalid VCS root: " + root);
continue;
}
@@ -70,15 +70,14 @@ class VcsIntegrationEnablerTest : VcsRootBaseTest() {
mock_init: String?,
vararg vcs_roots: String) {
for (vcsRoot in vcsRoots) {
assertTrue(File(vcsRoot.path!!.path, DOT_MOCK).mkdirs())
assertTrue(File(vcsRoot.path.path, DOT_MOCK).mkdirs())
}
val vcsRootsList = mutableListOf(*vcs_roots)
//default
if (vcsRootsList.isEmpty()) {
vcsRootsList.addAll(ContainerUtil.map(vcsRoots) { root ->
assert(root.path != null)
root.path!!.path
root.path.path
})
}
TestIntegrationEnabler(vcs).enable(vcsRoots)
@@ -21,10 +21,7 @@ fun getGitRootFiles(project: Project, files: Collection<FilePath>): Map<VirtualF
files.forEach { filePath ->
val fileVcs = projectLevelVcsManager.getVcsRootObjectFor(filePath)
if (fileVcs != null && fileVcs.vcs is GitVcs) {
val fileRoot = fileVcs.path
if (fileRoot != null) {
rootFiles.getOrPut(fileRoot) { HashSet() }.add(filePath)
}
rootFiles.getOrPut(fileVcs.path) { HashSet() }.add(filePath)
}
}
return rootFiles
@@ -83,10 +83,7 @@ public class GitAdd extends ScheduleForAdditionAction {
try {
if (!(vcsRoot.getVcs() instanceof GitVcs)) return;
VirtualFile root = vcsRoot.getPath();
if (root == null) return;
GitFileUtils.addPaths(project, root, paths);
GitFileUtils.addPaths(project, vcsRoot.getPath(), paths);
VcsFileUtil.markFilesDirty(project, paths);
}
catch (VcsException ex) {
@@ -366,7 +366,7 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory {
VcsRoot vcsRoot = vcsManager.getVcsRootObjectFor(path);
if (vcsRoot != null) {
VirtualFile root = vcsRoot.getPath();
if (git.equals(vcsRoot.getVcs()) && root != null) {
if (git.equals(vcsRoot.getVcs())) {
result.add(root);
}
}