diff options
-rw-r--r-- | Command/Vicfg.hs | 79 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | doc/design/assistant/transfer_control.mdwn | 52 |
3 files changed, 78 insertions, 60 deletions
diff --git a/Command/Vicfg.hs b/Command/Vicfg.hs index 31b8f6f01..0466c0c31 100644 --- a/Command/Vicfg.hs +++ b/Command/Vicfg.hs @@ -35,7 +35,8 @@ start = do f <- fromRepo gitAnnexTmpCfgFile createAnnexDirectory $ parentDir f cfg <- getCfg - liftIO $ writeFile f $ genCfg cfg + descs <- uuidDescriptions + liftIO $ writeFile f $ genCfg cfg descs vicfg cfg f stop @@ -57,7 +58,6 @@ data Cfg = Cfg { cfgTrustMap :: TrustMap , cfgGroupMap :: M.Map UUID (S.Set Group) , cfgPreferredContentMap :: M.Map UUID String - , cfgDescriptions :: M.Map UUID String } getCfg :: Annex Cfg @@ -65,7 +65,6 @@ getCfg = Cfg <$> trustMapRaw -- without local trust overrides <*> (groupsByUUID <$> groupMap) <*> preferredContentMapRaw - <*> uuidDescriptions setCfg :: Cfg -> Cfg -> Annex () setCfg curcfg newcfg = do @@ -80,13 +79,8 @@ diffCfg curcfg newcfg = (diff cfgTrustMap, diff cfgGroupMap, diff cfgPreferredCo diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x) (f newcfg) (f curcfg) -genCfg :: Cfg -> String -genCfg cfg = unlines $ concat - [ intro - , trustintro, trust, defaulttrust - , groupsintro, groups, defaultgroups - , preferredcontentintro, preferredcontent, defaultpreferredcontent - ] +genCfg :: Cfg -> M.Map UUID String -> String +genCfg cfg descs = unlines $ concat [intro, trust, groups, preferredcontent] where intro = [ com "git-annex configuration" @@ -94,50 +88,48 @@ genCfg cfg = unlines $ concat , com "Changes saved to this file will be recorded in the git-annex branch." , com "" , com "Lines in this file have the format:" - , com " setting repo = value" + , com " setting uuid = value" ] - trustintro = + trust = settings cfgTrustMap [ "" , com "Repository trust configuration" , com "(Valid trust levels: " ++ unwords (map showTrustLevel [Trusted .. DeadTrusted]) ++ ")" ] - trust = map (\(t, u) -> line "trust" u $ showTrustLevel t) $ - sort $ map swap $ M.toList $ cfgTrustMap cfg + (\(t, u) -> line "trust" u $ showTrustLevel t) + (\u -> lcom $ line "trust" u $ showTrustLevel SemiTrusted) - defaulttrust = map (\u -> pcom $ line "trust" u $ showTrustLevel SemiTrusted) $ - missing cfgTrustMap - groupsintro = + groups = settings cfgGroupMap [ "" , com "Repository groups" , com "(Separate group names with spaces)" ] - groups = sort $ map (\(s, u) -> line "group" u $ unwords $ S.toList s) $ - map swap $ M.toList $ cfgGroupMap cfg - defaultgroups = map (\u -> pcom $ line "group" u "") $ - missing cfgGroupMap + (\(s, u) -> line "group" u $ unwords $ S.toList s) + (\u -> lcom $ line "group" u "") - preferredcontentintro = + preferredcontent = settings cfgPreferredContentMap [ "" , com "Repository preferred contents" ] - preferredcontent = sort $ map (\(s, u) -> line "preferred-content" u s) $ - map swap $ M.toList $ cfgPreferredContentMap cfg - defaultpreferredcontent = map (\u -> pcom $ line "preferred-content" u "") $ - missing cfgPreferredContentMap - - line setting u value = unwords - [ setting - , showu u - , "=" - , value + (\(s, u) -> line "preferred-content" u s) + (\u -> line "preferred-content" u "") + + settings field desc showvals showdefaults = concat + [ desc + , concatMap showvals $ + sort $ map swap $ M.toList $ field cfg + , concatMap (\u -> lcom $ showdefaults u) $ + missing field ] - pcom s = "#" ++ s - showu u = fromMaybe (fromUUID u) $ - M.lookup u (cfgDescriptions cfg) - missing field = S.toList $ M.keysSet (cfgDescriptions cfg) `S.difference` M.keysSet (field cfg) + + line setting u value = + [ com $ "(for " ++ (fromMaybe "" $ M.lookup u descs) ++ ")" + , unwords [setting, fromUUID u, "=", value] + ] + lcom = map (\l -> if "#" `isPrefixOf` l then l else "#" ++ l) + missing field = S.toList $ M.keysSet descs `S.difference` M.keysSet (field cfg) {- If there's a parse error, returns a new version of the file, - with the problem lines noted. -} @@ -155,16 +147,14 @@ parseCfg curcfg = go [] curcfg . lines parse l cfg | null l = Right cfg | "#" `isPrefixOf` l = Right cfg - | null setting || null repo' = Left "missing repository name" - | otherwise = case M.lookup repo' name2uuid of - Nothing -> badval "repository" repo' - Just u -> handle cfg u setting value' + | null setting || null u = Left "missing repository uuid" + | otherwise = handle cfg (toUUID u) setting value' where (setting, rest) = separate isSpace l - (repo, value) = separate (== '=') rest + (r, value) = separate (== '=') rest value' = trimspace value - repo' = reverse $ trimspace $ - reverse $ trimspace repo + u = reverse $ trimspace $ + reverse $ trimspace r trimspace = dropWhile isSpace handle cfg u setting value @@ -184,9 +174,6 @@ parseCfg curcfg = go [] curcfg . lines in Right $ cfg { cfgPreferredContentMap = m } | otherwise = badval "setting" setting - name2uuid = M.fromList $ map swap $ - M.toList $ cfgDescriptions curcfg - showerr (Just msg, l) = [parseerr ++ msg, l] showerr (Nothing, l) -- filter out the header and parse error lines diff --git a/debian/changelog b/debian/changelog index a41fb8599..bedea5c05 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +git-annex (3.20121011) UNRELEASED; urgency=low + + * vicfg: New file format, avoids ambiguity with repos that have the same + description, or no description. + + -- Joey Hess <joeyh@debian.org> Fri, 12 Oct 2012 22:46:08 -0400 + git-annex (3.20121010) unstable; urgency=low * Renamed --ingroup to --inallgroup. diff --git a/doc/design/assistant/transfer_control.mdwn b/doc/design/assistant/transfer_control.mdwn index c506f3e64..614d384bb 100644 --- a/doc/design/assistant/transfer_control.mdwn +++ b/doc/design/assistant/transfer_control.mdwn @@ -8,17 +8,39 @@ But often the remote is just a removable drive or a cloud remote, that has a limited size. This page is about making the assistant do something smart with such remotes. -## TODO - -* easy configuration of preferred content -* Drop no longer preferred content. - - When a file is renamed, it might stop being preferred, so - could be checked and dropped. (If there's multiple links to - the same content, this gets tricky.) - - When a file is sent or received, the sender's preferred content - settings may change, causing it to be dropped from the sender. - - May also want to check for things to drop, from both local and remotes, - when doing the expensive trasfer scan. +## dropping no longer preferred content TODO + +When a file is renamed, it might stop being preferred, so +could be checked and dropped. (If there's multiple links to +the same content, this gets tricky. Let's assume there are not.) + +* When a file is sent or received, the sender's preferred content + settings may change, causing it to be dropped from the sender. +* May also want to check for things to drop, from both local and remotes, + when doing the expensive trasfer scan. + +### analysis of changes that can result in content no longer being preferred + +1. The preferred content expression can change, or a new repo is added, or + groups change. Generally, some change to global annex state. Only way to deal + with this is an expensive scan. (The rest of the items below come from + analizing the terminals used in preferred content expressions.) +2. renaming of a file (ie, moved to `archive/`) +3. some other repository gets the file (`in`, `copies`) +4. some other repository drops the file (`in`, `copies` .. However, it's + unlikely that an expression would prefer content when *more* copies + exisited, and want to drop it when less do. That's nearly a pathological + case.) +5. `migrate` is used to change a backend (`inbackend`; unlikely) + +That's all! Of these, 2 and 3 are by far the most important. + +Rename handling should certianly check 2. + +One place to check for 3 is after transferring a file; but that does not +cover all its cases, as some other repo could transfer the file. To fully +handle 3, need to either use a full scan, or examine location log history +when receiving a git-annex branch push. ## specifying what data a remote prefers to contain **done** @@ -72,6 +94,10 @@ Some examples of using groups: The above is all well and good for those who enjoy boolean algebra, but how to configure these sorts of expressions in the webapp? +Currently, we have a simple drop down list to select between a few +predefined groups with pre-defined preferred content recipes. Is this good +enough? + ## the state change problem **done** Imagine that a trusted repo has setting like `not copies=trusted:2` @@ -88,6 +114,4 @@ Or, expressions could be automatically rewritten to avoid the problem. Or, perhaps simulation could be used to detect the problem. Before dropping, check the expression. Then simulate that the drop has happened. Does the expression now make it want to add it? Then don't drop it! -How to implement this simulation? - -> Solved, fwiw.. +**done**.. effectively using this approach. |