Add --numcopies option.

This commit is contained in:
Joey Hess 2011-06-01 16:49:17 -04:00
parent 12e0e95916
commit 3d567aa64f
6 changed files with 32 additions and 8 deletions

View file

@ -39,6 +39,7 @@ data AnnexState = AnnexState
, force :: Bool , force :: Bool
, fast :: Bool , fast :: Bool
, forcebackend :: Maybe String , forcebackend :: Maybe String
, forcenumcopies :: Maybe Int
, defaultkey :: Maybe String , defaultkey :: Maybe String
, toremote :: Maybe String , toremote :: Maybe String
, fromremote :: Maybe String , fromremote :: Maybe String
@ -57,6 +58,7 @@ newState gitrepo allbackends = AnnexState
, force = False , force = False
, fast = False , fast = False
, forcebackend = Nothing , forcebackend = Nothing
, forcenumcopies = Nothing
, defaultkey = Nothing , defaultkey = Nothing
, toremote = Nothing , toremote = Nothing
, fromremote = Nothing , fromremote = Nothing

View file

@ -152,12 +152,16 @@ showTriedRemotes remotes =
showLongNote $ "Unable to access these remotes: " ++ showLongNote $ "Unable to access these remotes: " ++
(join ", " $ map Remote.name 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 :: Maybe Int -> Annex Int
getNumCopies (Just n) = return n getNumCopies v =
getNumCopies Nothing = do Annex.getState Annex.forcenumcopies >>= maybe (use v) (return . id)
g <- Annex.gitRepo
return $ read $ Git.configGet g config "1"
where where
use (Just n) = return n
use Nothing = do
g <- Annex.gitRepo
return $ read $ Git.configGet g config "1"
config = "annex.numcopies" config = "annex.numcopies"
{- Ideally, all keys have file size metadata. Old keys may not. -} {- Ideally, all keys have file size metadata. Old keys may not. -}

View file

@ -13,6 +13,7 @@ import qualified GitRepo as Git
import CmdLine import CmdLine
import Command import Command
import Options import Options
import Utility
import qualified Annex import qualified Annex
import qualified Command.Add import qualified Command.Add
@ -82,20 +83,23 @@ cmds = concat
options :: [Option] options :: [Option]
options = commonOptions ++ options = commonOptions ++
[ Option ['k'] ["key"] (ReqArg setkey paramKey) [ Option ['t'] ["to"] (ReqArg setto paramRemote)
"specify a key to use"
, Option ['t'] ["to"] (ReqArg setto paramRemote)
"specify to where to transfer content" "specify to where to transfer content"
, Option ['f'] ["from"] (ReqArg setfrom paramRemote) , Option ['f'] ["from"] (ReqArg setfrom paramRemote)
"specify from where to transfer content" "specify from where to transfer content"
, Option ['x'] ["exclude"] (ReqArg addexclude paramGlob) , Option ['x'] ["exclude"] (ReqArg addexclude paramGlob)
"skip files matching the glob pattern" "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 where
setkey v = Annex.changeState $ \s -> s { Annex.defaultkey = Just v }
setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v } setto v = Annex.changeState $ \s -> s { Annex.toremote = Just v }
setfrom v = Annex.changeState $ \s -> s { Annex.fromremote = Just v } setfrom v = Annex.changeState $ \s -> s { Annex.fromremote = Just v }
addexclude v = Annex.changeState $ \s -> s { Annex.exclude = v:(Annex.exclude s) } 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 :: String
header = "Usage: git-annex command [option ..]" header = "Usage: git-annex command [option ..]"

6
debian/changelog vendored
View file

@ -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 git-annex (0.20110601) unstable; urgency=low
* Minor bugfixes and error message improvements. * Minor bugfixes and error message improvements.

View file

@ -5,6 +5,9 @@ Here are a few I've been considering:
--- ---
* --numcopies would be a useful command line switch. * --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. * 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.) 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.)

View file

@ -354,6 +354,11 @@ Many git-annex commands will stage changes for later `git commit` by you.
This option can be specified multiple times. 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 * --backend=name
Specifies which key-value backend to use. This can be used when Specifies which key-value backend to use. This can be used when