Compare commits

..

21 Commits

Author SHA1 Message Date
Naoki Takezoe
d3268265cf Release GitBucket 4.42.1 (#3699) 2025-01-20 10:16:31 +09:00
Naoki Takezoe
5eaf59eebb Remove unnecessary setup code for SSL in LDAPUtil (#3697) 2025-01-20 09:41:33 +09:00
Scala Steward
d6d47aa977 Update scalafmt-core to 3.8.5 2025-01-20 07:19:49 +09:00
Naoki Takezoe
dc052e05ce Setup sbt explicitly in GitHub Actions (#3698) 2025-01-20 02:29:51 +09:00
Scala Steward
afb145ca7c Update sbt-scalafmt to 2.5.4 2025-01-17 07:26:49 +09:00
Scala Steward
a8beed33e0 Update scala3-library to 3.6.3 2025-01-16 20:00:10 +09:00
Scala Steward
488599dba5 Update postgresql to 42.7.5 2025-01-15 05:45:47 +09:00
Scala Steward
ef0d08a917 Update sbt-scoverage to 2.3.0 2025-01-14 07:42:48 +09:00
Scala Steward
9fa0d03c99 Update sbt-scalafmt to 2.5.3 2025-01-14 07:36:37 +09:00
kenji yoshida
15b6c5952b update build status badge in README 2025-01-11 16:06:43 +09:00
Scala Steward
cb75e9d312 Update oauth2-oidc-sdk to 11.21 2025-01-11 07:04:42 +09:00
Scala Steward
d542ee3528 Update scala-library to 2.13.16 2025-01-11 06:55:05 +09:00
Scala Steward
608a59cbfd Update oauth2-oidc-sdk to 11.20.2 2025-01-10 07:15:27 +09:00
Scala Steward
768e3a5c91 Update logback-classic to 1.5.16 2025-01-06 10:02:28 +09:00
Naoki Takezoe
f1fc794c0c Fix warnings in JGitUtil (#3683) 2025-01-05 14:35:50 +09:00
kenji yoshida
4cf924bee0 remove unused imports 2025-01-03 12:05:40 +09:00
kenji yoshida
8164efc720 remove unused import 2025-01-03 10:25:25 +09:00
Scala Steward
580a627d9d Update mockito-core to 5.15.2 2025-01-03 07:59:55 +09:00
Naoki Takezoe
1701916209 Update README and CHANGELOG for Java 17 requirement (#3679) 2025-01-02 02:17:06 +09:00
takezoe
811b2bff70 Update README.md and CHANGELOG.md 2024-12-30 05:52:06 +09:00
takezoe
9de9dd8940 Update README.md 2024-12-30 04:59:26 +09:00
13 changed files with 136 additions and 180 deletions

View File

@@ -27,6 +27,8 @@ jobs:
with:
java-version: ${{ matrix.java }}
distribution: adopt
- name: Setup sbt launcher
uses: sbt/setup-sbt@v1
- name: Run tests
run: sbt scalafmtSbtCheck scalafmtCheckAll test
- name: Scala 3

View File

@@ -1,4 +1,4 @@
version = "3.8.3"
version = "3.8.5"
project.git = true
maxColumn = 120

View File

@@ -1,11 +1,15 @@
# Changelog
All changes to the project will be documented in this file.
## 4.42.1 - 20 Jan 2025
- Fix LDAP issue with SSL
## 4.42.0 - 30 Dec 2024
- Increase max branch name length 100 -> 255
- Fix some Web API responses that were incompatible with GitHub API
- Fix some GitHub incompatible Web APIs
- Apply user-defined CSS after all plugins
- Improve performance of listing commit logs
- Drop Java 11 support. Java 17 is now required
## 4.41.0 - 18 May 2024
- Simplify pull request UI

View File

@@ -1,4 +1,4 @@
GitBucket [![Gitter chat](https://badges.gitter.im/gitbucket/gitbucket.svg)](https://gitter.im/gitbucket/gitbucket) [![build](https://github.com/gitbucket/gitbucket/workflows/build/badge.svg?branch=master)](https://github.com/gitbucket/gitbucket/actions?query=workflow%3Abuild+branch%3Amaster) [![gitbucket Scala version support](https://index.scala-lang.org/gitbucket/gitbucket/gitbucket/latest-by-scala-version.svg)](https://index.scala-lang.org/gitbucket/gitbucket/gitbucket) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/gitbucket/gitbucket/blob/master/LICENSE)
GitBucket [![Gitter chat](https://badges.gitter.im/gitbucket/gitbucket.svg)](https://gitter.im/gitbucket/gitbucket) [![build](https://github.com/gitbucket/gitbucket/actions/workflows/build.yml/badge.svg)](https://github.com/gitbucket/gitbucket/actions/workflows/build.yml) [![gitbucket Scala version support](https://index.scala-lang.org/gitbucket/gitbucket/gitbucket/latest-by-scala-version.svg)](https://index.scala-lang.org/gitbucket/gitbucket/gitbucket) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/gitbucket/gitbucket/blob/master/LICENSE)
=========
GitBucket is a Git web platform powered by Scala offering:
@@ -24,7 +24,7 @@ The current version of GitBucket provides many features such as:
Installation
--------
GitBucket requires **Java 11**. You have to install it, if it is not already installed.
GitBucket requires **Java 17**. You have to install it, if it is not already installed.
1. Download the latest **gitbucket.war** from [the releases page](https://github.com/gitbucket/gitbucket/releases) and run it by `java -jar gitbucket.war`.
2. Go to `http://[hostname]:8080/` and log in with ID: **root** / Pass: **root**.
@@ -59,12 +59,16 @@ Support
- If you can't find same question and report, send it to our [Gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
What's New in 4.41.x
What's New in 4.42.x
-------------
## 4.42.1 - 20 Jan 2025
- Fix LDAP issue with SSL
## 4.42.0 - 30 Dec 2024
- Increase max branch name length 100 -> 255
- Fix some Web API responses that were incompatible with GitHub API
- Fix some GitHub incompatible Web APIs
- Apply user-defined CSS after all plugins
- Improve performance of listing commit logs
- Drop Java 11 support. Java 17 is now required
See the [change log](CHANGELOG.md) for all of the updates.

View File

@@ -1,9 +1,8 @@
import sbtlicensereport.license.{DepModuleInfo, LicenseInfo}
import com.jsuereth.sbtpgp.PgpKeys._
val Organization = "io.github.gitbucket"
val Name = "gitbucket"
val GitBucketVersion = "4.42.0"
val GitBucketVersion = "4.42.1"
val ScalatraVersion = "3.1.1"
val JettyVersion = "10.0.24"
val JgitVersion = "6.10.0.202406032230-r"
@@ -15,9 +14,9 @@ sourcesInBase := false
organization := Organization
name := Name
version := GitBucketVersion
scalaVersion := "2.13.15"
scalaVersion := "2.13.16"
crossScalaVersions += "3.6.2"
crossScalaVersions += "3.6.3"
// scalafmtOnCompile := true
@@ -47,8 +46,8 @@ libraryDependencies ++= Seq(
"com.novell.ldap" % "jldap" % "2009-10-07",
"com.h2database" % "h2" % "1.4.199",
"org.mariadb.jdbc" % "mariadb-java-client" % "2.7.12",
"org.postgresql" % "postgresql" % "42.7.4",
"ch.qos.logback" % "logback-classic" % "1.5.15",
"org.postgresql" % "postgresql" % "42.7.5",
"ch.qos.logback" % "logback-classic" % "1.5.16",
"com.zaxxer" % "HikariCP" % "6.2.1" exclude ("org.slf4j", "slf4j-api"),
"com.typesafe" % "config" % "1.4.3",
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
@@ -56,12 +55,12 @@ libraryDependencies ++= Seq(
"org.cache2k" % "cache2k-all" % "1.6.0.Final",
"net.coobird" % "thumbnailator" % "0.4.20",
"com.github.zafarkhaja" % "java-semver" % "0.10.2",
"com.nimbusds" % "oauth2-oidc-sdk" % "11.20.1",
"com.nimbusds" % "oauth2-oidc-sdk" % "11.21",
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
"junit" % "junit" % "4.13.2" % "test",
"org.scalatra" %% "scalatra-scalatest-javax" % ScalatraVersion % "test",
"org.mockito" % "mockito-core" % "5.14.2" % "test",
"org.mockito" % "mockito-core" % "5.15.2" % "test",
"com.dimafeng" %% "testcontainers-scala" % "0.41.5" % "test",
"org.testcontainers" % "mysql" % "1.20.4" % "test",
"org.testcontainers" % "postgresql" % "1.20.4" % "test",

View File

@@ -1,11 +1,11 @@
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
addSbtPlugin("org.playframework.twirl" % "sbt-twirl" % "2.0.7")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.0")
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
addSbtPlugin("com.github.sbt" % "sbt-license-report" % "1.7.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.0")
addDependencyTreePlugin

View File

@@ -118,7 +118,8 @@ object GitBucketCoreModule
new Version("4.39.0", new LiquibaseMigration("update/gitbucket-core_4.39.xml")),
new Version("4.40.0"),
new Version("4.41.0"),
new Version("4.42.0", new LiquibaseMigration("update/gitbucket-core_4.42.xml"))
new Version("4.42.0", new LiquibaseMigration("update/gitbucket-core_4.42.xml")),
new Version("4.42.1")
) {
java.util.logging.Logger.getLogger("liquibase").setLevel(Level.SEVERE)
}

View File

@@ -23,10 +23,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
JsonFormat(
JGitUtil
.getBranchesNoMergeInfo(
git = git,
defaultBranch = repository.repository.defaultBranch
)
.getBranchesNoMergeInfo(git)
.map { br =>
ApiBranchForList(br.name, ApiBranchCommit(br.commitId))
}
@@ -42,10 +39,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
(for {
branch <- params.get("splat") if repository.branchList.contains(branch)
br <- getBranchesNoMergeInfo(
git,
repository.repository.defaultBranch
).find(_.name == branch)
br <- getBranchesNoMergeInfo(git).find(_.name == branch)
} yield {
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
JsonFormat(
@@ -269,10 +263,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
(for {
branch <- params.get("splat") if repository.branchList.contains(branch)
protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection)
br <- getBranchesNoMergeInfo(
git,
repository.repository.defaultBranch
).find(_.name == branch)
br <- getBranchesNoMergeInfo(git).find(_.name == branch)
} yield {
if (protection.enabled) {
enableBranchProtection(

View File

@@ -159,7 +159,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
val apiBranchForCommits = for {
branch <- getBranchesOfCommit(git, sha)
br <- getBranchesNoMergeInfo(git, branch).find(_.name == branch)
br <- getBranchesNoMergeInfo(git).find(_.name == branch)
} yield {
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
ApiBranchForHeadCommit(branch, ApiBranchCommit(br.commitId), protection.enabled)

View File

@@ -313,7 +313,7 @@ trait PullRequestService {
base.foreach { _base =>
if (pr.branch != _base) {
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
getBranchesNoMergeInfo(git, repository.repository.defaultBranch)
getBranchesNoMergeInfo(git)
.find(_.name == _base)
.foreach(br => updateBaseBranch(repository.owner, repository.name, issueId, br.name, br.commitId))
}

View File

@@ -1,19 +1,19 @@
package gitbucket.core.util
import java.io._
import java.io.*
import gitbucket.core.service.RepositoryService
import org.eclipse.jgit.api.Git
import Directory._
import StringUtil._
import Directory.*
import StringUtil.*
import scala.annotation.tailrec
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
import scala.util.Using
import org.eclipse.jgit.lib._
import org.eclipse.jgit.revwalk._
import org.eclipse.jgit.revwalk.filter._
import org.eclipse.jgit.treewalk._
import org.eclipse.jgit.treewalk.filter._
import org.eclipse.jgit.lib.*
import org.eclipse.jgit.revwalk.*
import org.eclipse.jgit.revwalk.filter.*
import org.eclipse.jgit.treewalk.*
import org.eclipse.jgit.treewalk.filter.*
import org.eclipse.jgit.diff.DiffEntry.ChangeType
import org.eclipse.jgit.errors.{ConfigInvalidException, IncorrectObjectTypeException, MissingObjectException}
import org.eclipse.jgit.transport.RefSpec
@@ -21,14 +21,13 @@ import org.eclipse.jgit.transport.RefSpec
import java.util.Date
import java.util.concurrent.TimeUnit
import org.cache2k.{Cache, Cache2kBuilder}
import org.eclipse.jgit.api.errors._
import org.eclipse.jgit.api.errors.*
import org.eclipse.jgit.diff.{DiffEntry, DiffFormatter, RawTextComparator}
import org.eclipse.jgit.dircache.DirCacheEntry
import org.eclipse.jgit.util.io.DisabledOutputStream
import org.slf4j.LoggerFactory
import scala.util.Using.Releasable
import scala.util.{Try, Using}
/**
* Provides complex JGit operations.
@@ -40,7 +39,7 @@ object JGitUtil {
private implicit val objectDatabaseReleasable: Releasable[ObjectDatabase] =
_.close()
private def isCacheEnabled(): Boolean =
private def isCacheEnabled: Boolean =
!ConfigUtil.getConfigValue[Boolean]("gitbucket.disableCache").getOrElse(false)
/**
@@ -91,8 +90,6 @@ object JGitUtil {
/**
* The verified gpg sign data.
* @param signedUser
* @param signedKeyId
*/
case class GpgVerifyInfo(signedUser: String, signedKeyId: String)
@@ -128,7 +125,7 @@ object JGitUtil {
os.write('\n')
if (!rev.getFullMessage.isEmpty) {
if (rev.getFullMessage.nonEmpty) {
w.write(rev.getFullMessage)
w.flush()
}
@@ -169,7 +166,7 @@ object JGitUtil {
rev.getName,
rev.getShortMessage,
rev.getFullMessage,
rev.getParents().map(_.name).toList,
rev.getParents.map(_.name).toList,
rev.getAuthorIdent.getWhen,
rev.getAuthorIdent.getName,
rev.getAuthorIdent.getEmailAddress,
@@ -182,9 +179,9 @@ object JGitUtil {
None
)
val summary = getSummaryMessage(fullMessage, shortMessage)
val summary: String = getSummaryMessage(fullMessage, shortMessage)
val description = {
val description: Option[String] = {
val i = fullMessage.trim.indexOf('\n')
if (i >= 0) {
Some(fullMessage.trim.substring(i).trim)
@@ -291,11 +288,11 @@ object JGitUtil {
case r: RevTag => revWalk.parseCommit(r.getObject)
case _ => revWalk.parseCommit(objectId)
}
revWalk.dispose
revWalk.dispose()
revCommit
}
private val cache: Cache[String, Int] = if (isCacheEnabled()) {
private val cache: Cache[String, Int] = if (isCacheEnabled) {
Cache2kBuilder
.of(classOf[String], classOf[Int])
.name("commit-count")
@@ -304,7 +301,7 @@ object JGitUtil {
.build()
} else null
private val objectCommitCache: Cache[ObjectId, RevCommit] = if (isCacheEnabled()) {
private val objectCommitCache: Cache[ObjectId, RevCommit] = if (isCacheEnabled) {
Cache2kBuilder
.of(classOf[ObjectId], classOf[RevCommit])
.name("object-commit")
@@ -313,7 +310,7 @@ object JGitUtil {
} else null
def removeCache(git: Git): Unit = {
if (isCacheEnabled()) {
if (isCacheEnabled) {
val dir = git.getRepository.getDirectory
val keyPrefix = dir.getAbsolutePath + "@"
@@ -332,7 +329,7 @@ object JGitUtil {
def getCommitCount(git: Git, branch: String, max: Int = 10001): Int = {
val dir = git.getRepository.getDirectory
if (isCacheEnabled()) {
if (isCacheEnabled) {
val key = dir.getAbsolutePath + "@" + branch
val entry = cache.getEntry(key)
@@ -388,7 +385,7 @@ object JGitUtil {
)
} catch {
// not initialized
case e: NoHeadException => RepositoryInfo(owner, repository, Nil, Nil)
case _: NoHeadException => RepositoryInfo(owner, repository, Nil, Nil)
}
}
}
@@ -425,7 +422,7 @@ object JGitUtil {
} else {
val treeWalk = TreeWalk.forPath(git.getRepository, path, rev.getTree)
if (treeWalk != null) {
treeWalk.enterSubtree
treeWalk.enterSubtree()
Using.resource(treeWalk)(f)
}
}
@@ -436,7 +433,7 @@ object JGitUtil {
): (ObjectId, FileMode, String, String, Option[String], Option[RevCommit]) =
tuple match {
case (oid, FileMode.TREE, name, path, _, commit) =>
(Using.resource(new TreeWalk(git.getRepository)) { walk =>
Using.resource(new TreeWalk(git.getRepository)) { walk =>
walk.addTree(oid)
// single tree child, or None
if (walk.next() && walk.getFileMode(0) == FileMode.TREE) {
@@ -453,7 +450,7 @@ object JGitUtil {
} else {
None
}
}) match {
} match {
case Some(child) => simplifyPath(child)
case _ => tuple
}
@@ -469,7 +466,7 @@ object JGitUtil {
(id, mode, name, path, opt, None)
} else if (commitCount < 10000) {
(id, mode, name, path, opt, Some(getCommit(path)))
} else if (isCacheEnabled()) {
} else if (isCacheEnabled) {
// Use in-memory cache if the commit count is too big.
val cached = objectCommitCache.getEntry(id)
if (cached == null) {
@@ -505,9 +502,7 @@ object JGitUtil {
} else None
fileList +:= (
treeWalk.getObjectId(0),
treeWalk.getFileMode(
0
),
treeWalk.getFileMode(0),
treeWalk.getNameString,
treeWalk.getPathString,
linkUrl
@@ -559,9 +554,12 @@ object JGitUtil {
def getTreeId(git: Git, revision: String): Option[String] = {
Using.resource(new RevWalk(git.getRepository)) { revWalk =>
val objectId = git.getRepository.resolve(revision)
if (objectId == null) return None
val revCommit = revWalk.parseCommit(objectId)
Some(revCommit.getTree.name)
if (objectId == null) {
None
} else {
val revCommit = revWalk.parseCommit(objectId)
Some(revCommit.getTree.name)
}
}
}
@@ -569,20 +567,18 @@ object JGitUtil {
* get all file list by tree object id.
*/
def getAllFileListByTreeId(git: Git, treeId: String): List[String] = {
Using.resource(new RevWalk(git.getRepository)) { revWalk =>
val objectId = git.getRepository.resolve(treeId + "^{tree}")
if (objectId == null) return Nil
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
treeWalk.addTree(objectId)
treeWalk.setRecursive(true)
var ret: List[String] = Nil
if (treeWalk != null) {
while (treeWalk.next()) {
ret +:= treeWalk.getPathString
}
val objectId = git.getRepository.resolve(treeId + "^{tree}")
if (objectId == null) return Nil
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
treeWalk.addTree(objectId)
treeWalk.setRecursive(true)
var ret: List[String] = Nil
if (treeWalk != null) {
while (treeWalk.next()) {
ret +:= treeWalk.getPathString
}
ret.reverse
}
ret.reverse
}
}
@@ -611,22 +607,21 @@ object JGitUtil {
count: Int,
logs: List[CommitInfo]
): (List[CommitInfo], Boolean) =
i.hasNext match {
case true if (limit <= 0 || logs.size < limit) => {
val commit = i.next
getCommitLog(
i,
count + 1,
if (limit <= 0 || (fixedPage - 1) * limit <= count) logs :+ new CommitInfo(commit) else logs
)
}
case _ => (logs, i.hasNext)
if (i.hasNext) {
val commit = i.next
getCommitLog(
i,
count + 1,
if (limit <= 0 || (fixedPage - 1) * limit <= count) logs :+ new CommitInfo(commit) else logs
)
} else {
(logs, i.hasNext)
}
Using.resource(new RevWalk(git.getRepository)) { revWalk =>
val objectId = git.getRepository.resolve(revision)
if (objectId == null) {
Left(s"${revision} can't be resolved.")
Left(s"$revision can't be resolved.")
} else {
revWalk.markStart(revWalk.parseCommit(objectId))
if (path.nonEmpty) {
@@ -642,16 +637,15 @@ object JGitUtil {
): List[CommitInfo] = {
@scala.annotation.tailrec
def getCommitLog(i: java.util.Iterator[RevCommit], logs: List[CommitInfo]): List[CommitInfo] =
i.hasNext match {
case true => {
val revCommit = i.next
if (endCondition(revCommit)) {
if (includesLastCommit) logs :+ new CommitInfo(revCommit) else logs
} else {
getCommitLog(i, logs :+ new CommitInfo(revCommit))
}
if (i.hasNext) {
val revCommit = i.next
if (endCondition(revCommit)) {
if (includesLastCommit) logs :+ new CommitInfo(revCommit) else logs
} else {
getCommitLog(i, logs :+ new CommitInfo(revCommit))
}
case false => logs
} else {
logs
}
Using.resource(new RevWalk(git.getRepository)) { revWalk =>
@@ -873,7 +867,7 @@ object JGitUtil {
private def getTextContent(git: Git, objectId: ObjectId): Option[String] = {
JGitUtil
.getContentFromId(git, objectId, false)
.getContentFromId(git, objectId, fetchLargeFile = false)
.filter(FileUtil.isText)
.map(convertFromByteArray)
}
@@ -898,10 +892,7 @@ object JGitUtil {
.getRefsByPrefix(Constants.R_HEADS)
.asScala
.filter { e =>
(revWalk.isMergedInto(
commit,
revWalk.parseCommit(e.getObjectId)
))
revWalk.isMergedInto(commit, revWalk.parseCommit(e.getObjectId))
}
.map { e =>
e.getName.substring(Constants.R_HEADS.length)
@@ -940,10 +931,7 @@ object JGitUtil {
.getRefsByPrefix(Constants.R_TAGS)
.asScala
.filter { e =>
(revWalk.isMergedInto(
commit,
revWalk.parseCommit(e.getObjectId)
))
revWalk.isMergedInto(commit, revWalk.parseCommit(e.getObjectId))
}
.map { e =>
e.getName.substring(Constants.R_TAGS.length)
@@ -970,7 +958,7 @@ object JGitUtil {
private def setReceivePack(repository: org.eclipse.jgit.lib.Repository): Unit = {
val config = repository.getConfig
config.setBoolean("http", null, "receivepack", true)
config.save
config.save()
}
def getDefaultBranch(
@@ -987,7 +975,7 @@ object JGitUtil {
}.find(_._1 != null)
}
def createTag(git: Git, name: String, message: Option[String], commitId: String) = {
def createTag(git: Git, name: String, message: Option[String], commitId: String): Either[String, String] = {
try {
val objectId: ObjectId = git.getRepository.resolve(commitId)
Using.resource(new RevWalk(git.getRepository)) { walk =>
@@ -1006,7 +994,7 @@ object JGitUtil {
}
}
def createBranch(git: Git, fromBranch: String, newBranch: String) = {
def createBranch(git: Git, fromBranch: String, newBranch: String): Either[String, String] = {
try {
git.branchCreate().setStartPoint(fromBranch).setName(newBranch).call()
Right("Branch created.")
@@ -1061,19 +1049,18 @@ object JGitUtil {
*/
def getSubmodules(git: Git, tree: RevTree, baseUrl: Option[String]): List[SubmoduleInfo] = {
val repository = git.getRepository
getContentFromPath(git, tree, ".gitmodules", true).map { bytes =>
getContentFromPath(git, tree, ".gitmodules", fetchLargeFile = true).map { bytes =>
(try {
val config = new BlobBasedConfig(repository.getConfig(), bytes)
val config = new BlobBasedConfig(repository.getConfig, bytes)
config.getSubsections("submodule").asScala.map { module =>
val path = config.getString("submodule", module, "path")
val url = config.getString("submodule", module, "url")
SubmoduleInfo(module, path, url, StringUtil.getRepositoryViewerUrl(url, baseUrl))
}
} catch {
case e: ConfigInvalidException => {
logger.error("Failed to load .gitmodules file for " + repository.getDirectory(), e)
case e: ConfigInvalidException =>
logger.error("Failed to load .gitmodules file for " + repository.getDirectory, e)
Nil
}
}).toList
} getOrElse Nil
}
@@ -1091,9 +1078,9 @@ object JGitUtil {
@scala.annotation.tailrec
def getPathObjectId(path: String, walk: TreeWalk): Option[ObjectId] =
walk.next match {
case true if (walk.getPathString == path) => Some(walk.getObjectId(0))
case true => getPathObjectId(path, walk)
case false => None
case true if walk.getPathString == path => Some(walk.getObjectId(0))
case true => getPathObjectId(path, walk)
case false => None
}
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
@@ -1146,7 +1133,7 @@ object JGitUtil {
val isLfs = isLfsPointer(loader)
val large = FileUtil.isLarge(loader.getSize)
val viewer = if (FileUtil.isImage(path, safeMode)) "image" else if (large) "large" else "other"
val bytes = if (viewer == "other") JGitUtil.getContentFromId(git, objectId, false) else None
val bytes = if (viewer == "other") JGitUtil.getContentFromId(git, objectId, fetchLargeFile = false) else None
val size = Some(getContentSize(loader))
if (viewer == "other") {
@@ -1181,7 +1168,7 @@ object JGitUtil {
try {
Using.resource(git.getRepository.getObjectDatabase) { db =>
val loader = db.open(id)
if (loader.isLarge || (fetchLargeFile == false && FileUtil.isLarge(loader.getSize))) {
if (loader.isLarge || (!fetchLargeFile && FileUtil.isLarge(loader.getSize))) {
None
} else {
Some(loader.getBytes)
@@ -1251,7 +1238,7 @@ object JGitUtil {
requestBranch: String
): String = {
val existIds = getAllCommitIds(oldGit)
getCommitLogs(newGit, requestBranch, true) { commit =>
getCommitLogs(newGit, requestBranch, includesLastCommit = true) { commit =>
existIds.contains(commit.name) && getBranchesOfCommit(oldGit, commit.getName).contains(branch)
}.head.id
}
@@ -1275,10 +1262,10 @@ object JGitUtil {
) { (oldGit, newGit) =>
oldGit.fetch
.setRemote(Directory.getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString)
.setRefSpecs(new RefSpec(s"refs/heads/${requestBranch}:refs/pull/${issueId}/head").setForceUpdate(true))
.setRefSpecs(new RefSpec(s"refs/heads/$requestBranch:refs/pull/$issueId/head").setForceUpdate(true))
.call
val commitIdTo = oldGit.getRepository.resolve(s"refs/pull/${issueId}/head").getName
val commitIdTo = oldGit.getRepository.resolve(s"refs/pull/$issueId/head").getName
val commitIdFrom = getForkedCommitId(
oldGit,
newGit,
@@ -1304,9 +1291,8 @@ object JGitUtil {
git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
}
def getBranchesNoMergeInfo(git: Git, defaultBranch: String): Seq[BranchInfoSimple] = {
def getBranchesNoMergeInfo(git: Git): Seq[BranchInfoSimple] = {
val repo = git.getRepository
val defaultObject = repo.resolve(defaultBranch)
git.branchList.call.asScala.map { ref =>
val walk = new RevWalk(repo)
@@ -1370,7 +1356,7 @@ object JGitUtil {
val blame = blamer.call()
var blameMap = Map[String, JGitUtil.BlameInfo]()
var idLine = List[(String, Int)]()
0.until(blame.getResultContents().size()).foreach { i =>
0.until(blame.getResultContents.size()).foreach { i =>
val c = blame.getSourceCommit(i)
if (!blameMap.contains(c.name)) {
blameMap += c.name -> JGitUtil.BlameInfo(
@@ -1407,7 +1393,7 @@ object JGitUtil {
*/
def getShaByRef(owner: String, name: String, revstr: String): Option[String] = {
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
Option(git.getRepository.resolve(revstr)).map(ObjectId.toString(_))
Option(git.getRepository.resolve(revstr)).map(ObjectId.toString)
}
}

View File

@@ -3,9 +3,7 @@ package gitbucket.core.util
import gitbucket.core.model.Account
import gitbucket.core.service.SystemSettingsService
import gitbucket.core.service.SystemSettingsService.Ldap
import com.novell.ldap._
import java.security.{Provider, Security}
import java.util.concurrent.atomic.AtomicReference
import com.novell.ldap.*
import org.slf4j.LoggerFactory
@@ -19,8 +17,7 @@ object LDAPUtil {
private val LDAP_VERSION: Int = LDAPConnection.LDAP_V3
private val LDAP_DUMMY_MAL = "@ldap-devnull"
private val logger = LoggerFactory.getLogger(getClass().getName())
private val provider = new AtomicReference[Provider](null)
private val logger = LoggerFactory.getLogger(getClass.getName)
/**
* Returns true if mail address ends with "@ldap-devnull"
@@ -119,34 +116,10 @@ object LDAPUtil {
private def getUserNameFromMailAddress(userName: String): String = {
(userName.indexOf('@') match {
case i if i >= 0 => userName.substring(0, i)
case i => userName
case _ => userName
}).replaceAll("[^a-zA-Z0-9\\-_.]", "").replaceAll("^[_\\-]", "")
}
private def getSslProvider(): Provider = {
import scala.language.existentials
val cachedInstance = provider.get()
if (cachedInstance == null) {
val cls =
try {
Class.forName("com.sun.net.ssl.internal.ssl.Provider")
} catch {
case e: ClassNotFoundException =>
Class.forName("com.ibm.jsse.IBMJSSEProvider")
case e: Throwable => throw e
}
val newInstance = cls
.getDeclaredConstructor()
.newInstance()
.asInstanceOf[Provider]
provider.compareAndSet(null, newInstance)
newInstance
} else {
cachedInstance
}
}
private def bind[A](
host: String,
port: Int,
@@ -158,9 +131,6 @@ object LDAPUtil {
error: String
)(f: LDAPConnection => Either[String, A]): Either[String, A] = {
if (tls || ssl) {
// Dynamically set Sun as the security provider
Security.addProvider(getSslProvider())
if (keystore.compareTo("") != 0) {
// Dynamically set the property that JSSE uses to identify
// the keystore that holds trusted root certificates
@@ -191,7 +161,7 @@ object LDAPUtil {
f(conn)
} catch {
case e: Exception => {
case e: Exception =>
// Provide more information if something goes wrong
logger.info("" + e)
@@ -200,7 +170,6 @@ object LDAPUtil {
}
// Returns an error message
Left(error)
}
}
}
@@ -222,7 +191,7 @@ object LDAPUtil {
entries :+ (try {
Option(results.next)
} catch {
case ex: LDAPReferralException => None // NOTE(tanacasino): Referral follow is off. so ignores it.(for AD)
case _: LDAPReferralException => None // NOTE(tanacasino): Referral follow is off. so ignores it.(for AD)
})
)
} else {

View File

@@ -13,10 +13,10 @@ class JGitUtilSpec extends AnyFunSuite {
test("isEmpty") {
withTestRepository { git =>
assert(JGitUtil.isEmpty(git) == true)
assert(JGitUtil.isEmpty(git))
createFile(git, Constants.HEAD, "README.md", "body1", message = "commit1")
assert(JGitUtil.isEmpty(git) == false)
assert(!JGitUtil.isEmpty(git))
}
}
@@ -31,13 +31,13 @@ class JGitUtilSpec extends AnyFunSuite {
createFile(git, Constants.HEAD, "README.md", "body1\nbody2", message = "commit1")
// latest commit
val diff1 = JGitUtil.getDiffs(git, None, "main", false, true)
val diff1 = JGitUtil.getDiffs(git, None, "main", fetchContent = false, makePatch = true)
assert(diff1.size == 1)
assert(diff1(0).changeType == ChangeType.MODIFY)
assert(diff1(0).oldPath == "README.md")
assert(diff1(0).newPath == "README.md")
assert(diff1(0).tooLarge == false)
assert(diff1(0).patch == Some("""@@ -1 +1,2 @@
assert(!diff1(0).tooLarge)
assert(diff1(0).patch.contains("""@@ -1 +1,2 @@
|-body1
|\ No newline at end of file
|+body1
@@ -45,13 +45,13 @@ class JGitUtilSpec extends AnyFunSuite {
|\ No newline at end of file""".stripMargin))
// from specified commit
val diff2 = JGitUtil.getDiffs(git, Some(commit.getName), "main", false, true)
val diff2 = JGitUtil.getDiffs(git, Some(commit.getName), "main", fetchContent = false, makePatch = true)
assert(diff2.size == 2)
assert(diff2(0).changeType == ChangeType.ADD)
assert(diff2(0).oldPath == "/dev/null")
assert(diff2(0).newPath == "LICENSE")
assert(diff2(0).tooLarge == false)
assert(diff2(0).patch == Some("""+++ b/LICENSE
assert(!diff2(0).tooLarge)
assert(diff2(0).patch.contains("""+++ b/LICENSE
|@@ -0,0 +1 @@
|+Apache License
|\ No newline at end of file""".stripMargin))
@@ -59,8 +59,8 @@ class JGitUtilSpec extends AnyFunSuite {
assert(diff2(1).changeType == ChangeType.MODIFY)
assert(diff2(1).oldPath == "README.md")
assert(diff2(1).newPath == "README.md")
assert(diff2(1).tooLarge == false)
assert(diff2(1).patch == Some("""@@ -1 +1,2 @@
assert(!diff2(1).tooLarge)
assert(diff2(1).patch.contains("""@@ -1 +1,2 @@
|-body1
|\ No newline at end of file
|+body1
@@ -210,7 +210,7 @@ class JGitUtilSpec extends AnyFunSuite {
JGitUtil.createBranch(git, "main", "test2")
// getBranches
val branches = JGitUtil.getBranches(git, "main", true)
val branches = JGitUtil.getBranches(git, "main", origin = true)
assert(branches.size == 3)
assert(branches(0).name == "main")
@@ -239,8 +239,8 @@ class JGitUtilSpec extends AnyFunSuite {
JGitUtil.createBranch(git, "main", "test2")
// getBranches
val branchesNMI = JGitUtil.getBranchesNoMergeInfo(git, "main")
val branches = JGitUtil.getBranches(git, "main", true)
val branchesNMI = JGitUtil.getBranchesNoMergeInfo(git)
val branches = JGitUtil.getBranches(git, "main", origin = true)
assert(
branches.map(bi =>
@@ -313,14 +313,14 @@ class JGitUtilSpec extends AnyFunSuite {
val objectId = git.getRepository.resolve("main")
val commit = JGitUtil.getRevCommitFromId(git, objectId)
val content1 = JGitUtil.getContentFromPath(git, commit.getTree, "README.md", true)
assert(content1.map(x => new String(x, "UTF-8")) == Some("body1"))
val content1 = JGitUtil.getContentFromPath(git, commit.getTree, "README.md", fetchLargeFile = true)
assert(content1.map(x => new String(x, "UTF-8")).contains("body1"))
val content2 = JGitUtil.getContentFromPath(git, commit.getTree, "LARGE_FILE", false)
val content2 = JGitUtil.getContentFromPath(git, commit.getTree, "LARGE_FILE", fetchLargeFile = false)
assert(content2.isEmpty)
val content3 = JGitUtil.getContentFromPath(git, commit.getTree, "LARGE_FILE", true)
assert(content3.map(x => new String(x, "UTF-8")) == Some("body1" * 1000000))
val content3 = JGitUtil.getContentFromPath(git, commit.getTree, "LARGE_FILE", fetchLargeFile = true)
assert(content3.map(x => new String(x, "UTF-8")).contains("body1" * 1000000))
}
}