refactor
This commit is contained in:
parent
f4ca592cd0
commit
c58d553265
2 changed files with 10 additions and 6 deletions
|
@ -27,7 +27,6 @@ import qualified Types.Remote
|
||||||
import qualified Remote.Git
|
import qualified Remote.Git
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
|
||||||
import qualified Data.Map as M
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Data.Hash.MD5
|
import Data.Hash.MD5
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
|
||||||
where
|
where
|
||||||
pickfast = (++) <$> listed <*> (good =<< fastest <$> available)
|
pickfast = (++) <$> listed <*> (good =<< fastest <$> available)
|
||||||
wanted
|
wanted
|
||||||
| null rs = good =<< concat . byspeed <$> available
|
| null rs = good =<< concat . Remote.byCost <$> available
|
||||||
| otherwise = listed
|
| otherwise = listed
|
||||||
listed = do
|
listed = do
|
||||||
l <- catMaybes <$> mapM (Remote.byName . Just) rs
|
l <- catMaybes <$> mapM (Remote.byName . Just) rs
|
||||||
|
@ -74,10 +73,7 @@ syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
|
||||||
available = filter (not . Remote.specialRemote)
|
available = filter (not . Remote.specialRemote)
|
||||||
<$> Remote.enabledRemoteList
|
<$> Remote.enabledRemoteList
|
||||||
good = filterM $ Remote.Git.repoAvail . Types.Remote.repo
|
good = filterM $ Remote.Git.repoAvail . Types.Remote.repo
|
||||||
fastest = fromMaybe [] . headMaybe . byspeed
|
fastest = fromMaybe [] . headMaybe . Remote.byCost
|
||||||
byspeed = map snd . sort . M.toList . costmap
|
|
||||||
costmap = M.fromListWith (++) . map costpair
|
|
||||||
costpair r = (Types.Remote.cost r, [r])
|
|
||||||
|
|
||||||
commit :: CommandStart
|
commit :: CommandStart
|
||||||
commit = do
|
commit = do
|
||||||
|
|
|
@ -24,6 +24,7 @@ module Remote (
|
||||||
remoteMap,
|
remoteMap,
|
||||||
uuidDescriptions,
|
uuidDescriptions,
|
||||||
byName,
|
byName,
|
||||||
|
byCost,
|
||||||
prettyPrintUUIDs,
|
prettyPrintUUIDs,
|
||||||
prettyListUUIDs,
|
prettyListUUIDs,
|
||||||
remotesWithUUID,
|
remotesWithUUID,
|
||||||
|
@ -224,3 +225,10 @@ forceTrust level remotename = do
|
||||||
- on the remote, but this cannot always be relied on. -}
|
- on the remote, but this cannot always be relied on. -}
|
||||||
logStatus :: Remote -> Key -> LogStatus -> Annex ()
|
logStatus :: Remote -> Key -> LogStatus -> Annex ()
|
||||||
logStatus remote key = logChange key (uuid remote)
|
logStatus remote key = logChange key (uuid remote)
|
||||||
|
|
||||||
|
{- Orders remotes by cost, with ones with the lowest cost grouped together. -}
|
||||||
|
byCost :: [Remote] -> [[Remote]]
|
||||||
|
byCost = map snd . sort . M.toList . costmap
|
||||||
|
where
|
||||||
|
costmap = M.fromListWith (++) . map costpair
|
||||||
|
costpair r = (cost r, [r])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue