summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-15 16:24:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-15 16:24:47 -0400
commit456b45b9b3982d9440a43ec014635dee15066f0e (patch)
tree18760407864d501595b0cf89de00c755a0105931
parentd036cd590f5c3c4edcd025effcf57c3d16886559 (diff)
move annex.numcopies parsing into withNumCopies
-rw-r--r--Command.hs13
-rw-r--r--Command/Copy.hs7
-rw-r--r--Command/Drop.hs7
-rw-r--r--Command/Fsck.hs7
-rw-r--r--Command/Get.hs7
5 files changed, 16 insertions, 25 deletions
diff --git a/Command.hs b/Command.hs
index bcc05c03c..05b215ec2 100644
--- a/Command.hs
+++ b/Command.hs
@@ -59,9 +59,6 @@ type CommandStartKey = Key -> CommandStart
type BackendFile = (FilePath, Maybe (Backend Annex))
type CommandSeekBackendFiles = CommandStartBackendFile -> CommandSeek
type CommandStartBackendFile = BackendFile -> CommandStart
-type AttrFile = (FilePath, String)
-type CommandSeekAttrFiles = CommandStartAttrFile -> CommandSeek
-type CommandStartAttrFile = AttrFile -> CommandStart
type CommandSeekNothing = CommandStart -> CommandSeek
type CommandStartNothing = CommandStart
@@ -129,14 +126,18 @@ withFilesInGit a params = do
repo <- Annex.gitRepo
files <- liftIO $ runPreserveOrder (LsFiles.inRepo repo) params
liftM (map a) $ filterFiles files
-withAttrFilesInGit :: String -> CommandSeekAttrFiles
+withAttrFilesInGit :: String -> ((FilePath, String) -> CommandStart) -> CommandSeek
withAttrFilesInGit attr a params = do
repo <- Annex.gitRepo
files <- liftIO $ runPreserveOrder (LsFiles.inRepo repo) params
files' <- filterFiles files
liftM (map a) $ liftIO $ Git.checkAttr repo attr files'
-withNumCopies :: CommandSeekAttrFiles
-withNumCopies = withAttrFilesInGit "annex.numcopies"
+withNumCopies :: (FilePath -> Maybe Int -> CommandStart) -> CommandSeek
+withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params
+ where
+ go (file, v) = do
+ let numcopies = readMaybe v
+ a file numcopies
withBackendFilesInGit :: CommandSeekBackendFiles
withBackendFilesInGit a params = do
repo <- Annex.gitRepo
diff --git a/Command/Copy.hs b/Command/Copy.hs
index 125e0bb9f..d7625ccdb 100644
--- a/Command/Copy.hs
+++ b/Command/Copy.hs
@@ -9,7 +9,6 @@ module Command.Copy where
import Command
import qualified Command.Move
-import Utility
command :: [Command]
command = [repoCommand "copy" paramPaths seek
@@ -20,9 +19,7 @@ seek = [withNumCopies start]
-- A copy is just a move that does not delete the source file.
-- However, --auto mode avoids unnecessary copies.
-start :: CommandStartAttrFile
-start (file, attr) = isAnnexed file $ \(key, _) ->
+start :: FilePath -> Maybe Int -> CommandStart
+start file numcopies = isAnnexed file $ \(key, _) ->
autoCopies key (<) numcopies $
Command.Move.start False file
- where
- numcopies = readMaybe attr
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 1325e3dcb..4a7596921 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -14,7 +14,6 @@ import LocationLog
import Types
import Content
import Messages
-import Utility
import Utility.Conditional
import Trust
import Config
@@ -28,16 +27,14 @@ seek = [withNumCopies start]
{- Indicates a file's content is not wanted anymore, and should be removed
- if it's safe to do so. -}
-start :: CommandStartAttrFile
-start (file, attr) = isAnnexed file $ \(key, _) -> do
+start :: FilePath -> Maybe Int -> CommandStart
+start file numcopies = isAnnexed file $ \(key, _) -> do
present <- inAnnex key
if present
then autoCopies key (>) numcopies $ do
showStart "drop" file
next $ perform key numcopies
else stop
- where
- numcopies = readMaybe attr
perform :: Key -> Maybe Int -> CommandPerform
perform key numcopies = do
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 4e8eeb043..142f755a7 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -20,7 +20,6 @@ import qualified Types.Key
import UUID
import Types
import Messages
-import Utility
import Content
import LocationLog
import Locations
@@ -35,10 +34,10 @@ command = [repoCommand "fsck" paramPaths seek "check for problems"]
seek :: [CommandSeek]
seek = [withNumCopies start]
-start :: CommandStartAttrFile
-start (file, attr) = notBareRepo $ isAnnexed file $ \(key, backend) -> do
+start :: FilePath -> Maybe Int -> CommandStart
+start file numcopies = notBareRepo $ isAnnexed file $ \(key, backend) -> do
showStart "fsck" file
- next $ perform key file backend $ readMaybe attr
+ next $ perform key file backend numcopies
perform :: Key -> FilePath -> Backend Annex -> Maybe Int -> CommandPerform
perform key file backend numcopies = do
diff --git a/Command/Get.hs b/Command/Get.hs
index bc617c9fa..4fd654f63 100644
--- a/Command/Get.hs
+++ b/Command/Get.hs
@@ -13,7 +13,6 @@ import qualified Remote
import Types
import Content
import Messages
-import Utility
import qualified Command.Move
command :: [Command]
@@ -23,8 +22,8 @@ command = [repoCommand "get" paramPaths seek
seek :: [CommandSeek]
seek = [withNumCopies start]
-start :: CommandStartAttrFile
-start (file, attr) = isAnnexed file $ \(key, _) -> do
+start :: FilePath -> Maybe Int -> CommandStart
+start file numcopies = isAnnexed file $ \(key, _) -> do
inannex <- inAnnex key
if inannex
then stop
@@ -37,8 +36,6 @@ start (file, attr) = isAnnexed file $ \(key, _) -> do
-- get --from = copy --from
src <- Remote.byName name
next $ Command.Move.fromPerform src False key
- where
- numcopies = readMaybe attr
perform :: Key -> CommandPerform
perform key = do