2010-11-15 22:06:21 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2012-05-02 17:15:19 +00:00
|
|
|
- Copyright 2010,2012 Joey Hess <joey@kitenet.net>
|
2010-11-15 22:06:21 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.DropUnused where
|
|
|
|
|
2012-05-02 18:59:05 +00:00
|
|
|
import Logs.Unused
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-15 22:06:21 +00:00
|
|
|
import Command
|
|
|
|
import qualified Annex
|
|
|
|
import qualified Command.Drop
|
2011-04-03 00:59:41 +00:00
|
|
|
import qualified Remote
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git
|
2012-01-06 14:14:37 +00:00
|
|
|
import qualified Option
|
2011-04-29 17:59:00 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
def = [withOptions [Command.Drop.fromOption] $
|
2012-05-02 18:59:05 +00:00
|
|
|
command "dropunused" (paramRepeating paramNumRange)
|
2013-03-24 22:28:21 +00:00
|
|
|
seek SectionMaintenance "drop unused file content"]
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2012-05-02 18:59:05 +00:00
|
|
|
seek = [withUnusedMaps start]
|
2012-05-02 17:15:19 +00:00
|
|
|
|
2012-05-02 18:59:05 +00:00
|
|
|
start :: UnusedMaps -> Int -> CommandStart
|
|
|
|
start = startUnused "dropunused" perform (performOther gitAnnexBadLocation) (performOther gitAnnexTmpLocation)
|
2011-04-03 00:59:41 +00:00
|
|
|
|
|
|
|
perform :: Key -> CommandPerform
|
2013-03-05 19:39:42 +00:00
|
|
|
perform key = maybe droplocal dropremote =<< Remote.byNameWithUUID =<< from
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
dropremote r = do
|
|
|
|
showAction $ "from " ++ Remote.name r
|
|
|
|
ok <- Remote.removeKey r key
|
|
|
|
next $ Command.Drop.cleanupRemote key r ok
|
2012-11-24 20:30:15 +00:00
|
|
|
droplocal = Command.Drop.performLocal key (Just 0) Nothing -- force drop
|
2012-11-12 05:05:04 +00:00
|
|
|
from = Annex.getField $ Option.name Command.Drop.fromOption
|
2011-04-03 00:59:41 +00:00
|
|
|
|
2011-11-08 19:34:10 +00:00
|
|
|
performOther :: (Key -> Git.Repo -> FilePath) -> Key -> CommandPerform
|
2011-04-29 17:59:00 +00:00
|
|
|
performOther filespec key = do
|
2011-11-08 19:34:10 +00:00
|
|
|
f <- fromRepo $ filespec key
|
2012-06-06 17:13:13 +00:00
|
|
|
liftIO $ nukeFile f
|
2011-05-15 06:02:46 +00:00
|
|
|
next $ return True
|