From 258a3356e6461e0164441bb3a3e202cb9ef889e6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Jul 2016 15:22:55 -0400 Subject: --branch, stage 2 Show branch:file that is being operated on. I had to make ActionItem a type and not a type class because withKeyOptions' passed two different types of values when using the type class, and I could not get the type checker to accept that. --- Messages.hs | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'Messages.hs') diff --git a/Messages.hs b/Messages.hs index 6851729ae..050dff950 100644 --- a/Messages.hs +++ b/Messages.hs @@ -9,6 +9,8 @@ module Messages ( showStart, + ActionItem, + mkActionItem, showStart', showNote, showAction, @@ -50,36 +52,50 @@ import System.Log.Handler.Simple import Common import Types import Types.Messages +import Git.FilePath import Messages.Internal import qualified Messages.JSON as JSON import Types.Key import qualified Annex showStart :: String -> FilePath -> Annex () -showStart command file = outputMessage (JSON.start command (Just file) Nothing) $ +showStart command file = outputMessage json $ command ++ " " ++ file ++ " " + where + json = JSON.start command (Just file) Nothing + +data ActionItem + = ActionItemAssociatedFile AssociatedFile + | ActionItemKey + | ActionItemBranchFilePath BranchFilePath + +class MkActionItem t where + mkActionItem :: t -> ActionItem -class ActionItem i where - actionItemDesc :: i -> Key -> String - actionItemWorkTreeFile :: i -> Maybe FilePath +instance MkActionItem AssociatedFile where + mkActionItem = ActionItemAssociatedFile -instance ActionItem FilePath where - actionItemDesc f _ = f - actionItemWorkTreeFile = Just +instance MkActionItem Key where + mkActionItem _ = ActionItemKey -instance ActionItem AssociatedFile where - actionItemDesc (Just f) _ = f - actionItemDesc Nothing k = key2file k - actionItemWorkTreeFile = id +instance MkActionItem BranchFilePath where + mkActionItem = ActionItemBranchFilePath -instance ActionItem Key where - actionItemDesc k _ = key2file k - actionItemWorkTreeFile _ = Nothing +actionItemDesc :: ActionItem -> Key -> String +actionItemDesc (ActionItemAssociatedFile (Just f)) _ = f +actionItemDesc (ActionItemAssociatedFile Nothing) k = key2file k +actionItemDesc ActionItemKey k = key2file k +actionItemDesc (ActionItemBranchFilePath bfp) _ = descBranchFilePath bfp -showStart' :: ActionItem i => String -> Key -> i -> Annex () -showStart' command key i = - outputMessage (JSON.start command (actionItemWorkTreeFile i) (Just key)) $ - command ++ " " ++ actionItemDesc i key ++ " " +actionItemWorkTreeFile :: ActionItem -> Maybe FilePath +actionItemWorkTreeFile (ActionItemAssociatedFile af) = af +actionItemWorkTreeFile _ = Nothing + +showStart' :: String -> Key -> ActionItem -> Annex () +showStart' command key i = outputMessage json $ + command ++ " " ++ actionItemDesc i key ++ " " + where + json = JSON.start command (actionItemWorkTreeFile i) (Just key) showNote :: String -> Annex () showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") " -- cgit v1.2.3