aboutsummaryrefslogtreecommitdiff
path: root/Command/Forget.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-08-31 17:38:33 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-08-31 17:51:13 -0400
commit2afb4de6c02a4515f8b1bf6e24a32cbde7eae5a8 (patch)
tree22f667488fe21140622dd235fed81d03c1b747de /Command/Forget.hs
parent2b83639fac92307deeaa7b1bc75a0c71f35e5b1e (diff)
forget --drop-dead: Completely removes mentions of repositories that have been marked as dead from the git-annex branch.
Wrote nice pure transition calculator, and ugly code to stage its results into the git-annex branch. Also had to split up several Log modules that Annex.Branch needed to use, but that themselves used Annex.Branch. The transition calculator is limited to looking at and changing one file at a time. While this made the implementation relatively easy, it precludes transitions that do stuff like deleting old url log files for keys that are being removed because they are no longer present anywhere.
Diffstat (limited to 'Command/Forget.hs')
-rw-r--r--Command/Forget.hs31
1 files changed, 21 insertions, 10 deletions
diff --git a/Command/Forget.hs b/Command/Forget.hs
index e405a9918..d216ae3ca 100644
--- a/Command/Forget.hs
+++ b/Command/Forget.hs
@@ -12,30 +12,41 @@ import Command
import qualified Annex.Branch as Branch
import Logs.Transitions
import qualified Annex
+import qualified Option
import Data.Time.Clock.POSIX
def :: [Command]
-def = [command "forget" paramNothing seek
+def = [withOptions forgetOptions $ command "forget" paramNothing seek
SectionMaintenance "prune git-annex branch history"]
+forgetOptions :: [Option]
+forgetOptions = [dropDeadOption]
+
+dropDeadOption :: Option
+dropDeadOption = Option.flag [] "drop-dead" "drop references to dead repositories"
+
seek :: [CommandSeek]
-seek = [withNothing start]
+seek = [withFlag dropDeadOption $ \dropdead ->
+ withNothing $ start dropdead]
-start :: CommandStart
-start = do
+start :: Bool -> CommandStart
+start dropdead = do
showStart "forget" "git-annex"
- next $ perform =<< Annex.getState Annex.force
-
-perform :: Bool -> CommandPerform
-perform True = do
now <- liftIO getPOSIXTime
- let ts = addTransition now ForgetGitHistory noTransitions
+ let basets = addTransition now ForgetGitHistory noTransitions
+ let ts = if dropdead
+ then addTransition now ForgetDeadRemotes basets
+ else basets
+ next $ perform ts =<< Annex.getState Annex.force
+
+perform :: Transitions -> Bool -> CommandPerform
+perform ts True = do
recordTransitions Branch.change ts
-- get branch committed before contining with the transition
Branch.update
void $ Branch.performTransitions ts True
next $ return True
-perform False = do
+perform _ False = do
showLongNote "To forget git-annex branch history, you must specify --force. This deletes metadata!"
stop