aboutsummaryrefslogtreecommitdiff
path: root/Logs/View.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-02-19 12:52:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-02-19 12:52:47 -0400
commit8d0b3f09a9effc71f729d5b820076c642b605eb4 (patch)
treebf46f214a285de8dde9cdb5eef130ef8c51a950e /Logs/View.hs
parentb3872e5df8256f25911e0859c474342003b63522 (diff)
speed up currentView when not in a view
Avoid reading the view log when the branch is clearly not a view branch.
Diffstat (limited to 'Logs/View.hs')
-rw-r--r--Logs/View.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/Logs/View.hs b/Logs/View.hs
index 47ce7c4c1..2a26cfa17 100644
--- a/Logs/View.hs
+++ b/Logs/View.hs
@@ -50,14 +50,14 @@ recentViews = do
{- Gets the currently checked out view, if there is one. -}
currentView :: Annex (Maybe View)
-currentView = do
- vs <- recentViews
- maybe Nothing (go vs) <$> inRepo Git.Branch.current
+currentView = go =<< inRepo Git.Branch.current
where
- go [] _ = Nothing
- go (v:vs) b
- | branchView v == b = Just v
- | otherwise = go vs b
+ go (Just b) | branchViewPrefix `isPrefixOf` fromRef b =
+ headMaybe . filter (\v -> branchView v == b) <$> recentViews
+ go _ = return Nothing
+
+branchViewPrefix :: String
+branchViewPrefix = "refs/heads/views"
{- Generates a git branch name for a View.
-
@@ -66,8 +66,8 @@ currentView = do
-}
branchView :: View -> Git.Branch
branchView view
- | null name = Git.Ref "refs/heads/views"
- | otherwise = Git.Ref $ "refs/heads/views/" ++ name
+ | null name = Git.Ref branchViewPrefix
+ | otherwise = Git.Ref $ branchViewPrefix ++ "/" ++ name
where
name = intercalate ";" $ map branchcomp (viewComponents view)
branchcomp c