vicfg: Include the numcopies configuation.
Docs say vicfg can configure everything from git-annex branch, so it ought to configure numcopies. Note that commenting out existing numcopies does not unset it. This commit was sponsored by Thom May on Patreon.
This commit is contained in:
parent
67ffb8bada
commit
26d23e38f1
5 changed files with 39 additions and 8 deletions
|
@ -5,6 +5,7 @@ git-annex (6.20170102) UNRELEASED; urgency=medium
|
||||||
remotes when possible.
|
remotes when possible.
|
||||||
* Remove -j short option for --json-progress; that option was already
|
* Remove -j short option for --json-progress; that option was already
|
||||||
taken for --json.
|
taken for --json.
|
||||||
|
* vicfg: Include the numcopies configuation.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Fri, 06 Jan 2017 15:22:06 -0400
|
-- Joey Hess <id@joeyh.name> Fri, 06 Jan 2017 15:22:06 -0400
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex command
|
{- git-annex command
|
||||||
-
|
-
|
||||||
- Copyright 2012-2014 Joey Hess <id@joeyh.name>
|
- Copyright 2012-2017 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -24,12 +24,14 @@ import Logs.Trust
|
||||||
import Logs.Group
|
import Logs.Group
|
||||||
import Logs.PreferredContent
|
import Logs.PreferredContent
|
||||||
import Logs.Schedule
|
import Logs.Schedule
|
||||||
|
import Logs.NumCopies
|
||||||
import Types.StandardGroups
|
import Types.StandardGroups
|
||||||
import Types.ScheduledActivity
|
import Types.ScheduledActivity
|
||||||
|
import Types.NumCopies
|
||||||
import Remote
|
import Remote
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = command "vicfg" SectionSetup "edit git-annex's configuration"
|
cmd = command "vicfg" SectionSetup "edit configuration in git-annex branch"
|
||||||
paramNothing (withParams seek)
|
paramNothing (withParams seek)
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
seek :: CmdParams -> CommandSeek
|
||||||
|
@ -66,6 +68,7 @@ data Cfg = Cfg
|
||||||
, cfgRequiredContentMap :: M.Map UUID PreferredContentExpression
|
, cfgRequiredContentMap :: M.Map UUID PreferredContentExpression
|
||||||
, cfgGroupPreferredContentMap :: M.Map Group PreferredContentExpression
|
, cfgGroupPreferredContentMap :: M.Map Group PreferredContentExpression
|
||||||
, cfgScheduleMap :: M.Map UUID [ScheduledActivity]
|
, cfgScheduleMap :: M.Map UUID [ScheduledActivity]
|
||||||
|
, cfgNumCopies :: Maybe NumCopies
|
||||||
}
|
}
|
||||||
|
|
||||||
getCfg :: Annex Cfg
|
getCfg :: Annex Cfg
|
||||||
|
@ -76,6 +79,7 @@ getCfg = Cfg
|
||||||
<*> requiredContentMapRaw
|
<*> requiredContentMapRaw
|
||||||
<*> groupPreferredContentMapRaw
|
<*> groupPreferredContentMapRaw
|
||||||
<*> scheduleMap
|
<*> scheduleMap
|
||||||
|
<*> getGlobalNumCopies
|
||||||
|
|
||||||
setCfg :: Cfg -> Cfg -> Annex ()
|
setCfg :: Cfg -> Cfg -> Annex ()
|
||||||
setCfg curcfg newcfg = do
|
setCfg curcfg newcfg = do
|
||||||
|
@ -86,6 +90,7 @@ setCfg curcfg newcfg = do
|
||||||
mapM_ (uncurry requiredContentSet) $ M.toList $ cfgRequiredContentMap diff
|
mapM_ (uncurry requiredContentSet) $ M.toList $ cfgRequiredContentMap diff
|
||||||
mapM_ (uncurry groupPreferredContentSet) $ M.toList $ cfgGroupPreferredContentMap diff
|
mapM_ (uncurry groupPreferredContentSet) $ M.toList $ cfgGroupPreferredContentMap diff
|
||||||
mapM_ (uncurry scheduleSet) $ M.toList $ cfgScheduleMap diff
|
mapM_ (uncurry scheduleSet) $ M.toList $ cfgScheduleMap diff
|
||||||
|
maybe noop setGlobalNumCopies $ cfgNumCopies diff
|
||||||
|
|
||||||
{- Default config has all the keys from the input config, but with their
|
{- Default config has all the keys from the input config, but with their
|
||||||
- default values. -}
|
- default values. -}
|
||||||
|
@ -97,6 +102,7 @@ defCfg curcfg = Cfg
|
||||||
, cfgRequiredContentMap = mapdef $ cfgRequiredContentMap curcfg
|
, cfgRequiredContentMap = mapdef $ cfgRequiredContentMap curcfg
|
||||||
, cfgGroupPreferredContentMap = mapdef $ cfgGroupPreferredContentMap curcfg
|
, cfgGroupPreferredContentMap = mapdef $ cfgGroupPreferredContentMap curcfg
|
||||||
, cfgScheduleMap = mapdef $ cfgScheduleMap curcfg
|
, cfgScheduleMap = mapdef $ cfgScheduleMap curcfg
|
||||||
|
, cfgNumCopies = Nothing
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
mapdef :: forall k v. Default v => M.Map k v -> M.Map k v
|
mapdef :: forall k v. Default v => M.Map k v -> M.Map k v
|
||||||
|
@ -110,6 +116,7 @@ diffCfg curcfg newcfg = Cfg
|
||||||
, cfgRequiredContentMap = diff cfgRequiredContentMap
|
, cfgRequiredContentMap = diff cfgRequiredContentMap
|
||||||
, cfgGroupPreferredContentMap = diff cfgGroupPreferredContentMap
|
, cfgGroupPreferredContentMap = diff cfgGroupPreferredContentMap
|
||||||
, cfgScheduleMap = diff cfgScheduleMap
|
, cfgScheduleMap = diff cfgScheduleMap
|
||||||
|
, cfgNumCopies = cfgNumCopies newcfg
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x)
|
diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x)
|
||||||
|
@ -125,6 +132,7 @@ genCfg cfg descs = unlines $ intercalate [""]
|
||||||
, standardgroups
|
, standardgroups
|
||||||
, requiredcontent
|
, requiredcontent
|
||||||
, schedule
|
, schedule
|
||||||
|
, others
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
intro =
|
intro =
|
||||||
|
@ -202,6 +210,14 @@ genCfg cfg descs = unlines $ intercalate [""]
|
||||||
, unwords [setting, fromUUID u, "=", val]
|
, unwords [setting, fromUUID u, "=", val]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
line' setting Nothing = com $ unwords [setting, "default", "="]
|
||||||
|
line' setting (Just val) = unwords [setting, "default", "=", val]
|
||||||
|
|
||||||
|
others =
|
||||||
|
[ com "Other configuration"
|
||||||
|
, line' "numcopies" (show . fromNumCopies <$> cfgNumCopies cfg)
|
||||||
|
]
|
||||||
|
|
||||||
settings :: Ord v => Cfg -> M.Map UUID String -> (Cfg -> M.Map UUID v) -> [String] -> ((v, UUID) -> [String]) -> (UUID -> [String]) -> [String]
|
settings :: Ord v => Cfg -> M.Map UUID String -> (Cfg -> M.Map UUID v) -> [String] -> ((v, UUID) -> [String]) -> (UUID -> [String]) -> [String]
|
||||||
settings cfg descs = settings' cfg (M.keysSet descs)
|
settings cfg descs = settings' cfg (M.keysSet descs)
|
||||||
|
|
||||||
|
@ -274,6 +290,9 @@ parseCfg defcfg = go [] defcfg . lines
|
||||||
Right l ->
|
Right l ->
|
||||||
let m = M.insert u l (cfgScheduleMap cfg)
|
let m = M.insert u l (cfgScheduleMap cfg)
|
||||||
in Right $ cfg { cfgScheduleMap = m }
|
in Right $ cfg { cfgScheduleMap = m }
|
||||||
|
| setting == "numcopies" = case readish val of
|
||||||
|
Nothing -> Left "parse error (expected an integer)"
|
||||||
|
Just n -> Right $ cfg { cfgNumCopies = Just (NumCopies n) }
|
||||||
| otherwise = badval "setting" setting
|
| otherwise = badval "setting" setting
|
||||||
where
|
where
|
||||||
u = toUUID f
|
u = toUUID f
|
||||||
|
|
|
@ -24,7 +24,10 @@ instance SingleValueSerializable NumCopies where
|
||||||
deserialize = NumCopies <$$> readish
|
deserialize = NumCopies <$$> readish
|
||||||
|
|
||||||
setGlobalNumCopies :: NumCopies -> Annex ()
|
setGlobalNumCopies :: NumCopies -> Annex ()
|
||||||
setGlobalNumCopies = setLog numcopiesLog
|
setGlobalNumCopies new = do
|
||||||
|
curr <- getGlobalNumCopies
|
||||||
|
when (curr /= Just new) $
|
||||||
|
setLog numcopiesLog new
|
||||||
|
|
||||||
{- Value configured in the numcopies log. Cached for speed. -}
|
{- Value configured in the numcopies log. Cached for speed. -}
|
||||||
getGlobalNumCopies :: Annex (Maybe NumCopies)
|
getGlobalNumCopies :: Annex (Maybe NumCopies)
|
||||||
|
|
|
@ -13,6 +13,9 @@ repositories. The default is 1.
|
||||||
|
|
||||||
Run without a number to get the current value.
|
Run without a number to get the current value.
|
||||||
|
|
||||||
|
This configuration is stored in the git-annex branch, so it will be seen
|
||||||
|
by all clones of the repository.
|
||||||
|
|
||||||
When git-annex is asked to drop a file, it first verifies that the
|
When git-annex is asked to drop a file, it first verifies that the
|
||||||
required number of copies can be satisfied among all the other
|
required number of copies can be satisfied among all the other
|
||||||
repositories that have a copy of the file.
|
repositories that have a copy of the file.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# NAME
|
# NAME
|
||||||
|
|
||||||
git-annex vicfg - edit git-annex's configuration
|
git-annex vicfg - edit configuration in git-annex branch
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
|
@ -8,14 +8,19 @@ git annex vicfg
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
Opens EDITOR on a temp file containing all of git-annex's global
|
Opens EDITOR on a temp file containing all of git-annex's
|
||||||
configuration settings, and when it exits, stores any
|
configuration settings that are stored in the git-annex branch,
|
||||||
changes made back to the git-annex branch.
|
and when it exits, stores any changes made back to the git-annex branch.
|
||||||
|
|
||||||
|
Unlike git config settings, these configuration settings can be seen
|
||||||
|
by all clones of the repository.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
[[git-annex]](1)
|
[[git-annex]](1)
|
||||||
|
|
||||||
|
git-config(1)
|
||||||
|
|
||||||
# AUTHOR
|
# AUTHOR
|
||||||
|
|
||||||
Joey Hess <id@joeyh.name>
|
Joey Hess <id@joeyh.name>
|
||||||
|
|
Loading…
Reference in a new issue