A way to match files in repositories in a group

--copies=group:number can now be used to match files that are present in a
specified number of repositories in a group.
This commit is contained in:
Joey Hess 2012-10-01 18:25:11 -04:00
parent 5bd5bc094a
commit eeaa8dada8
3 changed files with 21 additions and 10 deletions

View file

@ -10,6 +10,7 @@ module Limit where
import Text.Regex.PCRE.Light.Char8 import Text.Regex.PCRE.Light.Char8
import System.Path.WildMatch import System.Path.WildMatch
import Data.Time.Clock.POSIX import Data.Time.Clock.POSIX
import qualified Data.Set as S
import Common.Annex import Common.Annex
import qualified Annex import qualified Annex
@ -18,6 +19,7 @@ import qualified Remote
import qualified Backend import qualified Backend
import Annex.Content import Annex.Content
import Logs.Trust import Logs.Trust
import Logs.Group
import Utility.HumanTime import Utility.HumanTime
type Limit = Utility.Matcher.Token (FilePath -> Annex Bool) type Limit = Utility.Matcher.Token (FilePath -> Annex Bool)
@ -86,21 +88,22 @@ addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
{- Adds a limit to skip files not believed to have the specified number {- Adds a limit to skip files not believed to have the specified number
- of copies. -} - of copies. -}
addCopies :: String -> Annex () addCopies :: String -> Annex ()
addCopies trust_num = addLimit . check $ readnum num addCopies want = addLimit . check $ readnum num
where where
(num, mayCheckTrust) = case split ":" trust_num of (num, good) = case split ":" want of
[trust, num'] -> (num', checkTrust (readtrust trust)) [v, n] -> case readTrust v of
[num'] -> (num', const (return True)) Just trust -> (n, checktrust trust)
_ -> bad Nothing -> (n, checkgroup v)
readnum = maybe bad id . readish [n] -> (n, const $ return True)
readtrust = maybe bad id . readTrust _ -> error "bad value for --copies"
readnum = maybe (error "bad number for --copies") id . readish
check n = Backend.lookupFile >=> handle n check n = Backend.lookupFile >=> handle n
handle _ Nothing = return False handle _ Nothing = return False
handle n (Just (key, _)) = do handle n (Just (key, _)) = do
us <- filterM mayCheckTrust =<< Remote.keyLocations key us <- filterM good =<< Remote.keyLocations key
return $ length us >= n return $ length us >= n
checkTrust t u = (== t) <$> lookupTrust u checktrust t u = (== t) <$> lookupTrust u
bad = error "bad number or trust:number for --copies" checkgroup g u = S.member g <$> lookupGroups u
{- Adds a limit to skip files not using a specified key-value backend. -} {- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex () addInBackend :: String -> Annex ()

2
debian/changelog vendored
View file

@ -1,6 +1,8 @@
git-annex (3.20121002) UNRELEASED; urgency=low git-annex (3.20121002) UNRELEASED; urgency=low
* group, ungroup: New commands to indicate groups of repositories. * group, ungroup: New commands to indicate groups of repositories.
* --copies=group:number can now be used to match files that are present
in a specified number of repositories in a group.
-- Joey Hess <joeyh@debian.org> Mon, 01 Oct 2012 15:09:49 -0400 -- Joey Hess <joeyh@debian.org> Mon, 01 Oct 2012 15:09:49 -0400

View file

@ -625,6 +625,12 @@ file contents are present at either of two repositories.
copies, on remotes with the specified trust level. For example, copies, on remotes with the specified trust level. For example,
"--copies=trusted:2" "--copies=trusted:2"
* --copies=groupname:number
Matches only files that git-annex believes have the specified number of
copies, on remotes in the specified group. For example,
"--copies=archival:2"
* --inbackend=name * --inbackend=name
Matches only files whose content is stored using the specified key-value Matches only files whose content is stored using the specified key-value