From 6552751c45a55d59f83f3ef1fdada4947aec47ad Mon Sep 17 00:00:00 2001 From: Marat Radchenko Date: Tue, 5 Sep 2023 12:10:25 +0300 Subject: [PATCH] Simplify GitEntry.getEntry --- .../kotlin/svnserver/repository/git/GitEntry.kt | 2 +- .../svnserver/repository/git/GitEntryImpl.kt | 2 +- .../kotlin/svnserver/repository/git/GitFile.kt | 2 +- .../repository/git/GitFileEmptyTree.kt | 2 +- .../repository/git/GitFileTreeEntry.kt | 2 +- .../svnserver/repository/git/GitRepository.kt | 17 +++++++++++------ .../svnserver/repository/git/GitRevision.kt | 2 +- .../svnserver/repository/git/GitWriter.kt | 8 ++++---- .../svnserver/server/command/CommitCmd.kt | 11 +++++------ 9 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/svnserver/repository/git/GitEntry.kt b/src/main/kotlin/svnserver/repository/git/GitEntry.kt index 3af745b3..32bf5d27 100644 --- a/src/main/kotlin/svnserver/repository/git/GitEntry.kt +++ b/src/main/kotlin/svnserver/repository/git/GitEntry.kt @@ -22,5 +22,5 @@ interface GitEntry { fun createChild(name: String, isDir: Boolean, stringInterner: (String) -> String): GitEntry @Throws(IOException::class) - fun getEntry(name: String, stringInterner: (String) -> String): GitFile? + fun getEntry(name: String): GitFile? } diff --git a/src/main/kotlin/svnserver/repository/git/GitEntryImpl.kt b/src/main/kotlin/svnserver/repository/git/GitEntryImpl.kt index 4f3a8564..b3a77ddc 100644 --- a/src/main/kotlin/svnserver/repository/git/GitEntryImpl.kt +++ b/src/main/kotlin/svnserver/repository/git/GitEntryImpl.kt @@ -30,7 +30,7 @@ internal open class GitEntryImpl(parentProps: Array, parentPath: St } @Throws(IOException::class) - override fun getEntry(name: String, stringInterner: (String) -> String): GitFile? { + override fun getEntry(name: String): GitFile? { return null } } diff --git a/src/main/kotlin/svnserver/repository/git/GitFile.kt b/src/main/kotlin/svnserver/repository/git/GitFile.kt index b0086bbd..4372d5ab 100644 --- a/src/main/kotlin/svnserver/repository/git/GitFile.kt +++ b/src/main/kotlin/svnserver/repository/git/GitFile.kt @@ -30,7 +30,7 @@ interface GitFile : GitEntry { } @Throws(IOException::class) - override fun getEntry(name: String, stringInterner: (String) -> String): GitFile? + override fun getEntry(name: String): GitFile? /** * Get native repository content hash for cheap content modification check. diff --git a/src/main/kotlin/svnserver/repository/git/GitFileEmptyTree.kt b/src/main/kotlin/svnserver/repository/git/GitFileEmptyTree.kt index 9f17182c..9d0c34d4 100644 --- a/src/main/kotlin/svnserver/repository/git/GitFileEmptyTree.kt +++ b/src/main/kotlin/svnserver/repository/git/GitFileEmptyTree.kt @@ -24,7 +24,7 @@ internal class GitFileEmptyTree(override val branch: GitBranch, parentPath: Stri return super.createChild(name, isDir, stringInterner) } - override fun getEntry(name: String, stringInterner: (String) -> String): GitFile? { + override fun getEntry(name: String): GitFile? { return null } diff --git a/src/main/kotlin/svnserver/repository/git/GitFileTreeEntry.kt b/src/main/kotlin/svnserver/repository/git/GitFileTreeEntry.kt index 9ead82b1..1fadb066 100644 --- a/src/main/kotlin/svnserver/repository/git/GitFileTreeEntry.kt +++ b/src/main/kotlin/svnserver/repository/git/GitFileTreeEntry.kt @@ -107,7 +107,7 @@ internal class GitFileTreeEntry private constructor( } @Throws(IOException::class) - override fun getEntry(name: String, stringInterner: (String) -> String): GitFile? { + override fun getEntry(name: String): GitFile? { return entries[name] } diff --git a/src/main/kotlin/svnserver/repository/git/GitRepository.kt b/src/main/kotlin/svnserver/repository/git/GitRepository.kt index e8dddb7c..fb14893a 100644 --- a/src/main/kotlin/svnserver/repository/git/GitRepository.kt +++ b/src/main/kotlin/svnserver/repository/git/GitRepository.kt @@ -89,9 +89,11 @@ class GitRepository( @Throws(IOException::class) fun collectProperties(treeEntry: GitTreeEntry, entryProvider: Iterable): Array { - if (treeEntry.fileMode.objectType == Constants.OBJ_BLOB) return GitProperty.emptyArray - var props = directoryPropertyCache[treeEntry.objectId.`object`] - if (props == null) { + if (treeEntry.fileMode.objectType == Constants.OBJ_BLOB) { + return GitProperty.emptyArray + } + + return directoryPropertyCache.computeIfAbsent(treeEntry.objectId.`object`) { val propList = ArrayList() try { for (entry in entryProvider) { @@ -102,10 +104,13 @@ class GitRepository( } } catch (ignored: SvnForbiddenException) { } - props = propList.toTypedArray() - directoryPropertyCache[treeEntry.objectId.`object`] = if (props.isEmpty()) { GitProperty.emptyArray } else { props } + val props = propList.toTypedArray() + if (props.isEmpty()) { + GitProperty.emptyArray + } else { + props + } } - return props } @Throws(IOException::class) diff --git a/src/main/kotlin/svnserver/repository/git/GitRevision.kt b/src/main/kotlin/svnserver/repository/git/GitRevision.kt index 604d111c..8bc0bc0f 100644 --- a/src/main/kotlin/svnserver/repository/git/GitRevision.kt +++ b/src/main/kotlin/svnserver/repository/git/GitRevision.kt @@ -77,7 +77,7 @@ class GitRevision internal constructor( if (pathItem.isEmpty()) { continue } - result = result!!.getEntry(pathItem, branch.repository.context.shared.stringInterner) + result = result!!.getEntry(pathItem) if (result == null) { return null } diff --git a/src/main/kotlin/svnserver/repository/git/GitWriter.kt b/src/main/kotlin/svnserver/repository/git/GitWriter.kt index 2c08bede..82cbe930 100644 --- a/src/main/kotlin/svnserver/repository/git/GitWriter.kt +++ b/src/main/kotlin/svnserver/repository/git/GitWriter.kt @@ -56,7 +56,7 @@ class GitWriter internal constructor(val branch: GitBranch, private val pusher: inserter.use { } } - private abstract class CommitAction(val root: GitFile) { + private abstract class CommitAction(root: GitFile) { private val treeStack: Deque val element: GitFile get() { @@ -65,7 +65,7 @@ class GitWriter internal constructor(val branch: GitBranch, private val pusher: @Throws(IOException::class) fun openDir(name: String) { - val file: GitFile = treeStack.element().getEntry(name, root.branch.repository.context.shared.stringInterner) ?: throw IllegalStateException("Invalid state: can't find file $name in created commit.") + val file: GitFile = treeStack.element().getEntry(name) ?: throw IllegalStateException("Invalid state: can't find file $name in created commit.") treeStack.push(file) } @@ -87,7 +87,7 @@ class GitWriter internal constructor(val branch: GitBranch, private val pusher: @Throws(IOException::class) override fun checkProperties(name: String?, props: Map, deltaConsumer: GitDeltaConsumer?) { val dir: GitFile = element - val node: GitFile = (if (name == null) dir else dir.getEntry(name, root.branch.repository.context.shared.stringInterner)) ?: throw IllegalStateException("Invalid state: can't find entry $name in created commit.") + val node: GitFile = (if (name == null) dir else dir.getEntry(name)) ?: throw IllegalStateException("Invalid state: can't find entry $name in created commit.") if (deltaConsumer != null) { assert((node.filter != null)) if (deltaConsumer.migrateFilter(node.filter)) { @@ -108,7 +108,7 @@ class GitWriter internal constructor(val branch: GitBranch, private val pusher: @Throws(IOException::class) override fun checkProperties(name: String?, props: Map, deltaConsumer: GitDeltaConsumer?) { val dir: GitFile = element - val node: GitFile = (if (name == null) dir else dir.getEntry(name, root.branch.repository.context.shared.stringInterner)) ?: throw IllegalStateException("Invalid state: can't find entry $name in created commit.") + val node: GitFile = (if (name == null) dir else dir.getEntry(name)) ?: throw IllegalStateException("Invalid state: can't find entry $name in created commit.") if (deltaConsumer != null) { assert((node.filter != null)) if (node.filter!!.name != deltaConsumer.filterName) { diff --git a/src/main/kotlin/svnserver/server/command/CommitCmd.kt b/src/main/kotlin/svnserver/server/command/CommitCmd.kt index 6df6f80d..c0140df4 100644 --- a/src/main/kotlin/svnserver/server/command/CommitCmd.kt +++ b/src/main/kotlin/svnserver/server/command/CommitCmd.kt @@ -102,7 +102,6 @@ class CommitCmd : BaseCmd() { val entry: GitEntry, // Old source entry (source) val source: GitFile?, val head: Boolean, - val stringInterner: (String) -> String, ) { val props = if (source != null) HashMap(source.properties) else HashMap() val changes = ArrayList>() @@ -112,7 +111,7 @@ class CommitCmd : BaseCmd() { if (source == null) { throw SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "Can't find node: $name")) } - return source.getEntry(name, stringInterner) ?: throw SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "Can't find node: " + name + " in " + source.fullPath)) + return source.getEntry(name) ?: throw SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "Can't find node: " + name + " in " + source.fullPath)) } } @@ -144,7 +143,7 @@ class CommitCmd : BaseCmd() { log.debug("Add dir: {}", args.name) source = null } - val updater = EntryUpdater(parent.entry, source, false, context.server.sharedContext.stringInterner) + val updater = EntryUpdater(parent.entry, source, false) paths[args.token] = updater parent.changes.add(VcsConsumer { treeBuilder: GitCommitBuilder -> treeBuilder.addDir(StringHelper.baseName(args.name), source) @@ -203,7 +202,7 @@ class CommitCmd : BaseCmd() { for (i in 1 until rootPath.size) { val name: String = rootPath[i] val entry: GitFile = lastUpdater.getEntry(name) - val updater = EntryUpdater(entry, entry, true, context.server.sharedContext.stringInterner) + val updater = EntryUpdater(entry, entry, true) lastUpdater.changes.add(VcsConsumer { treeBuilder: GitCommitBuilder -> treeBuilder.openDir(name) updateDir(treeBuilder, updater) @@ -230,7 +229,7 @@ class CommitCmd : BaseCmd() { log.debug("Modify dir: {} (rev: {})", args.name, rev) val sourceDir: GitFile = parent.getEntry(StringHelper.baseName(args.name)) context.checkRead(sourceDir.fullPath) - val dir = EntryUpdater(sourceDir, sourceDir, parent.head, context.server.sharedContext.stringInterner) + val dir = EntryUpdater(sourceDir, sourceDir, parent.head) if ((rev >= 0) && (parent.head)) checkUpToDate(sourceDir, rev) paths[args.token] = dir parent.changes.add(VcsConsumer { treeBuilder: GitCommitBuilder -> @@ -455,7 +454,7 @@ class CommitCmd : BaseCmd() { init { val entry: GitFile = context.branch.latestRevision.getFile("") ?: throw IllegalStateException("Repository root entry not found.") - rootEntry = EntryUpdater(entry, entry, true, context.server.sharedContext.stringInterner) + rootEntry = EntryUpdater(entry, entry, true) paths = HashMap() files = HashMap() locks = getLocks(context, params.locks)