Skip to content

Commit

Permalink
Simplify GitEntry.getEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Sep 5, 2023
1 parent f337313 commit 6552751
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/svnserver/repository/git/GitEntry.kt
Expand Up @@ -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?
}
2 changes: 1 addition & 1 deletion src/main/kotlin/svnserver/repository/git/GitEntryImpl.kt
Expand Up @@ -30,7 +30,7 @@ internal open class GitEntryImpl(parentProps: Array<GitProperty>, parentPath: St
}

@Throws(IOException::class)
override fun getEntry(name: String, stringInterner: (String) -> String): GitFile? {
override fun getEntry(name: String): GitFile? {
return null
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/svnserver/repository/git/GitFile.kt
Expand Up @@ -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.
Expand Down
Expand Up @@ -24,7 +24,7 @@ internal class GitFileEmptyTree(override val branch: GitBranch, parentPath: Stri
return super<GitEntryImpl>.createChild(name, isDir, stringInterner)
}

override fun getEntry(name: String, stringInterner: (String) -> String): GitFile? {
override fun getEntry(name: String): GitFile? {
return null
}

Expand Down
Expand Up @@ -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]
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/kotlin/svnserver/repository/git/GitRepository.kt
Expand Up @@ -89,9 +89,11 @@ class GitRepository(

@Throws(IOException::class)
fun collectProperties(treeEntry: GitTreeEntry, entryProvider: Iterable<GitTreeEntry>): Array<GitProperty> {
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<GitProperty>()
try {
for (entry in entryProvider) {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/svnserver/repository/git/GitRevision.kt
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/svnserver/repository/git/GitWriter.kt
Expand Up @@ -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<GitFile>
val element: GitFile
get() {
Expand All @@ -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)
}

Expand All @@ -87,7 +87,7 @@ class GitWriter internal constructor(val branch: GitBranch, private val pusher:
@Throws(IOException::class)
override fun checkProperties(name: String?, props: Map<String, String>, 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)) {
Expand All @@ -108,7 +108,7 @@ class GitWriter internal constructor(val branch: GitBranch, private val pusher:
@Throws(IOException::class)
override fun checkProperties(name: String?, props: Map<String, String>, 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) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/svnserver/server/command/CommitCmd.kt
Expand Up @@ -102,7 +102,6 @@ class CommitCmd : BaseCmd<Params>() {
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<VcsConsumer<GitCommitBuilder>>()
Expand All @@ -112,7 +111,7 @@ class CommitCmd : BaseCmd<Params>() {
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))
}

}
Expand Down Expand Up @@ -144,7 +143,7 @@ class CommitCmd : BaseCmd<Params>() {
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)
Expand Down Expand Up @@ -203,7 +202,7 @@ class CommitCmd : BaseCmd<Params>() {
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)
Expand All @@ -230,7 +229,7 @@ class CommitCmd : BaseCmd<Params>() {
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 ->
Expand Down Expand Up @@ -455,7 +454,7 @@ class CommitCmd : BaseCmd<Params>() {

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)
Expand Down

0 comments on commit 6552751

Please sign in to comment.