2010-11-15 22:06:21 +00:00
|
|
|
{- 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
|
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
|
|
|
command = [Command "dropunused" (paramRepeating paramNumber) seek
|
|
|
|
"drop unused file content"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-15 22:06:21 +00:00
|
|
|
seek = [withStrings start]
|
|
|
|
|
|
|
|
{- Drops unused content by number. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartString
|
2010-11-15 22:06:21 +00:00
|
|
|
start s = do
|
|
|
|
m <- readUnusedLog
|
|
|
|
case M.lookup s m of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just key -> do
|
|
|
|
showStart "dropunused" s
|
|
|
|
backend <- keyBackend key
|
2010-11-28 19:28:20 +00:00
|
|
|
return $ Just $ Command.Drop.perform key backend (Just 0)
|
2010-11-15 22:06:21 +00:00
|
|
|
|
|
|
|
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
|