summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-15 18:06:21 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-15 18:06:21 -0400
commit3a4e9398a1652b664fb17dc2072f4b85966dcb61 (patch)
treeae2fe1c4793927112169345dc9f794c4fdef2cdd
parent748a7475bb99e1127dc12bb2cc9d5653e4648200 (diff)
add
-rw-r--r--Command/DropUnused.hs46
1 files changed, 46 insertions, 0 deletions
diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs
new file mode 100644
index 000000000..e8b8d43c4
--- /dev/null
+++ b/Command/DropUnused.hs
@@ -0,0 +1,46 @@
+{- git-annex command
+ -
+ - Copyright 2010 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.DropUnused where
+
+import Control.Monad.State (liftIO)
+import qualified Data.Map as M
+
+import Command
+import Types
+import Messages
+import Locations
+import qualified Annex
+import qualified Command.Drop
+import Backend
+
+seek :: [SubCmdSeek]
+seek = [withStrings start]
+
+{- Drops unused content by number. -}
+start :: SubCmdStartString
+start s = do
+ m <- readUnusedLog
+ case M.lookup s m of
+ Nothing -> return Nothing
+ Just key -> do
+ showStart "dropunused" s
+ backend <- keyBackend key
+ -- force drop, even if this is the only copy
+ Annex.flagChange "force" $ FlagBool True
+ return $ Just $ Command.Drop.perform key backend
+
+readUnusedLog :: Annex (M.Map String Key)
+readUnusedLog = do
+ g <- Annex.gitRepo
+ l <- liftIO $ readFile (annexUnusedLog g)
+ return $ M.fromList $ map parse $ lines l
+ where
+ parse line = (head ws, tokey $ unwords $ tail ws)
+ where
+ ws = words line
+ tokey s = read s :: Key