summaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-13 14:40:56 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-13 14:40:56 -0400
commit771a6b36e1527571b9a38baacbee6e864f44172a (patch)
tree7801037facceb6b602533be8efc104a6ff6091ec /Annex.hs
parent794d44cf1daf073f05d1a27b2a02c47db37c443a (diff)
cost ordering
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/Annex.hs b/Annex.hs
index 012e90199..bd57514ea 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -9,12 +9,14 @@ module Annex (
annexWantFile,
annexDropFile,
annexPushRepo,
+ repoCost,
annexPullRepo
) where
import System.Posix.Files
import System.Directory
import Data.String.Utils
+import List
import GitRepo
import Utility
import Locations
@@ -165,3 +167,26 @@ logStatus state key status = do
{- Checks if a given key is currently present in the annexLocation -}
inAnnex :: State -> Backend -> Key -> IO Bool
inAnnex state backend key = doesFileExist $ annexLocation state backend key
+
+{- Orders a list of git repos by cost. -}
+reposByCost :: State -> [GitRepo] -> [GitRepo]
+reposByCost state l =
+ fst $ unzip $ sortBy (\(r1, c1) (r2, c2) -> compare c1 c2) $ costpairs l
+ where
+ costpairs l = map (\r -> (r, repoCost state r)) l
+
+{- Calculates cost for a repo.
+ -
+ - The default cost is 100 for local repositories, and 200 for remote
+ - repositories; it can also be configured by remote.<name>.annex-cost
+ -}
+repoCost :: State -> GitRepo -> Int
+repoCost state r =
+ if ((length $ config state r) > 0)
+ then read $ config state r
+ else if (gitRepoIsLocal r)
+ then 100
+ else 200
+ where
+ config state r = gitConfig (repo state) (configkey r) ""
+ configkey r = "remote." ++ (gitRepoRemoteName r) ++ ".annex-cost"