Skip to content

Commit

Permalink
Add --strip-trees-with-ids option (From pull rtyley#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski authored and Whoaa512 committed Apr 13, 2020
1 parent 0ad1b64 commit e9a4e5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class BlobRemover(blobIds: Set[ObjectId]) extends Cleaner[TreeBlobs] {
override def apply(treeBlobs: TreeBlobs) = treeBlobs.entries.filter(e => !blobIds.contains(e.objectId))
}

class SubtreeRemover(blobIds: Set[ObjectId]) extends Cleaner[TreeSubtrees] {
override def apply(subtrees: TreeSubtrees) = TreeSubtrees(subtrees.entryMap.filter(e => !blobIds.contains(e._2)))
}

class BlobReplacer(badBlobs: Set[ObjectId], blobInserter: => BlobInserter) extends Cleaner[TreeBlobs] {
override def apply(treeBlobs: TreeBlobs) = treeBlobs.entries.map {
case e if badBlobs.contains(e.objectId) =>
Expand Down
14 changes: 12 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 @@ -68,6 +68,9 @@ object CLIConfig {
opt[File]("strip-blobs-with-ids").abbr("bi").valueName("<blob-ids-file>").text("strip blobs with the specified Git object ids").action {
(v, c) => c.copy(stripBlobsWithIds = Some(v.lines().map(_.trim).filterNot(_.isEmpty).map(_.asObjectId).toSet))
}
opt[File]("strip-trees-with-ids").valueName("<tree-ids-file>").text("strip trees with the specified Git object ids").action {
(v, c) => c.copy(stripSubtreesWithIds = Some(v.lines().map(_.trim).filterNot(_.isEmpty).map(_.asObjectId).toSet))
}
fileMatcher("delete-files").abbr("D").text("delete files with the specified names (eg '*.class', '*.{txt,log}' - matches on file name, not path within repo)").action {
(v, c) => c.copy(deleteFiles = c.deleteFiles :+ v)
}
Expand Down Expand Up @@ -136,6 +139,7 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,
filterSizeThreshold: Long = BlobTextModifier.DefaultSizeThreshold,
textReplacementExpressions: Traversable[String] = List.empty,
stripBlobsWithIds: Option[Set[ObjectId]] = None,
stripSubtreesWithIds: Option[Set[ObjectId]] = None,
lfsConversion: Option[String] = None,
strictObjectChecking: Boolean = false,
sensitiveData: Option[Boolean] = None,
Expand Down Expand Up @@ -225,7 +229,13 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,
Seq(blobsByIdRemover, blobRemover, blobTextModifier, lfsBlobConverter).flatten ++ fileDeletion
}

lazy val definesNoWork = treeBlobCleaners.isEmpty && folderDeletion.isEmpty && treeEntryListCleaners.isEmpty && !pruneEmptyCommits
lazy val treeSubtreesCleaners: Seq[Cleaner[TreeSubtrees]] = {
lazy val subtreesByIdRemover: Option[SubtreeRemover] = stripSubtreesWithIds.map(new SubtreeRemover(_))

Seq(subtreesByIdRemover, folderDeletion).flatten
}

lazy val definesNoWork = treeBlobCleaners.isEmpty && treeSubtreesCleaners.isEmpty && treeEntryListCleaners.isEmpty && !pruneEmptyCommits

def objectIdCleanerConfig: ObjectIdCleaner.Config =
ObjectIdCleaner.Config(
Expand All @@ -235,7 +245,7 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,
commitNodeCleaners,
treeEntryListCleaners,
treeBlobCleaners,
folderDeletion.toSeq,
treeSubtreesCleaners,
objectChecker
)

Expand Down

0 comments on commit e9a4e5f

Please sign in to comment.