Skip to content

Commit

Permalink
feat(vcs): Add Git-specific configuration options for submodule handling
Browse files Browse the repository at this point in the history
 For large repositories with many layers of nested Git submodules, the
 download process can be very time-consuming and often results in
 duplicate projects in the tree of nested submodules.
 This feature introduces configuration options to limit the recursive
 checkout of nested Git submodules to the first layer, optimizing
 performance and reducing redundancy. Additionally, it also allows to
 limit the depth of commit history to fetch when downloading
 the projects.

Signed-off-by: Wolfgang Klenk <[email protected]>
  • Loading branch information
wkl3nk committed Nov 11, 2024
1 parent 9370898 commit c66ccf6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
22 changes: 22 additions & 0 deletions integrations/schemas/ort-configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@
"items": {
"$ref": "#/definitions/SourceCodeOrigins"
}
},
"versionControlSystems": {
"type": "object",
"properties": {
"Git": {
"type": "object",
"properties": {
"options": {
"type": "object",
"properties": {
"submoduleHistoryDepth": {
"type": "integer",
"minimum": 1
},
"updateNestedSubmodules": {
"type": "boolean"
}
}
}
}
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private const val REPO_REV_FOR_VERSION = "371b23f37da064687518bace268d607a92ecbe
private const val REPO_PATH_FOR_VERSION = "specs"

class GitDownloadFunTest : StringSpec() {
private val git = Git()
private val git = Git.create()
private lateinit var outputDir: File

override suspend fun beforeTest(testCase: TestCase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private val tags = mapOf(
)

class GitFunTest : WordSpec({
val git = Git()
val git = Git.create()
val vcsInfo = VcsInfo(
type = VcsType.GIT,
url = "https://github.com/oss-review-toolkit/ort-test-data-git.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType

class GitWorkingTreeFunTest : StringSpec({
val git = Git()
val git = Git.create()
val repoDir = tempdir()
val vcsInfo = VcsInfo(
type = VcsType.GIT,
Expand Down
22 changes: 11 additions & 11 deletions plugins/version-control-systems/git/src/main/kotlin/Git.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,11 @@ import org.eclipse.jgit.transport.sshd.ServerKeyDatabase
import org.eclipse.jgit.transport.sshd.SshdSessionFactory

import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.downloader.VersionControlSystemFactory
import org.ossreviewtoolkit.downloader.WorkingTree
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.config.VersionControlSystemConfiguration
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Options
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.collectMessages
import org.ossreviewtoolkit.utils.common.safeMkdirs
import org.ossreviewtoolkit.utils.common.withoutPrefix
import org.ossreviewtoolkit.utils.common.*
import org.ossreviewtoolkit.utils.ort.requestPasswordAuthentication
import org.ossreviewtoolkit.utils.ort.showStackTrace

Expand Down Expand Up @@ -97,10 +91,9 @@ object GitCommand : CommandLineTool {
override fun displayName(): String = "Git"
}

class Git internal constructor(
private val vcsConfig: VersionControlSystemConfiguration = VersionControlSystemConfiguration()
) : VersionControlSystem(GitCommand) {
class Git private constructor(val vcsConfig: VersionControlSystemConfiguration): VersionControlSystem(GitCommand) {

Check notice on line 94 in plugins/version-control-systems/git/src/main/kotlin/Git.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Class member can have 'private' visibility

Property 'vcsConfig' could be private

Check notice

Code scanning / QDJVMC

Class member can have 'private' visibility Note

Property 'vcsConfig' could be private
companion object {
const val VCS_NAME = "Git"

init {
// Make sure that JGit uses the exact same authentication information as ORT itself. This addresses
Expand Down Expand Up @@ -130,19 +123,26 @@ class Git internal constructor(

SshSessionFactory.setInstance(sessionFactory)
}

// Use the factory to create a new instance of Git (convenience function)
fun create() : Git {
return Factory().create(VersionControlSystemConfiguration()) as Git
}
}

override val type = VcsType.GIT.toString()
override val priority = 100
override val latestRevisionNames = listOf("HEAD", "@")

class Factory : VersionControlSystemFactory(VcsType.GIT.toString(), 100) {
class Factory : VersionControlSystemFactory<VersionControlSystemConfiguration>(VCS_NAME) {
override fun create(config: VersionControlSystemConfiguration): VersionControlSystem {
return Git(config)
}

override fun parseConfig(options: Options, secrets: Options): VersionControlSystemConfiguration {
TODO("Not yet implemented")
}

}

override fun getVersion() = GitCommand.getVersion(null)
Expand Down
15 changes: 11 additions & 4 deletions plugins/version-control-systems/git/src/main/kotlin/GitRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ object GitRepoCommand : CommandLineTool {
}

@Suppress("UnusedPrivateProperty")
class GitRepo internal constructor() : VersionControlSystem(GitRepoCommand) {
class GitRepo private constructor(private val vcsConfig: VersionControlSystemConfiguration) :

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Property "vcsConfig" is never used
VersionControlSystem(GitRepoCommand) {

companion object {
// Use the factory to create a new instance of GitRepo (convenience function)
fun create(): GitRepo {
return Factory().create(VersionControlSystemConfiguration()) as GitRepo
}
}

override val type = VcsType.GIT_REPO.toString()
override val latestRevisionNames = listOf("HEAD", "@")

class Factory : VersionControlSystemFactory(VcsType.GIT_REPO.toString(), 50) {
override fun create(config: VersionControlSystemConfiguration): VersionControlSystem {
return GitRepo()
return GitRepo(config)
}

override fun parseConfig(options: Options, secrets: Options): VersionControlSystemConfiguration {
Expand Down Expand Up @@ -150,8 +158,7 @@ class GitRepo internal constructor() : VersionControlSystem(GitRepoCommand) {

paths.forEach { path ->
// Add the nested Repo project.
val workingTree = Git.Factory().create(VersionControlSystemConfiguration())
.getWorkingTree(getRootPath().resolve(path))
val workingTree = Git.create().getWorkingTree(getRootPath().resolve(path))
nested[path] = workingTree.getInfo()

// Add the Git submodules of the nested Repo project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import org.ossreviewtoolkit.utils.ort.requestPasswordAuthentication

class GitTest : WordSpec({
// Make sure that the initialization logic runs.
val git = Git()
val git = Git.create()

var originalCredentialsProvider: CredentialsProvider? = null
var originalAuthenticator: Authenticator? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import java.io.IOException
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.config.VersionControlSystemConfiguration
import org.ossreviewtoolkit.plugins.versioncontrolsystems.git.Git

class SafeDeleteRecursivelyFunTest : WordSpec({
Expand Down Expand Up @@ -59,7 +58,7 @@ class SafeDeleteRecursivelyFunTest : WordSpec({
)

val nodeDir = tempdir().resolve("node-dir")
Git.Factory().create(VersionControlSystemConfiguration()).download(pkg, nodeDir)
Git.create().download(pkg, nodeDir)

shouldNotThrow<IOException> {
nodeDir.safeDeleteRecursively()
Expand Down

0 comments on commit c66ccf6

Please sign in to comment.