summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-18 12:20:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-18 12:20:47 -0400
commit8a2197adfab9d8425f92000621a802dce37e124c (patch)
treee305ea8d7ac9f88ef827902eecea805a867d603d
parent0c53ccc675b52d4995b3406d5814116605fe6ec7 (diff)
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.
-rw-r--r--Config.hs21
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex.mdwn6
3 files changed, 24 insertions, 5 deletions
diff --git a/Config.hs b/Config.hs
index 9cbf2d52f..6f2014483 100644
--- a/Config.hs
+++ b/Config.hs
@@ -9,6 +9,8 @@ module Config where
import Data.Maybe
import Control.Monad.State (liftIO)
+import Control.Monad (liftM)
+import System.Cmd.Utils
import qualified Git
import qualified Annex
@@ -40,14 +42,23 @@ remoteConfig r key = "remote." ++ fromMaybe "" (Git.repoRemoteName r) ++ ".annex
{- Calculates cost for a 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 r def = do
- c <- getConfig r "cost" ""
- if not $ null c
- then return $ read c
- else return def
+ cmd <- getConfig r "cost-command" ""
+ return . safeparse =<< if not $ null cmd
+ then liftM snd $ liftIO $ pipeFrom "sh" ["-c", cmd]
+ 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 = 100
diff --git a/debian/changelog b/debian/changelog
index 9230c0021..1ace861a4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ git-annex (3.20110818) UNRELEASED; urgency=low
is first being created. Clones will automatically notice that git-annex
is in use and automatically perform a basic initalization. It's
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
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 9d63ca156..a262d465f 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -424,6 +424,12 @@ Here are all the supported configuration settings.
The default cost is 100 for local repositories, and 200 for remote
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`
If set to `true`, prevents git-annex