Skip to content

Commit 079951a

Browse files
committed
Updates- new JGit, etc
1 parent 70b3ca6 commit 079951a

File tree

21 files changed

+90
-114
lines changed

21 files changed

+90
-114
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ jobs:
1313
test:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v3
18-
- name: Setup JDK
19-
uses: actions/setup-java@v3
20-
with:
21-
distribution: corretto
22-
java-version: 11
23-
cache: sbt
16+
- uses: actions/checkout@v4
17+
- uses: guardian/setup-scala@v1
2418
- name: Build and Test
2519
run: sbt -v test
2620
- name: Test Summary

.github/workflows/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
release:
8+
uses: guardian/gha-scala-library-release-workflow/.github/workflows/reusable-release.yml@v1
9+
permissions: { contents: write, pull-requests: write }
10+
with:
11+
GITHUB_APP_ID: 930725
12+
SONATYPE_PROFILE_NAME: 'com.madgag'
13+
SONATYPE_CREDENTIAL_HOST: 's01.oss.sonatype.org'
14+
secrets:
15+
SONATYPE_TOKEN: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_TOKEN }}
16+
PGP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
17+
GITHUB_APP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_GITHUB_APP_PRIVATE_KEY }}

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java corretto-11.0.25.9.1

BUILD.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ can run anywhere Java can.
44
Here's a rough set of instructions for building the BFG, if you don't want to use the
55
pre-built [downloads](http://rtyley.github.io/bfg-repo-cleaner/#download):
66

7-
* Install Java JDK 8 or above
7+
* Install Java JDK 11 or above
88
* Install [sbt](https://www.scala-sbt.org/1.x/docs/Setup.html)
99
* `git clone [email protected]:rtyley/bfg-repo-cleaner.git`
1010
* `cd bfg-repo-cleaner`

bfg-benchmark/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Dependencies._
1+
import Dependencies.*
22

33
libraryDependencies ++= guava ++ Seq(
44
madgagCompress,

bfg-library/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Dependencies._
1+
import Dependencies.*
22

33
libraryDependencies ++= guava ++ Seq(
44
parCollections,
@@ -9,6 +9,6 @@ libraryDependencies ++= guava ++ Seq(
99
slf4jSimple,
1010
lineSplitting,
1111
scalaGitTest % Test,
12-
"org.apache.commons" % "commons-text" % "1.9" % Test
12+
"org.apache.commons" % "commons-text" % "1.13.0" % Test
1313
)
1414

bfg-library/src/main/scala/com/madgag/git/bfg/GitUtil.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object GitUtil {
6363
implicit val revWalk = new RevWalk(repo)
6464
implicit val objectReader = revWalk.getObjectReader
6565

66-
repo.getAllRefs.values().stream().toScala(Seq).map(_.getObjectId).filter(_.open.getType == Constants.OBJ_COMMIT)
66+
repo.getRefDatabase.getRefs().stream().toScala(Seq).map(_.getObjectId).filter(_.open.getType == Constants.OBJ_COMMIT)
6767
.map(_.asRevCommit).exists(_.getFooterLines(FormerCommitFooter.Key).asScala.nonEmpty)
6868
}
6969

bfg-library/src/main/scala/com/madgag/git/bfg/cleaner/LfsBlobConverter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import com.madgag.textmatching.{Glob, TextMatcher}
3030
import org.eclipse.jgit.internal.storage.file.FileRepository
3131
import org.eclipse.jgit.lib.{ObjectId, ObjectReader}
3232

33-
import java.nio.charset.Charset
33+
import java.nio.charset.{Charset, StandardCharsets}
3434
import java.nio.file.{Files, Path}
3535
import scala.jdk.StreamConverters._
3636
import scala.util.{Try, Using}
@@ -50,7 +50,7 @@ class LfsBlobConverter(
5050

5151
val gitAttributesLine = s"$lfsGlobExpression filter=lfs diff=lfs merge=lfs -text"
5252

53-
implicit val UTF_8 = Charset.forName("UTF-8")
53+
implicit val UTF_8: Charset = StandardCharsets.UTF_8
5454

5555
val lfsPointerMemo = MemoUtil.concurrentCleanerMemo[ObjectId]()
5656

bfg-library/src/main/scala/com/madgag/git/bfg/cleaner/ObjectIdCleaner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class ObjectIdCleaner(config: ObjectIdCleaner.Config, objectDB: ObjectDatabase,
162162
tb.setTagger(originalTag.getTaggerIdent)
163163
tb.setMessage(objectIdSubstitutor.replaceOldIds(originalTag.getFullMessage, threadLocalResources.reader(), apply))
164164
val cleanedTag: ObjectId = threadLocalResources.inserter().insert(tb)
165-
objectChecker.foreach(_.checkTag(tb.toByteArray))
165+
objectChecker.foreach(_.checkTag(tb.build()))
166166
cleanedTag
167167
}.getOrElse(originalTag)
168168
}

bfg-library/src/main/scala/com/madgag/git/bfg/cleaner/RepoRewriter.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package com.madgag.git.bfg.cleaner
2222

2323
import com.madgag.git._
2424
import com.madgag.git.bfg.Timing
25-
import org.eclipse.jgit.lib.ObjectId
25+
import org.eclipse.jgit.lib.{ObjectId, ProgressMonitor, RefDatabase}
2626
import org.eclipse.jgit.revwalk.RevSort._
2727
import org.eclipse.jgit.revwalk.{RevCommit, RevWalk}
2828
import org.eclipse.jgit.transport.ReceiveCommand
@@ -66,14 +66,14 @@ When updating a Tree, the User has no right to muck with sub-trees. They can onl
6666
object RepoRewriter {
6767

6868
def rewrite(repo: org.eclipse.jgit.lib.Repository, objectIdCleanerConfig: ObjectIdCleaner.Config): Map[ObjectId, ObjectId] = {
69-
assert(!repo.getAllRefs.isEmpty, "Can't find any refs in repo at " + repo.getDirectory.getAbsolutePath)
69+
assert(!repo.getRefDatabase.getRefs().isEmpty, "Can't find any refs in repo at " + repo.getDirectory.getAbsolutePath)
7070

71-
implicit val refDatabase = repo.getRefDatabase
71+
implicit val refDatabase: RefDatabase = repo.getRefDatabase
7272

7373
val reporter: Reporter = new CLIReporter(repo)
74-
implicit val progressMonitor = reporter.progressMonitor
74+
implicit val progressMonitor: ProgressMonitor = reporter.progressMonitor
7575

76-
val allRefs = repo.getAllRefs.values
76+
val allRefs = repo.getRefDatabase.getRefs()
7777

7878
def createRevWalk: RevWalk = {
7979

bfg-library/src/main/scala/com/madgag/git/bfg/model/Commit.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.eclipse.jgit.lib.Constants.OBJ_COMMIT
66
import org.eclipse.jgit.lib._
77
import org.eclipse.jgit.revwalk.RevCommit
88

9+
import java.nio.charset.StandardCharsets.UTF_8
910
import java.nio.charset.{Charset, IllegalCharsetNameException, UnsupportedCharsetException}
1011
import scala.jdk.CollectionConverters._
1112

@@ -59,10 +60,10 @@ case class CommitArcs(parents: Seq[ObjectId], tree: ObjectId) {
5960

6061
object CommitNode {
6162
def apply(c: RevCommit): CommitNode = CommitNode(c.getAuthorIdent, c.getCommitterIdent, c.getFullMessage,
62-
try c.getEncoding catch {case e @ (_ : IllegalCharsetNameException | _ : UnsupportedCharsetException) => Constants.CHARSET})
63+
try c.getEncoding catch {case e @ (_ : IllegalCharsetNameException | _ : UnsupportedCharsetException) => UTF_8})
6364
}
6465

65-
case class CommitNode(author: PersonIdent, committer: PersonIdent, message: String, encoding: Charset = Constants.CHARSET) {
66+
case class CommitNode(author: PersonIdent, committer: PersonIdent, message: String, encoding: Charset = UTF_8) {
6667
lazy val subject = message.linesIterator.to(LazyList).headOption
6768
lazy val lastParagraphBreak = message.lastIndexOf("\n\n")
6869
lazy val messageWithoutFooters = if (footers.isEmpty) message else (message take lastParagraphBreak)

bfg-library/src/test/scala/com/madgag/git/bfg/GitUtilSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ package com.madgag.git.bfg
2222

2323
import com.madgag.git._
2424
import com.madgag.git.test._
25+
import org.eclipse.jgit.internal.storage.file.FileRepository
2526
import org.scalatest.flatspec.AnyFlatSpec
2627
import org.scalatest.matchers.should.Matchers
2728

2829
class GitUtilSpec extends AnyFlatSpec with Matchers {
29-
implicit val repo = unpackRepo("/sample-repos/example.git.zip")
30+
implicit val repo: FileRepository = unpackRepo("/sample-repos/example.git.zip")
3031

3132
"reachable blobs" should "match expectations" in {
3233
implicit val (revWalk, reader) = repo.singleThreadedReaderTuple

bfg-test/src/main/scala/com/madgag/git/bfg/test/unpackedRepo.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package com.madgag.git.bfg.test
22

33
import com.madgag.git._
44
import com.madgag.git.test._
5-
import org.eclipse.jgit.internal.storage.file.{GC, ObjectDirectory}
5+
import org.eclipse.jgit.internal.storage.file.{FileRepository, GC, ObjectDirectory}
66
import org.eclipse.jgit.lib.Constants.OBJ_BLOB
77
import org.eclipse.jgit.lib.{ObjectId, ObjectReader, Repository}
8-
import org.eclipse.jgit.revwalk.{RevCommit, RevTree}
8+
import org.eclipse.jgit.revwalk.{RevCommit, RevTree, RevWalk}
99
import org.eclipse.jgit.treewalk.TreeWalk
1010
import org.scalatest.Inspectors
1111
import org.scalatest.flatspec.AnyFlatSpec
@@ -16,9 +16,9 @@ import scala.jdk.CollectionConverters._
1616

1717
class unpackedRepo(filePath: String) extends AnyFlatSpec with Matchers {
1818

19-
implicit val repo = unpackRepo(filePath)
20-
implicit val objectDirectory = repo.getObjectDatabase.asInstanceOf[ObjectDirectory]
21-
implicit lazy val (revWalk, reader) = repo.singleThreadedReaderTuple
19+
implicit val repo: FileRepository = unpackRepo(filePath)
20+
implicit val objectDirectory: ObjectDirectory = repo.getObjectDatabase
21+
implicit lazy val (revWalk: RevWalk, reader: ObjectReader) = repo.singleThreadedReaderTuple
2222

2323

2424
def blobOfSize(sizeInBytes: Int): Matcher[ObjectId] = Matcher { (objectId: ObjectId) =>
@@ -29,8 +29,8 @@ class unpackedRepo(filePath: String) extends AnyFlatSpec with Matchers {
2929
}
3030

3131
def packedBlobsOfSize(sizeInBytes: Long): Set[ObjectId] = {
32-
implicit val reader = repo.newObjectReader()
33-
repo.getObjectDatabase.asInstanceOf[ObjectDirectory].packedObjects.filter { objectId =>
32+
implicit val reader: ObjectReader = repo.newObjectReader()
33+
repo.getObjectDatabase.packedObjects.filter { objectId =>
3434
val objectLoader = objectId.open
3535
objectLoader.getType == OBJ_BLOB && objectLoader.getSize == sizeInBytes
3636
}.toSet

bfg/build.sbt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import java.io.{File, FileOutputStream}
22

3-
import Dependencies._
3+
import Dependencies.*
44
import sbt.taskKey
55

66
import scala.sys.process.Process
@@ -13,30 +13,37 @@ gitDescription := Try[String](Process("git describe --all --always --dirty --lon
1313
libraryDependencies += useNewerJava
1414

1515
mainClass := Some("use.newer.java.Version8")
16-
packageOptions in (Compile, packageBin) +=
16+
Compile / packageBin / packageOptions +=
1717
Package.ManifestAttributes( "Main-Class-After-UseNewerJava-Check" -> "com.madgag.git.bfg.cli.Main" )
1818

1919
// note you don't want the jar name to collide with the non-assembly jar, otherwise confusion abounds.
2020
assembly / assemblyJarName := s"${name.value}-${version.value}-${gitDescription.value}${jgitVersionOverride.map("-jgit-" + _).mkString}.jar"
2121

22+
assembly / assemblyMergeStrategy := {
23+
case PathList("META-INF", "versions", "9", "module-info.class") => MergeStrategy.discard
24+
case x =>
25+
val oldStrategy = (assembly / assemblyMergeStrategy).value
26+
oldStrategy(x)
27+
}
28+
2229
buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion, gitDescription)
2330

2431
buildInfoPackage := "com.madgag.git.bfg"
2532

2633
crossPaths := false
2734

28-
publishArtifact in (Compile, packageBin) := false
35+
Compile / packageBin / publishArtifact := false
2936

3037
// replace the conventional main artifact with an uber-jar
31-
addArtifact(artifact in (Compile, packageBin), assembly)
38+
addArtifact(Compile / packageBin / artifact, assembly)
3239

3340
val cliUsageDump = taskKey[File]("Dump the CLI 'usage' output to a file")
3441

3542
cliUsageDump := {
3643
val usageDumpFile = File.createTempFile("bfg-usage", "dump.txt")
3744
val scalaRun = new ForkRun(ForkOptions().withOutputStrategy(CustomOutput(new FileOutputStream(usageDumpFile))))
3845

39-
val mainClassName = (mainClass in (Compile, run)).value getOrElse sys.error("No main class detected.")
46+
val mainClassName = (Compile / run / mainClass).value getOrElse sys.error("No main class detected.")
4047
val classpath = Attributed.data((Runtime / fullClasspath).value)
4148
val args = Seq.empty
4249

@@ -52,7 +59,7 @@ libraryDependencies ++= Seq(
5259
scalaGitTest % "test"
5360
)
5461

55-
import Tests._
62+
import Tests.*
5663
{
5764
def isolateTestsWhichRequireTheirOwnJvm(tests: Seq[TestDefinition]) = {
5865
val (testsRequiringIsolation, testsNotNeedingIsolation) = tests.partition(_.name.contains("RequiresOwnJvm"))

bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object CLIConfig {
4545
val parser = new OptionParser[CLIConfig]("bfg") {
4646

4747
def fileMatcher(name: String, defaultType: TextMatcherType = Glob) = {
48-
implicit val textMatcherRead = Read.reads { TextMatcher(_, defaultType) }
48+
implicit val textMatcherRead: Read[TextMatcher] = Read.reads { TextMatcher(_, defaultType) }
4949

5050
opt[TextMatcher](name).valueName(s"<${defaultType.expressionPrefix}>").validate { m =>
5151
if (m.expression.contains('/')) {
@@ -143,7 +143,7 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,
143143

144144
lazy val gitdir = resolveGitDirFor(repoLocation)
145145

146-
implicit lazy val repo = FileRepositoryBuilder.create(gitdir.get).asInstanceOf[FileRepository]
146+
implicit lazy val repo: FileRepository = FileRepositoryBuilder.create(gitdir.get).asInstanceOf[FileRepository]
147147

148148
lazy val objectProtection = ProtectedObjectCensus(protectBlobsFromRevisions)
149149

bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package com.madgag.git.bfg.cli
2323
import com.madgag.git._
2424
import com.madgag.git.bfg.cli.test.unpackedRepo
2525
import com.madgag.git.bfg.model._
26-
import org.eclipse.jgit.lib.ObjectId
26+
import org.eclipse.jgit.lib.{ObjectId, ObjectReader}
2727
import org.scalatest.flatspec.AnyFlatSpec
2828
import org.scalatest.matchers.should.Matchers
2929
import org.scalatest.{Inspectors, OptionValues}
@@ -36,7 +36,7 @@ class MainSpec extends AnyFlatSpec with Matchers with OptionValues with Inspecto
3636
// concurrent testing against scala.App is not safe https://twitter.com/rtyley/status/340376844916387840
3737

3838
"CLI" should "not change commits unnecessarily" in new unpackedRepo("/sample-repos/exampleWithInitialCleanHistory.git.zip") {
39-
implicit val r = reader
39+
implicit val r: ObjectReader = reader
4040

4141
ensureInvariantValue(commitHist() take 2) {
4242
ensureRemovalFrom(commitHist()).ofCommitsThat(haveCommitWhereObjectIds(contain(abbrId("294f")))) {
@@ -90,7 +90,7 @@ class MainSpec extends AnyFlatSpec with Matchers with OptionValues with Inspecto
9090
}
9191

9292
"strip blobs by id" should "work" in new unpackedRepo("/sample-repos/example.git.zip") {
93-
implicit val r = reader
93+
implicit val r: ObjectReader = reader
9494

9595
val badBlobs = Set(abbrId("db59"), abbrId("86f9"))
9696
val blobIdsFile = Files.createTempFile("test-strip-blobs",".ids")

build.sbt

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import Dependencies._
2-
import common._
1+
import Dependencies.*
32

43
ThisBuild / organization := "com.madgag"
54

6-
ThisBuild / scalaVersion := "2.13.10"
5+
ThisBuild / scalaVersion := "2.13.16"
76

87
ThisBuild / scalacOptions ++= Seq("-deprecation", "-feature", "-language:postfixOps")
98

10-
ThisBuild / licenses := Seq("GPLv3" -> url("http://www.gnu.org/licenses/gpl-3.0.html"))
11-
12-
ThisBuild / homepage := Some(url("https://github.com/rtyley/bfg-repo-cleaner"))
9+
ThisBuild / licenses := Seq(License.GPL3_or_later)
1310

1411
ThisBuild / resolvers ++= jgitVersionOverride.map(_ => Resolver.mavenLocal).toSeq
1512

@@ -20,30 +17,12 @@ ThisBuild / Test/testOptions += Tests.Argument(
2017
"-u", s"test-results/scala-${scalaVersion.value}"
2118
)
2219

23-
lazy val root = Project(id = "bfg-parent", base = file(".")) aggregate (bfg, bfgTest, bfgLibrary)
24-
25-
releaseSignedArtifactsSettings
26-
27-
lazy val bfgTest = bfgProject("bfg-test")
20+
lazy val root = Project(id = "bfg-parent", base = file(".")) aggregate (bfg, `bfg-test`, `bfg-library`)
2821

29-
lazy val bfgLibrary = bfgProject("bfg-library") dependsOn(bfgTest % Test)
22+
lazy val `bfg-test` = project
3023

31-
lazy val bfg = bfgProject("bfg") enablePlugins(BuildInfoPlugin) dependsOn(bfgLibrary, bfgTest % Test)
24+
lazy val `bfg-library` = project.dependsOn(`bfg-test` % Test)
3225

33-
lazy val bfgBenchmark = bfgProject("bfg-benchmark")
26+
lazy val bfg = project.enablePlugins(BuildInfoPlugin).dependsOn(`bfg-library`, `bfg-test` % Test)
3427

35-
ThisBuild / publishTo := sonatypePublishToBundle.value
36-
37-
ThisBuild / pomExtra := (
38-
<scm>
39-
<url>git@github.com:rtyley/bfg-repo-cleaner.git</url>
40-
<connection>scm:git:git@github.com:rtyley/bfg-repo-cleaner.git</connection>
41-
</scm>
42-
<developers>
43-
<developer>
44-
<id>rtyley</id>
45-
<name>Roberto Tyley</name>
46-
<url>https://github.com/rtyley</url>
47-
</developer>
48-
</developers>
49-
)
28+
lazy val `bfg-benchmark` = project

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.8.2
1+
sbt.version=1.10.7

project/common.scala

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)