[lvcs] extract local history facade API (IJPL-161713)

GitOrigin-RevId: 0419a95c4dad771dfee05a6d1f0d100f30d6466e
This commit is contained in:
Dmitry Zhuravlev
2024-09-09 15:46:44 +02:00
committed by intellij-monorepo-bot
parent 2b0b3341f4
commit 05c79ef42f
5 changed files with 68 additions and 53 deletions

View File

@@ -72,12 +72,14 @@ com.intellij.history.core.LabelImpl
- a:getByteContent(com.intellij.history.core.tree.RootEntry,java.lang.String):com.intellij.history.ByteContent
- a:getLabelChangeId():J
c:com.intellij.history.core.LocalHistoryFacade
- <init>(com.intellij.history.core.ChangeList):V
- sf:Companion:com.intellij.history.core.LocalHistoryFacade$Companion
- <init>():V
- f:accept(com.intellij.history.core.changes.ChangeVisitor):V
- f:addChangeInTests(com.intellij.history.core.changes.StructuralChange):V
- f:addListener(com.intellij.history.core.LocalHistoryFacade$Listener,com.intellij.openapi.Disposable):V
- f:beginChangeSet():V
- f:contentChanged(java.lang.String,com.intellij.history.core.Content,J):V
- p:createStorage():com.intellij.history.core.ChangeListStorage
- f:created(java.lang.String,Z):V
- f:deleted(java.lang.String,com.intellij.history.core.tree.Entry):V
- f:endChangeSet(java.lang.String):V
@@ -85,6 +87,7 @@ c:com.intellij.history.core.LocalHistoryFacade
- bs:endChangeSet$default(com.intellij.history.core.LocalHistoryFacade,java.lang.String,com.intellij.history.ActivityId,I,java.lang.Object):V
- f:forceBeginChangeSet():V
- f:getChangeListInTests():com.intellij.history.core.ChangeList
- sf:getInstance():com.intellij.history.core.LocalHistoryFacade
- f:moved(java.lang.String,java.lang.String):V
- f:putLabelInTests(com.intellij.history.core.changes.PutLabelChange):V
- f:putSystemLabel(java.lang.String,java.lang.String,I):com.intellij.history.core.LabelImpl
@@ -94,6 +97,8 @@ c:com.intellij.history.core.LocalHistoryFacade
- f:renamed(java.lang.String,java.lang.String):V
- f:revertUpToChange(com.intellij.history.core.tree.RootEntry,J,java.lang.String,Z,Z):java.lang.String
- f:revertUpToChangeSet(com.intellij.history.core.tree.RootEntry,J,java.lang.String,Z,Z):java.lang.String
f:com.intellij.history.core.LocalHistoryFacade$Companion
- f:getInstance():com.intellij.history.core.LocalHistoryFacade
a:com.intellij.history.core.LocalHistoryFacade$Listener
- <init>():V
- changeAdded(com.intellij.history.core.changes.Change):V

View File

