summaryrefslogtreecommitdiff
path: root/Command/DropUnused.hs
blob: ea2ff46eba1c00d3b2d6624e4e396b77d9ac08fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{- 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

command :: [Command]
command = [Command "dropunused" (paramRepeating paramNumber) seek
	"drop unused file content"]

seek :: [CommandSeek]
seek = [withStrings start]

{- Drops unused content by number. -} 
start :: CommandStartString
start s = do
	m <- readUnusedLog
	case M.lookup s m of
		Nothing -> return Nothing
		Just key -> do
			showStart "dropunused" s
			backend <- keyBackend key
			return $ Just $ Command.Drop.perform key backend (Just 0)

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