Skip to content

Commit

Permalink
Updates- new JGit, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyley committed Jan 18, 2025
1 parent 70b3ca6 commit d49900e
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 105 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 11
cache: sbt
- uses: actions/checkout@v4
- uses: guardian/setup-scala@v1
- name: Build and Test
run: sbt -v test
- name: Test Summary
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release

on:
workflow_dispatch:

jobs:
release:
uses: guardian/gha-scala-library-release-workflow/.github/workflows/reusable-release.yml@v1
permissions: { contents: write, pull-requests: write }
with:
GITHUB_APP_ID: 930725
SONATYPE_PROFILE_NAME: 'com.madgag'
SONATYPE_CREDENTIAL_HOST: 's01.oss.sonatype.org'
secrets:
SONATYPE_TOKEN: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_TOKEN }}
PGP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
GITHUB_APP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_GITHUB_APP_PRIVATE_KEY }}
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java corretto-11.0.25.9.1
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ can run anywhere Java can.
Here's a rough set of instructions for building the BFG, if you don't want to use the
pre-built [downloads](http://rtyley.github.io/bfg-repo-cleaner/#download):

* Install Java JDK 8 or above
* Install Java JDK 11 or above
* Install [sbt](https://www.scala-sbt.org/1.x/docs/Setup.html)
* `git clone [email protected]:rtyley/bfg-repo-cleaner.git`
* `cd bfg-repo-cleaner`
Expand Down
2 changes: 1 addition & 1 deletion bfg-benchmark/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Dependencies._
import Dependencies.*

libraryDependencies ++= guava ++ Seq(
madgagCompress,
Expand Down
4 changes: 2 additions & 2 deletions bfg-library/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Dependencies._
import Dependencies.*

libraryDependencies ++= guava ++ Seq(
parCollections,
Expand All @@ -9,6 +9,6 @@ libraryDependencies ++= guava ++ Seq(
slf4jSimple,
lineSplitting,
scalaGitTest % Test,
"org.apache.commons" % "commons-text" % "1.9" % Test
"org.apache.commons" % "commons-text" % "1.13.0" % Test
)

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.madgag.textmatching.{Glob, TextMatcher}
import org.eclipse.jgit.internal.storage.file.FileRepository
import org.eclipse.jgit.lib.{ObjectId, ObjectReader}

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

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

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

val lfsPointerMemo = MemoUtil.concurrentCleanerMemo[ObjectId]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.eclipse.jgit.lib.Constants.OBJ_COMMIT
import org.eclipse.jgit.lib._
import org.eclipse.jgit.revwalk.RevCommit

import java.nio.charset.StandardCharsets.UTF_8
import java.nio.charset.{Charset, IllegalCharsetNameException, UnsupportedCharsetException}
import scala.jdk.CollectionConverters._

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

object CommitNode {
def apply(c: RevCommit): CommitNode = CommitNode(c.getAuthorIdent, c.getCommitterIdent, c.getFullMessage,
try c.getEncoding catch {case e @ (_ : IllegalCharsetNameException | _ : UnsupportedCharsetException) => Constants.CHARSET})
try c.getEncoding catch {case e @ (_ : IllegalCharsetNameException | _ : UnsupportedCharsetException) => UTF_8})
}

case class CommitNode(author: PersonIdent, committer: PersonIdent, message: String, encoding: Charset = Constants.CHARSET) {
case class CommitNode(author: PersonIdent, committer: PersonIdent, message: String, encoding: Charset = UTF_8) {
lazy val subject = message.linesIterator.to(LazyList).headOption
lazy val lastParagraphBreak = message.lastIndexOf("\n\n")
lazy val messageWithoutFooters = if (footers.isEmpty) message else (message take lastParagraphBreak)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ package com.madgag.git.bfg

import com.madgag.git._
import com.madgag.git.test._
import org.eclipse.jgit.internal.storage.file.FileRepository
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

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

"reachable blobs" should "match expectations" in {
implicit val (revWalk, reader) = repo.singleThreadedReaderTuple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.madgag.git.bfg.test

import com.madgag.git._
import com.madgag.git.test._
import org.eclipse.jgit.internal.storage.file.{GC, ObjectDirectory}
import org.eclipse.jgit.internal.storage.file.{FileRepository, GC, ObjectDirectory}
import org.eclipse.jgit.lib.Constants.OBJ_BLOB
import org.eclipse.jgit.lib.{ObjectId, ObjectReader, Repository}
import org.eclipse.jgit.revwalk.{RevCommit, RevTree}
import org.eclipse.jgit.revwalk.{RevCommit, RevTree, RevWalk}
import org.eclipse.jgit.treewalk.TreeWalk
import org.scalatest.Inspectors
import org.scalatest.flatspec.AnyFlatSpec
Expand All @@ -16,9 +16,9 @@ import scala.jdk.CollectionConverters._

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

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


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

def packedBlobsOfSize(sizeInBytes: Long): Set[ObjectId] = {
implicit val reader = repo.newObjectReader()
repo.getObjectDatabase.asInstanceOf[ObjectDirectory].packedObjects.filter { objectId =>
implicit val reader: ObjectReader = repo.newObjectReader()
repo.getObjectDatabase.packedObjects.filter { objectId =>
val objectLoader = objectId.open
objectLoader.getType == OBJ_BLOB && objectLoader.getSize == sizeInBytes
}.toSet
Expand Down
10 changes: 5 additions & 5 deletions bfg/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.io.{File, FileOutputStream}

import Dependencies._
import Dependencies.*
import sbt.taskKey

import scala.sys.process.Process
Expand All @@ -13,7 +13,7 @@ gitDescription := Try[String](Process("git describe --all --always --dirty --lon
libraryDependencies += useNewerJava

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

// note you don't want the jar name to collide with the non-assembly jar, otherwise confusion abounds.
Expand All @@ -25,10 +25,10 @@ buildInfoPackage := "com.madgag.git.bfg"

crossPaths := false

publishArtifact in (Compile, packageBin) := false
Compile / packageBin / publishArtifact := false

// replace the conventional main artifact with an uber-jar
addArtifact(artifact in (Compile, packageBin), assembly)
addArtifact(Compile / packageBin / artifact, assembly)

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

Expand All @@ -52,7 +52,7 @@ libraryDependencies ++= Seq(
scalaGitTest % "test"
)

import Tests._
import Tests.*
{
def isolateTestsWhichRequireTheirOwnJvm(tests: Seq[TestDefinition]) = {
val (testsRequiringIsolation, testsNotNeedingIsolation) = tests.partition(_.name.contains("RequiresOwnJvm"))
Expand Down
4 changes: 2 additions & 2 deletions bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object CLIConfig {
val parser = new OptionParser[CLIConfig]("bfg") {

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

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

lazy val gitdir = resolveGitDirFor(repoLocation)

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

lazy val objectProtection = ProtectedObjectCensus(protectBlobsFromRevisions)

Expand Down
6 changes: 3 additions & 3 deletions bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.madgag.git.bfg.cli
import com.madgag.git._
import com.madgag.git.bfg.cli.test.unpackedRepo
import com.madgag.git.bfg.model._
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.{ObjectId, ObjectReader}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{Inspectors, OptionValues}
Expand All @@ -36,7 +36,7 @@ class MainSpec extends AnyFlatSpec with Matchers with OptionValues with Inspecto
// concurrent testing against scala.App is not safe https://twitter.com/rtyley/status/340376844916387840

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

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

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

val badBlobs = Set(abbrId("db59"), abbrId("86f9"))
val blobIdsFile = Files.createTempFile("test-strip-blobs",".ids")
Expand Down
37 changes: 8 additions & 29 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import Dependencies._
import common._
import Dependencies.*

ThisBuild / organization := "com.madgag"

ThisBuild / scalaVersion := "2.13.10"
ThisBuild / scalaVersion := "2.13.16"

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

ThisBuild / licenses := Seq("GPLv3" -> url("http://www.gnu.org/licenses/gpl-3.0.html"))

ThisBuild / homepage := Some(url("https://github.com/rtyley/bfg-repo-cleaner"))
ThisBuild / licenses := Seq(License.GPL3_or_later)

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

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

lazy val root = Project(id = "bfg-parent", base = file(".")) aggregate (bfg, bfgTest, bfgLibrary)

releaseSignedArtifactsSettings

lazy val bfgTest = bfgProject("bfg-test")
lazy val root = Project(id = "bfg-parent", base = file(".")) aggregate (bfg, `bfg-test`, `bfg-library`)

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

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

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

ThisBuild / publishTo := sonatypePublishToBundle.value

ThisBuild / pomExtra := (
<scm>
<url>git@github.com:rtyley/bfg-repo-cleaner.git</url>
<connection>scm:git:git@github.com:rtyley/bfg-repo-cleaner.git</connection>
</scm>
<developers>
<developer>
<id>rtyley</id>
<name>Roberto Tyley</name>
<url>https://github.com/rtyley</url>
</developer>
</developers>
)
lazy val `bfg-benchmark` = project
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.2
sbt.version=1.10.7
24 changes: 0 additions & 24 deletions project/common.scala

This file was deleted.

20 changes: 10 additions & 10 deletions project/dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ import sbt._

object Dependencies {

val scalaGitVersion = "4.3"
val scalaGitVersion = "4.8"

val jgitVersionOverride = Option(System.getProperty("jgit.version"))

val jgitVersion = jgitVersionOverride.getOrElse("4.4.1.201607150455-r")
val jgitVersion = jgitVersionOverride.getOrElse("6.10.0.202406032230-r")

val jgit = "org.eclipse.jgit" % "org.eclipse.jgit" % jgitVersion

// the 1.7.2 here matches slf4j-api in jgit's dependencies
val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.7.2"

val scalaCollectionPlus = "com.madgag" %% "scala-collection-plus" % "0.5"
val scalaCollectionPlus = "com.madgag" %% "scala-collection-plus" % "0.11"

val parCollections = "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.0"
val parCollections = "org.scala-lang.modules" %% "scala-parallel-collections" % "1.2.0"

val scalaGit = "com.madgag.scala-git" %% "scala-git" % scalaGitVersion exclude("org.eclipse.jgit", "org.eclipse.jgit")

val scalaGitTest = "com.madgag.scala-git" %% "scala-git-test" % scalaGitVersion

val scalatest = "org.scalatest" %% "scalatest" % "3.2.2"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.19"

val madgagCompress = "com.madgag" % "util-compress" % "1.33"
val madgagCompress = "com.madgag" % "util-compress" % "1.35"

val textmatching = "com.madgag" %% "scala-textmatching" % "2.5"
val textmatching = "com.madgag" %% "scala-textmatching" % "2.8"

val scopt = "com.github.scopt" %% "scopt" % "3.7.1"

val guava = Seq("com.google.guava" % "guava" % "30.1-jre", "com.google.code.findbugs" % "jsr305" % "2.0.3")
val guava = Seq("com.google.guava" % "guava" % "33.4.0-jre", "com.google.code.findbugs" % "jsr305" % "3.0.2")

val useNewerJava = "com.madgag" % "use-newer-java" % "0.1"
val useNewerJava = "com.madgag" % "use-newer-java" % "1.0.2"

val lineSplitting = "com.madgag" %% "line-break-preserving-line-splitting" % "0.1.0"
val lineSplitting = "com.madgag" %% "line-break-preserving-line-splitting" % "0.1.6"

}
12 changes: 5 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
scalacOptions += "-deprecation"
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.0")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.1")

0 comments on commit d49900e

Please sign in to comment.