diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-07-20 15:22:55 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-07-20 15:23:43 -0400 |
commit | 258a3356e6461e0164441bb3a3e202cb9ef889e6 (patch) | |
tree | f198f34aaedeffb1af624f918a214527b066175a /Command | |
parent | e97cd57e1ac72d5a240852704ebaf92716fcad94 (diff) |
--branch, stage 2
Show branch:file that is being operated on.
I had to make ActionItem a type and not a type class because
withKeyOptions' passed two different types of values when using the type
class, and I could not get the type checker to accept that.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Drop.hs | 28 | ||||
-rw-r--r-- | Command/DropKey.hs | 2 | ||||
-rw-r--r-- | Command/Fsck.hs | 16 | ||||
-rw-r--r-- | Command/Get.hs | 11 | ||||
-rw-r--r-- | Command/MetaData.hs | 13 | ||||
-rw-r--r-- | Command/Mirror.hs | 16 | ||||
-rw-r--r-- | Command/Move.hs | 34 | ||||
-rw-r--r-- | Command/SetPresentKey.hs | 2 | ||||
-rw-r--r-- | Command/Sync.hs | 7 | ||||
-rw-r--r-- | Command/Whereis.hs | 13 |
10 files changed, 73 insertions, 69 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs index 16196f0ca..79797ab02 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -63,36 +63,38 @@ seek o = allowConcurrentOutput $ go = whenAnnexed $ start o start :: DropOptions -> FilePath -> Key -> CommandStart -start o file key = start' o key (Just file) +start o file key = start' o key afile (mkActionItem afile) + where + afile = Just file -start' :: DropOptions -> Key -> AssociatedFile -> CommandStart -start' o key afile = do +start' :: DropOptions -> Key -> AssociatedFile -> ActionItem -> CommandStart +start' o key afile ai = do from <- maybe (pure Nothing) (Just <$$> getParsed) (dropFrom o) checkDropAuto (autoMode o) from afile key $ \numcopies -> stopUnless (want from) $ case from of - Nothing -> startLocal afile numcopies key [] + Nothing -> startLocal afile ai numcopies key [] Just remote -> do u <- getUUID if Remote.uuid remote == u - then startLocal afile numcopies key [] - else startRemote afile numcopies key remote + then startLocal afile ai numcopies key [] + else startRemote afile ai numcopies key remote where want from | autoMode o = wantDrop False (Remote.uuid <$> from) (Just key) afile | otherwise = return True -startKeys :: DropOptions -> Key -> CommandStart +startKeys :: DropOptions -> Key -> ActionItem -> CommandStart startKeys o key = start' o key Nothing -startLocal :: AssociatedFile -> NumCopies -> Key -> [VerifiedCopy] -> CommandStart -startLocal afile numcopies key preverified = stopUnless (inAnnex key) $ do - showStart' "drop" key afile +startLocal :: AssociatedFile -> ActionItem -> NumCopies -> Key -> [VerifiedCopy] -> CommandStart +startLocal afile ai numcopies key preverified = stopUnless (inAnnex key) $ do + showStart' "drop" key ai next $ performLocal key afile numcopies preverified -startRemote :: AssociatedFile -> NumCopies -> Key -> Remote -> CommandStart -startRemote afile numcopies key remote = do - showStart' ("drop " ++ Remote.name remote) key afile +startRemote :: AssociatedFile -> ActionItem -> NumCopies -> Key -> Remote -> CommandStart +startRemote afile ai numcopies key remote = do + showStart' ("drop " ++ Remote.name remote) key ai next $ performRemote key afile numcopies remote performLocal :: Key -> AssociatedFile -> NumCopies -> [VerifiedCopy] -> CommandPerform diff --git a/Command/DropKey.hs b/Command/DropKey.hs index 9a9d51354..42516f838 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -42,7 +42,7 @@ seek o = do start :: Key -> CommandStart start key = do - showStart' "dropkey" key key + showStart' "dropkey" key (mkActionItem key) next $ perform key perform :: Key -> CommandPerform diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 6bc91f0ef..4972be649 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -89,7 +89,7 @@ seek o = allowConcurrentOutput $ do checkDeadRepo u i <- prepIncremental u (incrementalOpt o) withKeyOptions (keyOptions o) False - (\k -> startKey i k =<< getNumCopies) + (\k ai -> startKey i k ai =<< getNumCopies) (withFilesInGit $ whenAnnexed $ start from i) (fsckFiles o) cleanupIncremental i @@ -111,7 +111,7 @@ start from inc file key = do Nothing -> go $ perform key file backend numcopies Just r -> go $ performRemote key file backend numcopies r where - go = runFsck inc file key + go = runFsck inc (mkActionItem (Just file)) key perform :: Key -> FilePath -> Backend -> NumCopies -> Annex Bool perform key file backend numcopies = do @@ -173,11 +173,11 @@ performRemote key file backend numcopies remote = ) dummymeter _ = noop -startKey :: Incremental -> Key -> NumCopies -> CommandStart -startKey inc key numcopies = +startKey :: Incremental -> Key -> ActionItem -> NumCopies -> CommandStart +startKey inc key ai numcopies = case Backend.maybeLookupBackendName (keyBackendName key) of Nothing -> stop - Just backend -> runFsck inc (key2file key) key $ + Just backend -> runFsck inc ai key $ performKey key backend numcopies performKey :: Key -> Backend -> NumCopies -> Annex Bool @@ -504,10 +504,10 @@ badContentRemote remote localcopy key = do (False, True) -> "dropped from " ++ Remote.name remote (_, False) -> "failed to drop from" ++ Remote.name remote -runFsck :: Incremental -> FilePath -> Key -> Annex Bool -> CommandStart -runFsck inc file key a = ifM (needFsck inc key) +runFsck :: Incremental -> ActionItem -> Key -> Annex Bool -> CommandStart +runFsck inc ai key a = ifM (needFsck inc key) ( do - showStart "fsck" file + showStart' "fsck" key ai next $ do ok <- a when ok $ diff --git a/Command/Get.hs b/Command/Get.hs index a56661ef4..3f461fa04 100644 --- a/Command/Get.hs +++ b/Command/Get.hs @@ -49,17 +49,18 @@ seek o = allowConcurrentOutput $ do (getFiles o) start :: GetOptions -> Maybe Remote -> FilePath -> Key -> CommandStart -start o from file key = start' expensivecheck from key (Just file) +start o from file key = start' expensivecheck from key afile (mkActionItem afile) where + afile = Just file expensivecheck | autoMode o = numCopiesCheck file key (<) <||> wantGet False (Just key) (Just file) | otherwise = return True -startKeys :: Maybe Remote -> Key -> CommandStart +startKeys :: Maybe Remote -> Key -> ActionItem -> CommandStart startKeys from key = start' (return True) from key Nothing -start' :: Annex Bool -> Maybe Remote -> Key -> AssociatedFile -> CommandStart -start' expensivecheck from key afile = stopUnless (not <$> inAnnex key) $ +start' :: Annex Bool -> Maybe Remote -> Key -> AssociatedFile -> ActionItem -> CommandStart +start' expensivecheck from key afile ai = stopUnless (not <$> inAnnex key) $ stopUnless expensivecheck $ case from of Nothing -> go $ perform key afile @@ -68,7 +69,7 @@ start' expensivecheck from key afile = stopUnless (not <$> inAnnex key) $ go $ Command.Move.fromPerform src False key afile where go a = do - showStart' "get" key afile + showStart' "get" key ai next a perform :: Key -> AssociatedFile -> CommandPerform diff --git a/Command/MetaData.hs b/Command/MetaData.hs index e2afccb9b..14e727fc7 100644 --- a/Command/MetaData.hs +++ b/Command/MetaData.hs @@ -69,20 +69,19 @@ seek o = do (forFiles o) start :: POSIXTime -> MetaDataOptions -> FilePath -> Key -> CommandStart -start now o file = start' (Just file) now o - -startKeys :: POSIXTime -> MetaDataOptions -> Key -> CommandStart -startKeys = start' Nothing +start now o file k = startKeys now o k (mkActionItem afile) + where + afile = Just file -start' :: AssociatedFile -> POSIXTime -> MetaDataOptions -> Key -> CommandStart -start' afile now o k = case getSet o of +startKeys :: POSIXTime -> MetaDataOptions -> Key -> ActionItem -> CommandStart +startKeys now o k ai = case getSet o of Get f -> do l <- S.toList . currentMetaDataValues f <$> getCurrentMetaData k liftIO $ forM_ l $ putStrLn . fromMetaValue stop _ -> do - showStart' "metadata" k afile + showStart' "metadata" k ai next $ perform now o k perform :: POSIXTime -> MetaDataOptions -> Key -> CommandPerform diff --git a/Command/Mirror.hs b/Command/Mirror.hs index 8fdba123b..50aca0338 100644 --- a/Command/Mirror.hs +++ b/Command/Mirror.hs @@ -47,25 +47,27 @@ seek o = allowConcurrentOutput $ (mirrorFiles o) start :: MirrorOptions -> FilePath -> Key -> CommandStart -start o file = startKey o (Just file) +start o file k = startKey o afile k (mkActionItem afile) + where + afile = Just file -startKey :: MirrorOptions -> Maybe FilePath -> Key -> CommandStart -startKey o afile key = case fromToOptions o of +startKey :: MirrorOptions -> Maybe FilePath -> Key -> ActionItem -> CommandStart +startKey o afile key ai = case fromToOptions o of ToRemote r -> ifM (inAnnex key) - ( Command.Move.toStart False afile key =<< getParsed r + ( Command.Move.toStart False afile key ai =<< getParsed r , do numcopies <- getnumcopies - Command.Drop.startRemote afile numcopies key =<< getParsed r + Command.Drop.startRemote afile ai numcopies key =<< getParsed r ) FromRemote r -> do haskey <- flip Remote.hasKey key =<< getParsed r case haskey of Left _ -> stop - Right True -> Command.Get.start' (return True) Nothing key afile + Right True -> Command.Get.start' (return True) Nothing key afile ai Right False -> ifM (inAnnex key) ( do numcopies <- getnumcopies - Command.Drop.startLocal afile numcopies key [] + Command.Drop.startLocal afile ai numcopies key [] , stop ) where diff --git a/Command/Move.hs b/Command/Move.hs index 2d2a6a227..88ca4e01d 100644 --- a/Command/Move.hs +++ b/Command/Move.hs @@ -51,18 +51,20 @@ seek o = allowConcurrentOutput $ (moveFiles o) start :: MoveOptions -> Bool -> FilePath -> Key -> CommandStart -start o move = start' o move . Just +start o move f k = start' o move afile k (mkActionItem afile) + where + afile = Just f -startKey :: MoveOptions -> Bool -> Key -> CommandStart +startKey :: MoveOptions -> Bool -> Key -> ActionItem -> CommandStart startKey o move = start' o move Nothing -start' :: MoveOptions -> Bool -> AssociatedFile -> Key -> CommandStart -start' o move afile key = +start' :: MoveOptions -> Bool -> AssociatedFile -> Key -> ActionItem -> CommandStart +start' o move afile key ai = case fromToOptions o of - FromRemote src -> fromStart move afile key =<< getParsed src - ToRemote dest -> toStart move afile key =<< getParsed dest + FromRemote src -> fromStart move afile key ai =<< getParsed src + ToRemote dest -> toStart move afile key ai =<< getParsed dest -showMoveAction :: Bool -> Key -> AssociatedFile -> Annex () +showMoveAction :: Bool -> Key -> ActionItem -> Annex () showMoveAction move = showStart' (if move then "move" else "copy") {- Moves (or copies) the content of an annexed file to a remote. @@ -74,16 +76,16 @@ showMoveAction move = showStart' (if move then "move" else "copy") - A file's content can be moved even if there are insufficient copies to - allow it to be dropped. -} -toStart :: Bool -> AssociatedFile -> Key -> Remote -> CommandStart -toStart move afile key dest = do +toStart :: Bool -> AssociatedFile -> Key -> ActionItem -> Remote -> CommandStart +toStart move afile key ai dest = do u <- getUUID ishere <- inAnnex key if not ishere || u == Remote.uuid dest then stop -- not here, so nothing to do - else toStart' dest move afile key + else toStart' dest move afile key ai -toStart' :: Remote -> Bool -> AssociatedFile -> Key -> CommandStart -toStart' dest move afile key = do +toStart' :: Remote -> Bool -> AssociatedFile -> Key -> ActionItem -> CommandStart +toStart' dest move afile key ai = do fast <- Annex.getState Annex.fast if fast && not move && not (Remote.hasKeyCheap dest) then ifM (expectedPresent dest key) @@ -93,7 +95,7 @@ toStart' dest move afile key = do else go False (Remote.hasKey dest key) where go fastcheck isthere = do - showMoveAction move key afile + showMoveAction move key ai next $ toPerform dest move key afile fastcheck =<< isthere expectedPresent :: Remote -> Key -> Annex Bool @@ -143,13 +145,13 @@ toPerform dest move key afile fastcheck isthere = - If the current repository already has the content, it is still removed - from the remote. -} -fromStart :: Bool -> AssociatedFile -> Key -> Remote -> CommandStart -fromStart move afile key src +fromStart :: Bool -> AssociatedFile -> Key -> ActionItem -> Remote -> CommandStart +fromStart move afile key ai src | move = go | otherwise = stopUnless (not <$> inAnnex key) go where go = stopUnless (fromOk src key) $ do - showMoveAction move key afile + showMoveAction move key ai next $ fromPerform src move key afile fromOk :: Remote -> Key -> Annex Bool diff --git a/Command/SetPresentKey.hs b/Command/SetPresentKey.hs index 73847792d..20c96ae36 100644 --- a/Command/SetPresentKey.hs +++ b/Command/SetPresentKey.hs @@ -23,7 +23,7 @@ seek = withWords start start :: [String] -> CommandStart start (ks:us:vs:[]) = do - showStart' "setpresentkey" k k + showStart' "setpresentkey" k (mkActionItem k) next $ perform k (toUUID us) s where k = fromMaybe (error "bad key") (file2key ks) diff --git a/Command/Sync.hs b/Command/Sync.hs index 4d8cdf2d1..0626d14aa 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -449,8 +449,7 @@ seekSyncContent o rs = do where seekworktree mvar l bloomfeeder = seekHelper LsFiles.inRepo l >>= mapM_ (\f -> ifAnnexed f (go (Right bloomfeeder) mvar (Just f)) noop) - seekkeys mvar bloom getkeys = - mapM_ (go (Left bloom) mvar Nothing) =<< getkeys + seekkeys mvar bloom k _ = go (Left bloom) mvar Nothing k go ebloom mvar af k = commandAction $ do whenM (syncFile ebloom rs af k) $ void $ liftIO $ tryPutMVar mvar () @@ -512,7 +511,7 @@ syncFile ebloom rs af k = do , return [] ) get have = includeCommandAction $ do - showStart' "get" k af + showStart' "get" k (mkActionItem af) next $ next $ getKey' k af have wantput r @@ -527,4 +526,4 @@ syncFile ebloom rs af k = do , return [] ) put dest = includeCommandAction $ - Command.Move.toStart' dest False af k + Command.Move.toStart' dest False af k (mkActionItem af) diff --git a/Command/Whereis.hs b/Command/Whereis.hs index 5b913cf45..b91c31ca1 100644 --- a/Command/Whereis.hs +++ b/Command/Whereis.hs @@ -47,14 +47,13 @@ seek o = do (whereisFiles o) start :: M.Map UUID Remote -> FilePath -> Key -> CommandStart -start remotemap file key = start' remotemap key (Just file) - -startKeys :: M.Map UUID Remote -> Key -> CommandStart -startKeys remotemap key = start' remotemap key Nothing +start remotemap file key = startKeys remotemap key (mkActionItem afile) + where + afile = Just file -start' :: M.Map UUID Remote -> Key -> AssociatedFile -> CommandStart -start' remotemap key afile = do - showStart' "whereis" key afile +startKeys :: M.Map UUID Remote -> Key -> ActionItem -> CommandStart +startKeys remotemap key ai = do + showStart' "whereis" key ai next $ perform remotemap key perform :: M.Map UUID Remote -> Key -> CommandPerform |