aboutsummaryrefslogtreecommitdiff
path: root/Config.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-13 16:16:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-13 16:30:34 -0400
commit571cd1c57aeb4e8071b30caf529a0845e8ddc7cf (patch)
treee895c99334d675cec3f7996cb6c298fb7751b33b /Config.hs
parent89cc1d2a38a1abaaecdfb7766739f3c2b5dbf963 (diff)
split cost out into its own module
Added a function to insert a new cost into a list, which could be used to asjust costs after a drag and drop.
Diffstat (limited to 'Config.hs')
-rw-r--r--Config.hs32
1 files changed, 3 insertions, 29 deletions
diff --git a/Config.hs b/Config.hs
index b732f982f..4d93a2af5 100644
--- a/Config.hs
+++ b/Config.hs
@@ -13,6 +13,7 @@ import qualified Git.Config
import qualified Git.Command
import qualified Annex
import qualified Types.Remote as Remote
+import Config.Cost
type UnqualifiedConfigKey = String
data ConfigKey = ConfigKey String
@@ -44,43 +45,16 @@ annexConfig key = ConfigKey $ "annex." ++ key
{- Calculates cost for a remote. Either the specific default, or as configured
- by remote.<name>.annex-cost, or if remote.<name>.annex-cost-command
- is set and prints a number, that is used. -}
-remoteCost :: RemoteGitConfig -> Int -> Annex Int
+remoteCost :: RemoteGitConfig -> Cost -> Annex Cost
remoteCost c def = case remoteAnnexCostCommand c of
Just cmd | not (null cmd) -> liftIO $
(fromMaybe def . readish) <$>
readProcess "sh" ["-c", cmd]
_ -> return $ fromMaybe def $ remoteAnnexCost c
-setRemoteCost :: Remote -> Int -> Annex ()
+setRemoteCost :: Remote -> Cost -> Annex ()
setRemoteCost r c = setConfig (remoteConfig (Remote.repo r) "cost") (show c)
-cheapRemoteCost :: Int
-cheapRemoteCost = 100
-semiCheapRemoteCost :: Int
-semiCheapRemoteCost = 110
-semiExpensiveRemoteCost :: Int
-semiExpensiveRemoteCost = 175
-expensiveRemoteCost :: Int
-expensiveRemoteCost = 200
-veryExpensiveRemoteCost :: Int
-veryExpensiveRemoteCost = 1000
-
-{- Adjusts a remote's cost to reflect it being encrypted. -}
-encryptedRemoteCostAdj :: Int
-encryptedRemoteCostAdj = 50
-
-{- Make sure the remote cost numbers work out. -}
-prop_cost_sane :: Bool
-prop_cost_sane = False `notElem`
- [ expensiveRemoteCost > 0
- , cheapRemoteCost < semiCheapRemoteCost
- , semiCheapRemoteCost < semiExpensiveRemoteCost
- , semiExpensiveRemoteCost < expensiveRemoteCost
- , cheapRemoteCost + encryptedRemoteCostAdj > semiCheapRemoteCost
- , cheapRemoteCost + encryptedRemoteCostAdj < semiExpensiveRemoteCost
- , semiCheapRemoteCost + encryptedRemoteCostAdj < expensiveRemoteCost
- ]
-
getNumCopies :: Maybe Int -> Annex Int
getNumCopies (Just v) = return v
getNumCopies Nothing = annexNumCopies <$> Annex.getGitConfig