@@ -81,6 +81,7 @@
<applicationService serviceInterface="com.intellij.history.LocalHistory"
serviceImplementation="com.intellij.history.integration.LocalHistoryImpl"/>
<applicationService serviceImplementation="com.intellij.history.core.LocalHistoryFacade"/>
<virtualFileManagerListener
implementation="com.intellij.history.integration.LocalHistoryEventDispatcher$LocalHistoryFileManagerListener"/>
@@ -103,4 +104,4 @@
<listener class="com.intellij.history.integration.LocalHistoryEventDispatcher$LocalHistoryBulkFileListener"
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"/>
</applicationListeners>
</idea-plugin>
</idea-plugin>

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.history.core
import com.intellij.history.ActivityId
@@ -21,7 +7,10 @@ import com.intellij.history.core.changes.*
import com.intellij.history.core.tree.Entry
import com.intellij.history.core.tree.RootEntry
import com.intellij.history.integration.IdeaGateway
import com.intellij.history.utils.LocalHistoryLog
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.components.service
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.Project
@@ -30,11 +19,44 @@ import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.NlsContexts
import com.intellij.psi.codeStyle.MinusculeMatcher
import com.intellij.psi.codeStyle.NameUtil
import com.intellij.util.application
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.io.delete
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.TestOnly
import java.nio.file.Path
open class LocalHistoryFacade {
private val storageDir: Path
get() = Path.of(PathManager.getSystemPath(), "LocalHistory")
internal var changeList: ChangeList
private set
init {
changeList = ChangeList(createStorage())
}
@TestOnly
internal fun reset() {
storageDir.delete()
changeList = ChangeList(createStorage())
}
protected open fun createStorage(): ChangeListStorage {
var storage: ChangeListStorage
try {
storage = ChangeListStorageImpl(storageDir)
}
catch (e: Throwable) {
LocalHistoryLog.LOG.warn("cannot create storage, in-memory implementation will be used", e)
storage = InMemoryChangeListStorage()
}
return storage
}
open class LocalHistoryFacade(internal val changeList: ChangeList) {
private val listeners: MutableList<Listener> = ContainerUtil.createLockFreeCopyOnWriteList()
@get:TestOnly
@@ -188,6 +210,11 @@ open class LocalHistoryFacade(internal val changeList: ChangeList) {
open fun changeAdded(c: Change) = Unit
open fun changeSetFinished(changeSet: ChangeSet) = Unit
}
companion object {
@JvmStatic
fun getInstance(): LocalHistoryFacade = application.service()
}
}
@ApiStatus.Internal
@@ -322,4 +349,4 @@ fun LocalHistoryFacade.processContents(
if (before && !processContents(changeSet.id, path)) break
}
}
}

View File

@@ -11,7 +11,6 @@ import com.intellij.history.integration.revertion.DifferenceReverter
import com.intellij.history.utils.LocalHistoryLog
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.options.advanced.AdvancedSettings.Companion.getInt
import com.intellij.openapi.options.advanced.AdvancedSettingsChangeListener
@@ -25,13 +24,11 @@ import com.intellij.platform.lvcs.impl.RevisionId
import com.intellij.platform.lvcs.impl.diff.findEntry
import com.intellij.platform.lvcs.impl.operations.getRevertCommandName
import com.intellij.util.SystemProperties
import com.intellij.util.io.delete
import kotlinx.coroutines.*
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.TestOnly
import java.lang.Runnable
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.Throws
import kotlin.time.Duration.Companion.seconds
@ApiStatus.Internal
@@ -39,12 +36,13 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor
companion object {
private const val DAYS_TO_KEEP = "localHistory.daysToKeep"
/**
* @see [LocalHistory.getInstance]
* @see [LocalHistoryFacade.getInstance]
*/
@JvmStatic
fun getInstanceImpl(): LocalHistoryImpl = getInstance() as LocalHistoryImpl
val storageDir: Path
get() = Path.of(PathManager.getSystemPath(), "LocalHistory")
private fun getProjectId(p: Project): String = p.getLocationHash()
}
@@ -113,15 +111,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor
}
private fun initHistory() {
var storage: ChangeListStorage
try {
storage = ChangeListStorageImpl(storageDir)
}
catch (e: Throwable) {
LocalHistoryLog.LOG.warn("cannot create storage, in-memory implementation will be used", e)
storage = InMemoryChangeListStorage()
}
facade = LocalHistoryFacade(ChangeList(storage))
facade = LocalHistoryFacade.getInstance()
eventDispatcher = LocalHistoryEventDispatcher(facade!!, gateway)
}
@@ -151,7 +141,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor
@TestOnly
fun cleanupForNextTest() {
doDispose()
storageDir.delete()
facade?.reset()
init()
}

View File

@@ -1,23 +1,15 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.history.core;
public class InMemoryLocalHistoryFacade extends LocalHistoryFacade {
import org.jetbrains.annotations.NotNull;
public final class InMemoryLocalHistoryFacade extends LocalHistoryFacade {
public InMemoryLocalHistoryFacade() {
super(new ChangeList(new InMemoryChangeListStorage()));
}
@Override
protected @NotNull ChangeListStorage createStorage() {
return new InMemoryChangeListStorage();
}
}