Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --strip-trees-with-ids option #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = Some(v))
}
Expand Down Expand Up @@ -132,6 +135,7 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,
filterSizeThreshold: Int = 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 @@ -220,7 +224,13 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,
Seq(blobsByIdRemover, blobRemover, fileDeletion, blobTextModifier, lfsBlobConverter).flatten
}

lazy val definesNoWork = treeBlobCleaners.isEmpty && folderDeletion.isEmpty && treeEntryListCleaners.isEmpty
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

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

Expand Down