summaryrefslogtreecommitdiff
path: root/Limit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-21 18:46:39 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-21 18:49:25 -0400
commit7c3f0eae77b07ccc65c4e30d9eb1288781bd0c02 (patch)
treeaf6b86482c4f67f710349677a48917ac29fa404f /Limit.hs
parentd71baf07108c4903c444175ca482af1ed4cca1b4 (diff)
benchmarked numcopies .gitattributes in preferred content
Checking .gitattributes adds a full minute to a git annex find looking for files that don't have enough copies. 2:25 increasts to 3:27. I feel this is too much of a slowdown to justify making it the default. So, exposed two versions of the preferred content expression, a slow one and a fast but approximate one. I'm using the approximate one in the default preferred content expressions to avoid slowing down the assistant.
Diffstat (limited to 'Limit.hs')
-rw-r--r--Limit.hs41
1 files changed, 19 insertions, 22 deletions
diff --git a/Limit.hs b/Limit.hs
index 471a0c278..6ce444325 100644
--- a/Limit.hs
+++ b/Limit.hs
@@ -178,29 +178,26 @@ limitCopies want = case split ":" want of
| "+" `isSuffixOf` s = (>=) <$> readTrustLevel (beginning s)
| otherwise = (==) <$> readTrustLevel s
-{- Adds a limit to match files that need more copies made.
- -
- - Does not look at annex.numcopies .gitattributes, because that
- - would require querying git check-attr every time a preferred content
- - expression is checked, which would probably be quite slow.
- -}
-addNumCopiesNeeded :: String -> Annex ()
-addNumCopiesNeeded = addLimit . limitNumCopiesNeeded
-
-limitNumCopiesNeeded :: MkLimit
-limitNumCopiesNeeded want = case readish want of
- Just needed -> Right $ \notpresent -> checkKey $
- handle needed notpresent
- Nothing -> Left "bad value for numcopiesneeded"
+{- Adds a limit to match files that need more copies made. -}
+addLackingCopies :: Bool -> String -> Annex ()
+addLackingCopies approx = addLimit . limitLackingCopies approx
+
+limitLackingCopies :: Bool -> MkLimit
+limitLackingCopies approx want = case readish want of
+ Just needed -> Right $ \notpresent mi -> flip checkKey mi $
+ handle mi needed notpresent
+ Nothing -> Left "bad value for number of lacking copies"
where
- handle needed notpresent key = do
- gv <- getGlobalNumCopies
- case gv of
- Nothing -> return False
- Just (NumCopies numcopies) -> do
- us <- filter (`S.notMember` notpresent)
- <$> (trustExclude UnTrusted =<< Remote.keyLocations key)
- return $ numcopies - length us >= needed
+ handle mi needed notpresent key = do
+ NumCopies numcopies <- if approx
+ then approxNumCopies
+ else case mi of
+ MatchingKey _ -> approxNumCopies
+ MatchingFile fi -> getGlobalFileNumCopies $ matchFile fi
+ us <- filter (`S.notMember` notpresent)
+ <$> (trustExclude UnTrusted =<< Remote.keyLocations key)
+ return $ numcopies - length us >= needed
+ approxNumCopies = fromMaybe defaultNumCopies <$> getGlobalNumCopies
{- Adds a limit to skip files not believed to be present in all
- repositories in the specified group. -}