summaryrefslogtreecommitdiff
path: root/Command/DropUnused.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 16:15:31 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-10 16:15:31 -0400
commit8b5e406cffc7eeccba308ff4219a26cfc6d10ac2 (patch)
tree8913c54a868ebcbd5af19dfb862e125fff98ae08 /Command/DropUnused.hs
parentaa96e9c8667b5e80b5ccae1958a073518d463dfa (diff)
convert DropUnused
Diffstat (limited to 'Command/DropUnused.hs')
-rw-r--r--Command/DropUnused.hs39
1 files changed, 23 insertions, 16 deletions
diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs
index 703cc3890..98fcef6ea 100644
--- a/Command/DropUnused.hs
+++ b/Command/DropUnused.hs
@@ -9,7 +9,6 @@ module Command.DropUnused where
import Common.Annex
import Command
-import qualified Annex
import qualified Command.Drop
import qualified Remote
import qualified Git
@@ -17,27 +16,35 @@ import Command.Unused (withUnusedMaps, UnusedMaps(..), startUnused)
import Annex.NumCopies
cmd :: Command
-cmd = withOptions [Command.Drop.dropFromOption] $
- command "dropunused" SectionMaintenance
- "drop unused file content"
- (paramRepeating paramNumRange) (withParams seek)
+cmd = command "dropunused" SectionMaintenance
+ "drop unused file content"
+ (paramRepeating paramNumRange) (seek <$$> optParser)
-seek :: CmdParams -> CommandSeek
-seek ps = do
+data DropUnusedOptions = DropUnusedOptions
+ { rangesToDrop :: CmdParams
+ , dropFrom :: Maybe (DeferredParse Remote)
+ }
+
+optParser :: CmdParamsDesc -> Parser DropUnusedOptions
+optParser desc = DropUnusedOptions
+ <$> cmdParams desc
+ <*> optional (Command.Drop.parseDropFromOption)
+
+seek :: DropUnusedOptions -> CommandSeek
+seek o = do
numcopies <- getNumCopies
- withUnusedMaps (start numcopies) ps
+ from <- maybe (pure Nothing) (Just <$$> getParsed) (dropFrom o)
+ withUnusedMaps (start from numcopies) (rangesToDrop o)
-start :: NumCopies -> UnusedMaps -> Int -> CommandStart
-start numcopies = startUnused "dropunused" (perform numcopies) (performOther gitAnnexBadLocation) (performOther gitAnnexTmpObjectLocation)
+start :: Maybe Remote -> NumCopies -> UnusedMaps -> Int -> CommandStart
+start from numcopies = startUnused "dropunused" (perform from numcopies) (performOther gitAnnexBadLocation) (performOther gitAnnexTmpObjectLocation)
-perform :: NumCopies -> Key -> CommandPerform
-perform numcopies key = maybe droplocal dropremote =<< Remote.byNameWithUUID =<< from
- where
- dropremote r = do
+perform :: Maybe Remote -> NumCopies -> Key -> CommandPerform
+perform from numcopies key = case from of
+ Just r -> do
showAction $ "from " ++ Remote.name r
Command.Drop.performRemote key Nothing numcopies r
- droplocal = Command.Drop.performLocal key Nothing numcopies Nothing
- from = Annex.getField $ optionName Command.Drop.dropFromOption
+ Nothing -> Command.Drop.performLocal key Nothing numcopies Nothing
performOther :: (Key -> Git.Repo -> FilePath) -> Key -> CommandPerform
performOther filespec key = do