diff --git a/GitAnnex.hs b/GitAnnex.hs index bcb30ff41f..a284daad5c 100644 --- a/GitAnnex.hs +++ b/GitAnnex.hs @@ -112,6 +112,8 @@ options = commonOptions ++ "skip files matching the glob pattern" , Option ['i'] ["in"] (ReqArg (Limit.addIn) paramRemote) "skip files not present in a remote" + , Option ['C'] ["copies"] (ReqArg (Limit.addCopies) paramNumber) + "skip files with fewer copies" ] ++ matcherOptions where setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v } diff --git a/Limit.hs b/Limit.hs index 13df5f6c27..4aeb8bafb4 100644 --- a/Limit.hs +++ b/Limit.hs @@ -17,6 +17,7 @@ import qualified Utility.Matcher import qualified Remote import qualified Backend import LocationLog +import Utility type Limit = Utility.Matcher.Token (FilePath -> Annex Bool) @@ -73,3 +74,17 @@ addIn name = do handle u (Just (key, _)) = do us <- keyLocations key return $ u `elem` us + +{- Adds a limit to skip files not believed to have the specified number + - of copies. -} +addCopies :: String -> Annex () +addCopies num = do + case readMaybe num :: Maybe Int of + Nothing -> error "bad number for --copies" + Just n -> addlimit $ check n + where + check n f = Backend.lookupFile f >>= handle n + handle _ Nothing = return False + handle n (Just (key, _)) = do + us <- keyLocations key + return $ length us >= n diff --git a/debian/changelog b/debian/changelog index 0b698bc66f..638661f735 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ git-annex (3.20110916) UNRELEASED; urgency=low * Arbitrarily complex expressions can be built to limit the files git-annex operates on, by combining the options --not --and --or -( and -) Example: git annex get --exclude '*.mp3' --and --not -( --in usbdrive --or --in archive -) + * --copies=N can be used to make git-annex only operate on files with + the specified number of copies. (And --not --copies=N for the inverse.) -- Joey Hess Sun, 18 Sep 2011 18:25:51 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 03277c6a0e..836e782cde 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -434,6 +434,11 @@ file contents are present at either of two repositories. The repository should be specified using the name of a configured remote, or the UUID or description of a repository. +* --copies=number + + Matches only files that git-annex believes to have the specified number + of copies. + * --not Inverts the next file matching option. For example, to only act on