summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-12 17:38:46 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-12 17:38:46 -0400
commit98dfc0c9b0024c156d0fea99bf8d2355e06244a7 (patch)
tree351e6f5f430aca7b5d10e79547f4e4c537a00ab7 /Annex
parentb2f934e07ad32cfe44ea1fab2ca154379f30efe8 (diff)
split out Annex/BranchState.hs
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Branch.hs45
-rw-r--r--Annex/BranchState.hs56
2 files changed, 58 insertions, 43 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index b79a8975d..699bc0323 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -8,7 +8,6 @@
module Annex.Branch (
create,
update,
- disableUpdate,
get,
change,
commit,
@@ -25,7 +24,7 @@ import qualified Data.ByteString.Lazy.Char8 as L
import Common.Annex
import Annex.Exception
-import Types.BranchState
+import Annex.BranchState
import qualified Git
import qualified Git.UnionMerge
import qualified Annex
@@ -148,30 +147,6 @@ commitBranch branchref message parents = do
withIndexUpdate :: Annex a -> Annex a
withIndexUpdate a = update >> withIndex a
-getState :: Annex BranchState
-getState = Annex.getState Annex.branchstate
-
-setState :: BranchState -> Annex ()
-setState state = Annex.changeState $ \s -> s { Annex.branchstate = state }
-
-setCache :: FilePath -> String -> Annex ()
-setCache file content = do
- state <- getState
- setState state { cachedFile = Just file, cachedContent = content }
-
-invalidateCache :: Annex ()
-invalidateCache = do
- state <- getState
- setState state { cachedFile = Nothing, cachedContent = "" }
-
-getCache :: FilePath -> Annex (Maybe String)
-getCache file = getState >>= go
- where
- go state
- | cachedFile state == Just file =
- return $ Just $ cachedContent state
- | otherwise = return Nothing
-
{- Creates the branch, if it does not already exist. -}
create :: Annex ()
create = do
@@ -214,7 +189,7 @@ commit message = whenM journalDirty $ lockJournal $ do
- made.
-}
update :: Annex ()
-update = onceonly $ do
+update = runUpdateOnce $ do
-- ensure branch exists, and get its current ref
branchref <- getBranch
-- check what needs updating before taking the lock
@@ -239,11 +214,6 @@ update = onceonly $ do
else commitBranch branchref merge_desc
(nub $ fullname:refs)
invalidateCache
- where
- onceonly a = unlessM (branchUpdated <$> getState) $ do
- r <- a
- disableUpdate
- return r
{- Checks if the second branch has any commits not present on the first
- branch. -}
@@ -294,17 +264,6 @@ tryFastForwardTo (first:rest) = do
(False, True) -> findbest c rs -- worse
(False, False) -> findbest c rs -- same
-{- Avoids updating the branch. A useful optimisation when the branch
- - is known to have not changed, or git-annex won't be relying on info
- - from it. -}
-disableUpdate :: Annex ()
-disableUpdate = Annex.changeState setupdated
- where
- setupdated s = s { Annex.branchstate = new }
- where
- new = old { branchUpdated = True }
- old = Annex.branchstate s
-
{- Checks if a git ref exists. -}
refExists :: Git.Ref -> Annex Bool
refExists ref = inRepo $ Git.runBool "show-ref"
diff --git a/Annex/BranchState.hs b/Annex/BranchState.hs
new file mode 100644
index 000000000..0950e9a96
--- /dev/null
+++ b/Annex/BranchState.hs
@@ -0,0 +1,56 @@
+{- git-annex branch state management
+ -
+ - Runtime state about the git-annex branch, including a small read cache.
+ -
+ - Copyright 2011 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Annex.BranchState where
+
+import Common.Annex
+import Types.BranchState
+import qualified Annex
+
+getState :: Annex BranchState
+getState = Annex.getState Annex.branchstate
+
+setState :: BranchState -> Annex ()
+setState state = Annex.changeState $ \s -> s { Annex.branchstate = state }
+
+setCache :: FilePath -> String -> Annex ()
+setCache file content = do
+ state <- getState
+ setState state { cachedFile = Just file, cachedContent = content }
+
+getCache :: FilePath -> Annex (Maybe String)
+getCache file = getState >>= go
+ where
+ go state
+ | cachedFile state == Just file =
+ return $ Just $ cachedContent state
+ | otherwise = return Nothing
+
+invalidateCache :: Annex ()
+invalidateCache = do
+ state <- getState
+ setState state { cachedFile = Nothing, cachedContent = "" }
+
+{- Runs an action to update the branch, if it's not been updated before
+ - in this run of git-annex. -}
+runUpdateOnce :: Annex () -> Annex ()
+runUpdateOnce a = unlessM (branchUpdated <$> getState) $ do
+ a
+ disableUpdate
+
+{- Avoids updating the branch. A useful optimisation when the branch
+ - is known to have not changed, or git-annex won't be relying on info
+ - from it. -}
+disableUpdate :: Annex ()
+disableUpdate = Annex.changeState setupdated
+ where
+ setupdated s = s { Annex.branchstate = new }
+ where
+ new = old { branchUpdated = True }
+ old = Annex.branchstate s