summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Annex/Branch.hs28
-rw-r--r--Utility/Misc.hs4
2 files changed, 17 insertions, 15 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index 3da8bb198..b108281ce 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -88,7 +88,8 @@ updateIndex = do
go Nothing = return ()
go (Just branchref) = do
lock <- fromRepo gitAnnexIndexLock
- lockref <- firstRef <$> liftIO (catchDefaultIO (readFileStrict lock) "")
+ lockref <- Git.Ref . firstLine <$>
+ liftIO (catchDefaultIO (readFileStrict lock) "")
when (lockref /= branchref) $ do
withIndex $ mergeIndex [fullname]
setIndexRef branchref
@@ -303,6 +304,17 @@ refExists :: Git.Ref -> Annex Bool
refExists ref = inRepo $ Git.runBool "show-ref"
[Param "--verify", Param "-q", Param $ show ref]
+{- Get the ref of a branch. -}
+getRef :: Git.Branch -> Annex (Maybe Git.Ref)
+getRef branch = process . L.unpack <$> showref
+ where
+ showref = inRepo $ Git.pipeRead [Param "show-ref",
+ Param "--hash", -- get the hash
+ Params "--verify", -- only exact match
+ Param $ show branch]
+ process [] = Nothing
+ process s = Just $ Git.Ref $ firstLine s
+
{- Does the main git-annex branch exist? -}
hasBranch :: Annex Bool
hasBranch = refExists fullname
@@ -325,20 +337,6 @@ siblingBranches = do
gen l = (Git.Ref $ head l, Git.Ref $ last l)
uref (a, _) (b, _) = a == b
-{- Get the ref of a branch. -}
-getRef :: Git.Ref -> Annex (Maybe Git.Ref)
-getRef branch = process . L.unpack <$> showref
- where
- showref = inRepo $ Git.pipeRead [Param "show-ref",
- Param "--hash", -- get the hash
- Params "--verify", -- only exact match
- Param $ show branch]
- process [] = Nothing
- process s = Just $ firstRef s
-
-firstRef :: String-> Git.Ref
-firstRef = Git.Ref . takeWhile (/= '\n')
-
{- Applies a function to modifiy the content of a file.
-
- Note that this does not cause the branch to be merged, it only
diff --git a/Utility/Misc.hs b/Utility/Misc.hs
index 541e150b7..e95ac4319 100644
--- a/Utility/Misc.hs
+++ b/Utility/Misc.hs
@@ -40,6 +40,10 @@ separate c l = unbreak $ break c l
| null b = r
| otherwise = (a, tail b)
+{- Breaks out the first line. -}
+firstLine :: String-> String
+firstLine = takeWhile (/= '\n')
+
{- Catches IO errors and returns a Bool -}
catchBoolIO :: IO Bool -> IO Bool
catchBoolIO a = catchDefaultIO a False