summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-18 20:23:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-18 20:23:08 -0400
commit9da23dff78d80158ba01a271ac2a32830fd9bccc (patch)
tree007f7fd05eb844d9e8fd04a172adbd6436e31544
parent1fc3ee24232059ae05ab18ed10bf151f86847ac1 (diff)
--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.)
-rw-r--r--GitAnnex.hs2
-rw-r--r--Limit.hs15
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex.mdwn5
4 files changed, 24 insertions, 0 deletions
diff --git a/GitAnnex.hs b/GitAnnex.hs
index bcb30ff41..a284daad5 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 13df5f6c2..4aeb8bafb 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 0b698bc66..638661f73 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 <joeyh@debian.org> Sun, 18 Sep 2011 18:25:51 -0400
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 03277c6a0..836e782cd 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