diff options
author | Joey Hess <joey@kitenet.net> | 2012-10-01 15:12:04 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-10-01 15:12:04 -0400 |
commit | 59d2f363b7a2762978978bb3edf62aa47ef81abd (patch) | |
tree | 6519760756a8d9cef3558a91ab3cbc69f1e58ac3 /Logs | |
parent | 65315e13716443be3c50f7e556a1206a45df2a32 (diff) |
group, ungroup: New commands to indicate groups of repositories.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/Group.hs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Logs/Group.hs b/Logs/Group.hs new file mode 100644 index 000000000..9263c7760 --- /dev/null +++ b/Logs/Group.hs @@ -0,0 +1,52 @@ +{- git-annex group log + - + - Copyright 2012 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Logs.Group ( + groupSet, + lookupGroups, + groupMap, +) where + +import qualified Data.Map as M +import qualified Data.Set as S +import Data.Time.Clock.POSIX + +import Common.Annex +import qualified Annex.Branch +import qualified Annex +import Logs.UUIDBased +import Types.Group + +{- Filename of group.log. -} +groupLog :: FilePath +groupLog = "group.log" + +{- Returns the groups of a given repo UUID. -} +lookupGroups :: UUID -> Annex (S.Set Group) +lookupGroups u = (fromMaybe S.empty . M.lookup u) <$> groupMap + +{- Changes the groups for a uuid in the groupLog. -} +groupSet :: UUID -> S.Set Group -> Annex () +groupSet uuid@(UUID _) groups = do + ts <- liftIO getPOSIXTime + Annex.Branch.change groupLog $ + showLog (unwords . S.toList) . changeLog ts uuid groups . + parseLog (Just . S.fromList . words) + Annex.changeState $ \s -> s { Annex.groupmap = Nothing } +groupSet NoUUID _ = error "unknown UUID; cannot modify group" + +{- Read the groupLog into a map. The map is cached for speed. -} +groupMap :: Annex GroupMap +groupMap = do + cached <- Annex.getState Annex.groupmap + case cached of + Just m -> return m + Nothing -> do + m <- simpleMap . parseLog (Just . S.fromList . words) <$> + Annex.Branch.get groupLog + Annex.changeState $ \s -> s { Annex.groupmap = Just m } + return m |