git-annex/Command/Forget.hs
Joey Hess aeca7c2207
Sped up query commands that read the git-annex branch by around 5%
The only price paid is one additional MVar read per write to the journal.
Presumably writing a journal file dominiates over a MVar read time by
several orders of magnitude.

--batch does not get the speedup because then it needs to notice when
another process has made a change. Also made the assistant and other damon
modes bypass the optimisation, which would not help them anyway.
2020-04-09 13:54:43 -04:00

53 lines
1.4 KiB
Haskell

{- git-annex command
-
- Copyright 2013 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Command.Forget where
import Command
import qualified Annex.Branch as Branch
import Logs.Transitions
import qualified Annex
import Annex.VectorClock
cmd :: Command
cmd = command "forget" SectionMaintenance
"prune git-annex branch history"
paramNothing (seek <$$> optParser)
data ForgetOptions = ForgetOptions
{ dropDead :: Bool
}
optParser :: CmdParamsDesc -> Parser ForgetOptions
optParser _ = ForgetOptions
<$> switch
( long "drop-dead"
<> help "drop references to dead repositories"
)
seek :: ForgetOptions -> CommandSeek
seek = commandAction . start
start :: ForgetOptions -> CommandStart
start o = starting "forget" (ActionItemOther (Just "git-annex")) $ do
c <- liftIO currentVectorClock
let basets = addTransition c ForgetGitHistory noTransitions
let ts = if dropDead o
then addTransition c ForgetDeadRemotes basets
else basets
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
showLongNote "To forget git-annex branch history, you must specify --force. This deletes metadata!"
stop