Skip to content

Commit

Permalink
Retain protected blobs (dirt) wherever they occur in history trees, n…
Browse files Browse the repository at this point in the history
…ot just in protected refs' trees. Fixed rtyley#49, rtyley#53, rtyley#138.

Added objectId exclusion filters during tree blob-cleaning, such that blobs that exist in the trees of protected refs as stored in the census (AKA dirt) are protected not only in those trees, but in any other trees in which they occur in in the walked-history.  This prevents the perception that those files are being deleted in-history and then re-added in the final re-written commit, which is the protected HEAD (with dirt) and its untouched tree.  This is more a perception because Git does not track the history of individual files, but it does show diffs and logs that indicate such changes, and the behaviour prior to this change is to remove protected blobs from non-protected history trees, retaining them only in the final HEAD ref, which then shows as an add in that commit when logs/diffs are taken.

This change is convenient if your clean-up selectors (by name, or size) do select some dirt (files still in HEADs that you want to keep) but you don't want those files to appear as if they were recently added to HEAD.
  • Loading branch information
javabrett committed May 17, 2016
1 parent 0b87cd7 commit 2a9387d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ import com.madgag.git.bfg.model.{TreeBlobEntry, _}
import com.madgag.textmatching.TextMatcher
import org.eclipse.jgit.lib.ObjectId

class FileDeleter(fileNameMatcher: TextMatcher, blobInserter: => Option[BlobInserter] = None) extends Cleaner[TreeBlobs] {
class FileDeleter(fileNameMatcher: TextMatcher, blobInserter: => Option[BlobInserter] = None)(implicit protectedObjectIds: Set[ObjectId] = Set.empty) extends Cleaner[TreeBlobs] {
override def apply(tbs: TreeBlobs) = tbs.entries.flatMap {
case e if protectedObjectIds contains e.objectId => Some(e)
case e if !fileNameMatcher(e.filename) => Some(e)
case e if !blobInserter.isEmpty => Some(TreeBlobEntry(FileName(e.filename + ".REMOVED.git-id"), RegularFile, blobInserter.get.insert(e.objectId.name.getBytes)))
case _ => None
}
}

class BlobRemover(blobIds: Set[ObjectId]) extends Cleaner[TreeBlobs] {
override def apply(treeBlobs: TreeBlobs) = treeBlobs.entries.filter(e => !blobIds.contains(e.objectId))
class BlobRemover(blobIds: Set[ObjectId])(implicit protectedObjectIds: Set[ObjectId] = Set.empty) extends Cleaner[TreeBlobs] {
override def apply(treeBlobs: TreeBlobs) = treeBlobs.entries.filter(e => (protectedObjectIds contains e.objectId) || !(blobIds contains e.objectId))
}

class BlobReplacer(badBlobs: Set[ObjectId], blobInserter: => BlobInserter) extends Cleaner[TreeBlobs] {
class BlobReplacer(badBlobs: Set[ObjectId], blobInserter: => BlobInserter)(implicit protectedObjectIds: Set[ObjectId] = Set.empty) extends Cleaner[TreeBlobs] {
override def apply(treeBlobs: TreeBlobs) = treeBlobs.entries.map {
case e if protectedObjectIds contains e.objectId => e
case e if badBlobs.contains(e.objectId) =>
TreeBlobEntry(FileName(e.filename + ".REMOVED.git-id"), RegularFile, blobInserter.insert(e.objectId.name.getBytes))
case e => e
Expand Down
2 changes: 2 additions & 0 deletions bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,

lazy val objectChecker = if (strictObjectChecking) Some(new ObjectChecker()) else None

implicit lazy val protectedObjectIds = objectProtection.blobIds

lazy val fileDeletion: Seq[Cleaner[TreeBlobs]] = deleteFiles.map {
case textMatcher if (replaceDeletedBlobs) => new FileDeleter(textMatcher, Some(new BlobInserter(repo.getObjectDatabase.threadLocalResources.inserter())))
case textMatcher => new FileDeleter(textMatcher, None)
Expand Down

0 comments on commit 2a9387d

Please sign in to comment.