vcs: extract isUnder to util

GitOrigin-RevId: 6769fc066e578ee1cf843d9b1c8f29321c6c144e
This commit is contained in:
Dmitry Zhuravlev
2019-11-25 13:39:33 +00:00
committed by intellij-monorepo-bot
parent f74f118ec7
commit 41e87f6205
3 changed files with 15 additions and 6 deletions
@@ -16,6 +16,7 @@ import com.intellij.openapi.vfs.newvfs.events.*
import com.intellij.util.EventDispatcher
import com.intellij.util.ui.update.ComparableObject
import com.intellij.util.ui.update.Update
import com.intellij.vcsUtil.VcsFileUtilKt.isUnder
import com.intellij.vcsUtil.VcsUtil
import com.intellij.vfs.AsyncVfsEventsListener
import com.intellij.vfs.AsyncVfsEventsPostProcessor
@@ -61,7 +62,7 @@ abstract class VcsRepositoryIgnoredFilesHolderBase<REPOSITORY : Repository>(
override fun getIgnoredFilePaths(): Set<FilePath> = SET_LOCK.read { ignoredSet.toHashSet() }
override fun containsFile(file: FilePath) =
SET_LOCK.read { isUnder(ignoredSet, file) }
SET_LOCK.read { isUnder(repositoryRootPath, ignoredSet, file) }
override fun getSize() = SET_LOCK.read { ignoredSet.size }
@@ -140,7 +141,7 @@ abstract class VcsRepositoryIgnoredFilesHolderBase<REPOSITORY : Repository>(
val ignored = SET_LOCK.read { ignoredSet.toHashSet() }
for (filePath in ignored) {
if (isUnder(filePathsSet, filePath)) {
if (isUnder(repositoryRootPath, filePathsSet, filePath)) {
removedIgnoredFilePaths.add(filePath)
}
}
@@ -197,7 +198,7 @@ abstract class VcsRepositoryIgnoredFilesHolderBase<REPOSITORY : Repository>(
private fun addNotContainedIgnores(ignored: Collection<FilePath>) =
SET_LOCK.write {
ignored.forEach { ignored ->
if (!isUnder(ignoredSet, ignored)) {
if (!isUnder(repositoryRootPath, ignoredSet, ignored)) {
ignoredSet.add(ignored)
}
}
@@ -224,9 +225,6 @@ abstract class VcsRepositoryIgnoredFilesHolderBase<REPOSITORY : Repository>(
listeners.multicaster.updateFinished(paths, isFullRescan)
}
private fun isUnder(parents: Set<FilePath>, child: FilePath) =
generateSequence(child) { if (repositoryRootPath == it) null else it.parentPath }.any { it in parents }
@TestOnly
inner class Waiter : VcsIgnoredHolderUpdateListener {
@@ -0,0 +1,10 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.vcsUtil
import com.intellij.openapi.vcs.FilePath
object VcsFileUtilKt {
@JvmStatic
fun isUnder(repositoryRootPath: FilePath, parents: Set<FilePath>, child: FilePath) =
generateSequence(child) { if (repositoryRootPath == it) null else it.parentPath }.any { it in parents }
}
@@ -37,6 +37,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import static com.intellij.dvcs.ignore.VcsRepositoryIgnoredFilesHolderBase.getAffectedFilePaths;
import static com.intellij.vcsUtil.VcsFileUtilKt.isUnder;
/**
* <p>