summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-04-21 19:42:49 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-04-21 19:42:49 -0400
commitcab63b89f2470d0874e72a4a9e088206fb554c94 (patch)
treec55bacd12c0d8329e932458a94a808adac332ba5
parentb98b69e8c6d9b873a864b79cff857882f67ee576 (diff)
cache parsed core.sharedrepository
-rw-r--r--Annex.hs3
-rw-r--r--Annex/Perms.hs13
2 files changed, 14 insertions, 2 deletions
diff --git a/Annex.hs b/Annex.hs
index ef95ff174..2b58c2bd4 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -37,6 +37,7 @@ import qualified Git
import qualified Git.Config
import Git.CatFile
import Git.CheckAttr
+import Git.SharedRepository
import qualified Git.Queue
import Types.Backend
import qualified Types.Remote
@@ -88,6 +89,7 @@ data AnnexState = AnnexState
, forcebackend :: Maybe String
, forcenumcopies :: Maybe Int
, limit :: Matcher (FilePath -> Annex Bool)
+ , shared :: Maybe SharedRepository
, forcetrust :: TrustMap
, trustmap :: Maybe TrustMap
, ciphers :: M.Map EncryptedCipher Cipher
@@ -113,6 +115,7 @@ newState gitrepo = AnnexState
, forcebackend = Nothing
, forcenumcopies = Nothing
, limit = Left []
+ , shared = Nothing
, forcetrust = M.empty
, trustmap = Nothing
, ciphers = M.empty
diff --git a/Annex/Perms.hs b/Annex/Perms.hs
index 2b54077ca..12dfdd667 100644
--- a/Annex/Perms.hs
+++ b/Annex/Perms.hs
@@ -15,15 +15,24 @@ module Annex.Perms (
import Common.Annex
import Utility.FileMode
import Git.SharedRepository
+import qualified Annex
import System.Posix.Types
+withShared :: (SharedRepository -> Annex a) -> Annex a
+withShared a = maybe startup a =<< Annex.getState Annex.shared
+ where
+ startup = do
+ shared <- fromRepo getSharedRepository
+ Annex.changeState $ \s -> s { Annex.shared = Just shared }
+ a shared
+
{- Sets appropriate file mode for a file or directory in the annex,
- other than the content files and content directory. Normally,
- use the default mode, but with core.sharedRepository set,
- allow the group to write, etc. -}
setAnnexPerm :: FilePath -> Annex ()
-setAnnexPerm file = liftIO . go =<< fromRepo getSharedRepository
+setAnnexPerm file = withShared $ liftIO . go
where
go GroupShared = groupWriteRead file
go AllShared = modifyFileMode file $ addModes $
@@ -33,7 +42,7 @@ setAnnexPerm file = liftIO . go =<< fromRepo getSharedRepository
{- Gets the appropriate mode to use for creating a file in the annex
- (other than content files, which are locked down more). -}
annexFileMode :: Annex FileMode
-annexFileMode = go <$> fromRepo getSharedRepository
+annexFileMode = withShared $ return . go
where
go GroupShared = sharedmode
go AllShared = combineModes (sharedmode:readModes)