From 4c4ebf2d7570030a70fdbd313b8b60e9fa727eee Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 22 Jun 2011 17:08:51 -0400 Subject: store trust.log and remote.log in the git-annex branch .. and I think that's everything that will use the branch --- Branch.hs | 18 +++++++++--------- CmdLine.hs | 2 +- Command/InitRemote.hs | 11 ----------- Locations.hs | 5 ----- Remote.hs | 20 +++++--------------- Trust.hs | 27 ++++++--------------------- UUID.hs | 8 ++++++-- 7 files changed, 27 insertions(+), 64 deletions(-) diff --git a/Branch.hs b/Branch.hs index 85928765d..ad9b805d0 100644 --- a/Branch.hs +++ b/Branch.hs @@ -168,15 +168,6 @@ change file content = do Param sha, File file] setCacheChanged file content -{- Commits any staged changes to the branch. -} -commit :: String -> Annex () -commit message = do - state <- getState - when (branchChanged state) $ do - g <- Annex.gitRepo - withIndex $ liftIO $ - GitUnionMerge.commit g message fullname [fullname] - {- Gets the content of a file on the branch, or content staged in the index - if it's newer. Returns an empty string if the file didn't exist yet. -} get :: FilePath -> Annex String @@ -192,3 +183,12 @@ get file = do where cat g = Git.pipeRead g [Param "cat-file", Param "blob", catfile] catfile = Param $ ':':file + +{- Commits any staged changes to the branch. -} +commit :: String -> Annex () +commit message = do + state <- getState + when (branchChanged state) $ do + g <- Annex.gitRepo + withIndex $ liftIO $ + GitUnionMerge.commit g message fullname [fullname] diff --git a/CmdLine.hs b/CmdLine.hs index a5bda695a..d10516bb9 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -103,8 +103,8 @@ startup = do {- Cleanup actions. -} shutdown :: Annex Bool shutdown = do - Branch.commit "update" AnnexQueue.flush False + Branch.commit "update" liftIO $ Git.reap diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index 41d3c37c7..67030689d 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -14,11 +14,8 @@ import Data.Maybe import Data.String.Utils import Command -import qualified Annex import qualified Remote import qualified Types.Remote as R -import qualified GitRepo as Git -import Utility import Types import UUID import Messages @@ -62,14 +59,6 @@ perform t u c = do cleanup :: UUID -> R.RemoteConfig -> CommandCleanup cleanup u c = do Remote.configSet u c - g <- Annex.gitRepo - logfile <- Remote.remoteLog - liftIO $ Git.run g "add" [File logfile] - liftIO $ Git.run g "commit" - [ Params "-q --allow-empty -m" - , Param "git annex initremote" - , File logfile - ] return True {- Look up existing remote's UUID and config by name, or generate a new one -} diff --git a/Locations.hs b/Locations.hs index 9175c4f61..d2241636e 100644 --- a/Locations.hs +++ b/Locations.hs @@ -20,7 +20,6 @@ module Locations ( gitAnnexBadLocation, gitAnnexUnusedLog, isLinkToAnnex, - uuidLog, logFile, logFileKey, hashDirMixed, @@ -118,10 +117,6 @@ gitAnnexUnusedLog prefix r = gitAnnexDir r (prefix ++ "unused") isLinkToAnnex :: FilePath -> Bool isLinkToAnnex s = ("/.git/" ++ objectDir) `isInfixOf` s -{- Filename of uuid.log. -} -uuidLog :: FilePath -uuidLog = "uuid.log" - {- The filename of the log file for a given key. -} logFile :: Key -> String logFile key = hashDirLower key ++ keyFile key ++ ".log" diff --git a/Remote.hs b/Remote.hs index 804c0ef5a..512242342 100644 --- a/Remote.hs +++ b/Remote.hs @@ -33,19 +33,17 @@ module Remote ( prop_idempotent_configEscape ) where -import Control.Monad.State (liftIO) import Control.Monad (filterM) import Data.List import qualified Data.Map as M import Data.Maybe import Data.Char +import qualified Branch import Types import Types.Remote import UUID import qualified Annex -import Locations -import Utility import Config import Trust import LocationLog @@ -160,29 +158,21 @@ forceTrust level remotename = do s { Annex.forcetrust = (r, level):Annex.forcetrust s } {- Filename of remote.log. -} -remoteLog :: Annex FilePath -remoteLog = do - g <- Annex.gitRepo - return $ gitStateDir g ++ "remote.log" +remoteLog :: FilePath +remoteLog = "remote.log" {- Adds or updates a remote's config in the log. -} configSet :: UUID -> RemoteConfig -> Annex () configSet u c = do m <- readRemoteLog - l <- remoteLog - liftIO $ safeWriteFile l $ unlines $ sort $ + Branch.change remoteLog $ unlines $ sort $ map toline $ M.toList $ M.insert u c m where toline (u', c') = u' ++ " " ++ (unwords $ configToKeyVal c') {- Map of remotes by uuid containing key/value config maps. -} readRemoteLog :: Annex (M.Map UUID RemoteConfig) -readRemoteLog = do - l <- remoteLog - s <- liftIO $ catch (readFile l) ignoreerror - return $ remoteLogParse s - where - ignoreerror _ = return "" +readRemoteLog = return . remoteLogParse =<< Branch.get remoteLog remoteLogParse :: String -> M.Map UUID RemoteConfig remoteLogParse s = diff --git a/Trust.hs b/Trust.hs index aaca3b370..d328235bf 100644 --- a/Trust.hs +++ b/Trust.hs @@ -18,18 +18,14 @@ import Control.Monad.State import qualified Data.Map as M import TrustLevel -import qualified GitRepo as Git +import qualified Branch import Types import UUID -import Locations import qualified Annex -import Utility {- Filename of trust.log. -} -trustLog :: Annex FilePath -trustLog = do - g <- Annex.gitRepo - return $ gitStateDir g ++ "trust.log" +trustLog :: FilePath +trustLog = "trust.log" {- Returns a list of UUIDs at the specified trust level. -} trustGet :: TrustLevel -> Annex [UUID] @@ -41,12 +37,9 @@ trustGet level = do - values from forcetrust -} trustMap :: Annex (M.Map UUID TrustLevel) trustMap = do - logfile <- trustLog overrides <- Annex.getState Annex.forcetrust - s <- liftIO $ catch (readFile logfile) ignoreerror + s <- Branch.get trustLog return $ M.fromList $ trustMapParse s ++ overrides - where - ignoreerror _ = return "" {- Trust map parser. -} trustMapParse :: String -> [(UUID, TrustLevel)] @@ -60,7 +53,7 @@ trustMapParse s = map pair $ filter (not . null) $ lines s where w = words l -{- Changes the trust level for a uuid in the trustLog, and commits it. -} +{- Changes the trust level for a uuid in the trustLog. -} trustSet :: UUID -> TrustLevel -> Annex () trustSet uuid level = do when (null uuid) $ @@ -68,15 +61,7 @@ trustSet uuid level = do m <- trustMap when (M.lookup uuid m /= Just level) $ do let m' = M.insert uuid level m - logfile <- trustLog - liftIO $ safeWriteFile logfile (serialize m') - g <- Annex.gitRepo - liftIO $ Git.run g "add" [File logfile] - liftIO $ Git.run g "commit" - [ Params "-q -m" - , Param "git annex trust change" - , File logfile - ] + Branch.change trustLog (serialize m') where serialize m = unlines $ map showpair $ M.toList m showpair (u, t) = u ++ " " ++ show t diff --git a/UUID.hs b/UUID.hs index 78667f235..5d8304f83 100644 --- a/UUID.hs +++ b/UUID.hs @@ -19,7 +19,8 @@ module UUID ( genUUID, prettyPrintUUIDs, describeUUID, - uuidMap + uuidMap, + uuidLog ) where import Control.Monad.State @@ -35,11 +36,14 @@ import Types.UUID import qualified Annex import qualified SysConfig import Config -import Locations configkey :: String configkey = "annex.uuid" +{- Filename of uuid.log. -} +uuidLog :: FilePath +uuidLog = "uuid.log" + {- Generates a UUID. There is a library for this, but it's not packaged, - so use the command line tool. -} genUUID :: IO UUID -- cgit v1.2.3