From 9b1fe37818e45db22c93e46111cd46ae26246829 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 27 Feb 2023 13:08:29 -0400 Subject: [PATCH] improve adjusted branch name parsing to support adjusted view branches 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 | 2 +- Utility/Misc.hs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Annex/AdjustedBranch/Name.hs b/Annex/AdjustedBranch/Name.hs index e71a5f66c8..7a1b44d54e 100644 --- a/Annex/AdjustedBranch/Name.hs +++ b/Annex/AdjustedBranch/Name.hs @@ -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 diff --git a/Utility/Misc.hs b/Utility/Misc.hs index 01ae178d85..121c06e7cd 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -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')