improve adjusted branch name parsing to support adjusted view branches
authorJoey Hess <joeyh@joeyh.name>
Mon, 27 Feb 2023 17:08:29 +0000 (13:08 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 27 Feb 2023 18:09:05 +0000 (14:09 -0400)
An adjusted view branch has a name like
"adjusted/views/master(author=_)(unlocked)"
and so the adjustment starts at the last open paren, not the first open
paren.

Note that git-annex sync still does not do anything useful when run in
such a branch, because it does not realize that it is a view branch.
This is only groundwork for adjusted view branches.

This also fixes adjusted branches when the basis branch name contains
parens for some other reason, though that is not common in a git branch
name.

Sponsored-by: Boyd Stephen Smith Jr. on Patreon
Annex/AdjustedBranch/Name.hs
Utility/Misc.hs

index e71a5f66c8ba91aec0f4867029fa790104c7efb1..7a1b44d54e428a79736b1c21d3aaaa6bb0fa173e 100644 (file)
@@ -88,7 +88,7 @@ type OrigBranch = Branch
 adjustedToOriginal :: Branch -> Maybe (Adjustment, OrigBranch)
 adjustedToOriginal b
        | adjustedBranchPrefix `S.isPrefixOf` bs = do
-               let (base, as) = separate' (== openparen) (S.drop prefixlen bs)
+               let (base, as) = separateEnd' (== openparen) (S.drop prefixlen bs)
                adj <- deserializeAdjustment (S.takeWhile (/= closeparen) as)
                Just (adj, Git.Ref.branchRef (Ref base))
        | otherwise = Nothing
index 01ae178d85feaf152f4da3ef1dc3d30b6b834911..121c06e7cd3cdd24367cb3a09053dd64391100c9 100644 (file)
@@ -12,6 +12,7 @@ module Utility.Misc (
        readFileStrict,
        separate,
        separate',
+       separateEnd',
        firstLine,
        firstLine',
        segment,
@@ -62,6 +63,13 @@ separate' c l = unbreak $ S.break c l
                | S.null b = r
                | otherwise = (a, S.tail b)
 
+separateEnd' :: (Word8 -> Bool) -> S.ByteString -> (S.ByteString, S.ByteString)
+separateEnd' c l = unbreak $ S.breakEnd c l
+  where
+       unbreak r@(a, b)
+               | S.null a = r
+               | otherwise = (S.init a, b)
+
 {- Breaks out the first line. -}
 firstLine :: String -> String
 firstLine = takeWhile (/= '\n')