refactor getCurrentBranch
Both Command.Sync and Annex.Ingest had their own versions of this. The one in Annex.Ingest used Git.Branch.currentUnsafe, but does not seem to need it. That is only checking to see if it's in an adjusted unlocked branch, and when in an adjusted branch, the branch does in fact exist, so the added check that Git.Branch.current does is fine. This commit was sponsored by Denis Dzyubenko on Patreon.
This commit is contained in:
parent
c94e62cab5
commit
8be5a7269a
15 changed files with 228 additions and 169 deletions
53
Types/AdjustedBranch.hs
Normal file
53
Types/AdjustedBranch.hs
Normal file
|
@ -0,0 +1,53 @@
|
|||
{- adjusted branch types
|
||||
-
|
||||
- Copyright 2016-2018 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Types.AdjustedBranch where
|
||||
|
||||
data Adjustment
|
||||
= LinkAdjustment LinkAdjustment
|
||||
| PresenceAdjustment PresenceAdjustment (Maybe LinkAdjustment)
|
||||
deriving (Show, Eq)
|
||||
|
||||
-- Doesn't make sense to combine unlock with fix.
|
||||
data LinkAdjustment
|
||||
= UnlockAdjustment
|
||||
| LockAdjustment
|
||||
| FixAdjustment
|
||||
| UnFixAdjustment
|
||||
deriving (Show, Eq)
|
||||
|
||||
data PresenceAdjustment
|
||||
= HideMissingAdjustment
|
||||
| ShowMissingAdjustment
|
||||
deriving (Show, Eq)
|
||||
|
||||
-- Adjustments have to be able to be reversed, so that commits made to the
|
||||
-- adjusted branch can be reversed to the commit that would have been made
|
||||
-- without the adjustment and applied to the original branch.
|
||||
class ReversableAdjustment t where
|
||||
reverseAdjustment :: t -> t
|
||||
|
||||
instance ReversableAdjustment Adjustment where
|
||||
reverseAdjustment (LinkAdjustment l) =
|
||||
LinkAdjustment (reverseAdjustment l)
|
||||
reverseAdjustment (PresenceAdjustment p ml) =
|
||||
PresenceAdjustment (reverseAdjustment p) (fmap reverseAdjustment ml)
|
||||
|
||||
instance ReversableAdjustment LinkAdjustment where
|
||||
reverseAdjustment UnlockAdjustment = LockAdjustment
|
||||
reverseAdjustment LockAdjustment = UnlockAdjustment
|
||||
reverseAdjustment FixAdjustment = UnFixAdjustment
|
||||
reverseAdjustment UnFixAdjustment = FixAdjustment
|
||||
|
||||
instance ReversableAdjustment PresenceAdjustment where
|
||||
reverseAdjustment HideMissingAdjustment = ShowMissingAdjustment
|
||||
reverseAdjustment ShowMissingAdjustment = HideMissingAdjustment
|
||||
|
||||
adjustmentHidesFiles :: Adjustment -> Bool
|
||||
adjustmentHidesFiles (PresenceAdjustment HideMissingAdjustment _) = True
|
||||
adjustmentHidesFiles _ = False
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue