Added annex-cost-command configuration, which can be used to vary the cost of a remote based on the output of a shell command.
Also avoided crashing if the user specified cost value cannot be parsed.
This commit is contained in:
parent
0c53ccc675
commit
8a2197adfa
3 changed files with 24 additions and 5 deletions
21
Config.hs
21
Config.hs
|
@ -9,6 +9,8 @@ module Config where
|
||||||
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Control.Monad.State (liftIO)
|
import Control.Monad.State (liftIO)
|
||||||
|
import Control.Monad (liftM)
|
||||||
|
import System.Cmd.Utils
|
||||||
|
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
@ -40,14 +42,23 @@ remoteConfig r key = "remote." ++ fromMaybe "" (Git.repoRemoteName r) ++ ".annex
|
||||||
{- Calculates cost for a remote.
|
{- Calculates cost for a remote.
|
||||||
-
|
-
|
||||||
- The default cost is 100 for local repositories, and 200 for remote
|
- The default cost is 100 for local repositories, and 200 for remote
|
||||||
- repositories; it can also be configured by remote.<name>.annex-cost
|
- repositories; it can also be configured by remote.<name>.annex-cost,
|
||||||
|
- or if remote.<name>.annex-cost-command is set and prints a number, that
|
||||||
|
- is used.
|
||||||
-}
|
-}
|
||||||
remoteCost :: Git.Repo -> Int -> Annex Int
|
remoteCost :: Git.Repo -> Int -> Annex Int
|
||||||
remoteCost r def = do
|
remoteCost r def = do
|
||||||
c <- getConfig r "cost" ""
|
cmd <- getConfig r "cost-command" ""
|
||||||
if not $ null c
|
return . safeparse =<< if not $ null cmd
|
||||||
then return $ read c
|
then liftM snd $ liftIO $ pipeFrom "sh" ["-c", cmd]
|
||||||
else return def
|
else getConfig r "cost" ""
|
||||||
|
where
|
||||||
|
safeparse v
|
||||||
|
| null ws || null ps = def
|
||||||
|
| otherwise = (fst . head) ps
|
||||||
|
where
|
||||||
|
ws = words v
|
||||||
|
ps = reads $ head ws
|
||||||
|
|
||||||
cheapRemoteCost :: Int
|
cheapRemoteCost :: Int
|
||||||
cheapRemoteCost = 100
|
cheapRemoteCost = 100
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -4,6 +4,8 @@ git-annex (3.20110818) UNRELEASED; urgency=low
|
||||||
is first being created. Clones will automatically notice that git-annex
|
is first being created. Clones will automatically notice that git-annex
|
||||||
is in use and automatically perform a basic initalization. It's
|
is in use and automatically perform a basic initalization. It's
|
||||||
still recommended to run "git annex init" in any clones, to describe them.
|
still recommended to run "git annex init" in any clones, to describe them.
|
||||||
|
* Added annex-cost-command configuration, which can be used to vary the
|
||||||
|
cost of a remote based on the output of a shell command.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Wed, 17 Aug 2011 13:44:44 -0400
|
-- Joey Hess <joeyh@debian.org> Wed, 17 Aug 2011 13:44:44 -0400
|
||||||
|
|
||||||
|
|
|
@ -424,6 +424,12 @@ Here are all the supported configuration settings.
|
||||||
The default cost is 100 for local repositories, and 200 for remote
|
The default cost is 100 for local repositories, and 200 for remote
|
||||||
repositories.
|
repositories.
|
||||||
|
|
||||||
|
* `remote.<name>.annex-cost-command`
|
||||||
|
|
||||||
|
If set, the command is run, and the number it outputs is used as the cost.
|
||||||
|
This allows varying the cost based on eg, the current network. The
|
||||||
|
cost-command can be any shell command line.
|
||||||
|
|
||||||
* `remote.<name>.annex-ignore`
|
* `remote.<name>.annex-ignore`
|
||||||
|
|
||||||
If set to `true`, prevents git-annex
|
If set to `true`, prevents git-annex
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue