summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-01 16:49:17 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-01 16:49:17 -0400
commit3d567aa64f263c6ee55c92e8b962087de063ebc8 (patch)
treeb900a87442363b33fd0fe9cba42923313f283676
parent12e0e95916b81352b6f0dfdf95d3e623d4a12738 (diff)
Add --numcopies option.
-rw-r--r--Annex.hs2
-rw-r--r--Backend/File.hs12
-rw-r--r--GitAnnex.hs12
-rw-r--r--debian/changelog6
-rw-r--r--doc/forum/new_microfeatures.mdwn3
-rw-r--r--doc/git-annex.mdwn5
6 files changed, 32 insertions, 8 deletions
diff --git a/Annex.hs b/Annex.hs
index 2148dd625..c5a098d98 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -39,6 +39,7 @@ data AnnexState = AnnexState
, force :: Bool
, fast :: Bool
, forcebackend :: Maybe String
+ , forcenumcopies :: Maybe Int
, defaultkey :: Maybe String
, toremote :: Maybe String
, fromremote :: Maybe String
@@ -57,6 +58,7 @@ newState gitrepo allbackends = AnnexState
, force = False
, fast = False
, forcebackend = Nothing
+ , forcenumcopies = Nothing
, defaultkey = Nothing
, toremote = Nothing
, fromremote = Nothing
diff --git a/Backend/File.hs b/Backend/File.hs
index b86413e40..543f02af7 100644
--- a/Backend/File.hs
+++ b/Backend/File.hs
@@ -152,12 +152,16 @@ showTriedRemotes remotes =
showLongNote $ "Unable to access these remotes: " ++
(join ", " $ map Remote.name remotes)
+{- If a value is specified, it is used; otherwise the default is looked up
+ - in git config. forcenumcopies overrides everything. -}
getNumCopies :: Maybe Int -> Annex Int
-getNumCopies (Just n) = return n
-getNumCopies Nothing = do
- g <- Annex.gitRepo
- return $ read $ Git.configGet g config "1"
+getNumCopies v =
+ Annex.getState Annex.forcenumcopies >>= maybe (use v) (return . id)
where
+ use (Just n) = return n
+ use Nothing = do
+ g <- Annex.gitRepo
+ return $ read $ Git.configGet g config "1"
config = "annex.numcopies"
{- Ideally, all keys have file size metadata. Old keys may not. -}
diff --git a/GitAnnex.hs b/GitAnnex.hs
index 99aec187a..37a73424a 100644
--- a/GitAnnex.hs
+++ b/GitAnnex.hs
@@ -13,6 +13,7 @@ import qualified GitRepo as Git
import CmdLine
import Command
import Options
+import Utility
import qualified Annex
import qualified Command.Add
@@ -82,20 +83,23 @@ cmds = concat
options :: [Option]
options = commonOptions ++
- [ Option ['k'] ["key"] (ReqArg setkey paramKey)
- "specify a key to use"
- , Option ['t'] ["to"] (ReqArg setto paramRemote)
+ [ Option ['t'] ["to"] (ReqArg setto paramRemote)
"specify to where to transfer content"
, Option ['f'] ["from"] (ReqArg setfrom paramRemote)
"specify from where to transfer content"
, Option ['x'] ["exclude"] (ReqArg addexclude paramGlob)
"skip files matching the glob pattern"
+ , Option ['N'] ["numcopies"] (ReqArg setnumcopies paramNumber)
+ "override default number of copies"
+ , Option ['k'] ["key"] (ReqArg setkey paramKey)
+ "specify a key to use"
]
where
- setkey v = Annex.changeState $ \s -> s { Annex.defaultkey = Just v }
setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v }
setfrom v = Annex.changeState $ \s -> s { Annex.fromremote = Just v }
addexclude v = Annex.changeState $ \s -> s { Annex.exclude = v:(Annex.exclude s) }
+ setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readMaybe v }
+ setkey v = Annex.changeState $ \s -> s { Annex.defaultkey = Just v }
header :: String
header = "Usage: git-annex command [option ..]"
diff --git a/debian/changelog b/debian/changelog
index 5e10b3d26..0d531a320 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+git-annex (0.20110602) UNRELEASED; urgency=low
+
+ * Add --numcopies option.
+
+ -- Joey Hess <joeyh@debian.org> Wed, 01 Jun 2011 16:26:48 -0400
+
git-annex (0.20110601) unstable; urgency=low
* Minor bugfixes and error message improvements.
diff --git a/doc/forum/new_microfeatures.mdwn b/doc/forum/new_microfeatures.mdwn
index 4b4389e3d..fe91addca 100644
--- a/doc/forum/new_microfeatures.mdwn
+++ b/doc/forum/new_microfeatures.mdwn
@@ -5,6 +5,9 @@ Here are a few I've been considering:
---
* --numcopies would be a useful command line switch.
+ > Update: Added. Also allows for things like `git annex drop
+ > --numcopies=2` when in a repo that normally needs 3 copies, if you need
+ > to urgently free up space.
* A way to make `drop` and other commands temporarily trust a given remote, or possibly all remotes.
Combined, this would allow `git annex drop --numcopies=2 --trust=repoa --trust=repob` to remove files that have been replicated out to the other 2 repositories, which could be offline. (Slightly unsafe, but in this case the files are podcasts so not really.)
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 7f2fce9d2..e4924d373 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -354,6 +354,11 @@ Many git-annex commands will stage changes for later `git commit` by you.
This option can be specified multiple times.
+* --numcopies=n
+
+ Overrides the `annex.numcopies` setting, forcing git-annex to ensure the
+ specified number of copies exist.
+
* --backend=name
Specifies which key-value backend to use. This can be used when