Skip to content

Commit

Permalink
new GitInfo type
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierverdier committed Feb 4, 2015
1 parent df509a3 commit 7d480a9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import StatusParse (Status(MakeStatus), processStatus)

newtype Hash = MkHash {getHash :: String}

data GitInfo = MkGitInfo MBranchInfo (Status Int)

{- Combining branch and status parsing -}

rightOrNothing :: Either a b -> Maybe b
Expand All @@ -17,9 +19,9 @@ rightOrNothing = either (const Nothing) Just
processBranch :: String -> Maybe MBranchInfo
processBranch = rightOrNothing . branchInfo

processGitStatus :: [String] -> Maybe (MBranchInfo, Status Int)
processGitStatus :: [String] -> Maybe GitInfo
processGitStatus [] = Nothing
processGitStatus (branchLine:statusLines) = (,) <$> processBranch branchLine <*> processStatus statusLines
processGitStatus (branchLine:statusLines) = MkGitInfo <$> processBranch branchLine <*> processStatus statusLines

showStatusNumbers :: Status Int -> [String]
showStatusNumbers (MakeStatus s x c t) = show <$> [s, x, c, t]
Expand All @@ -42,9 +44,9 @@ branchOrHashWith c (Just hash) Nothing = showBranchInfo $ MkBranchInfo (MkBranch
branchOrHashWith _ Nothing _ = showBranchInfo $ MkBranchInfo (MkBranch "") Nothing

allStrings :: Maybe Hash
-> (MBranchInfo, Status Int)
-> GitInfo
-> [String]
allStrings mhash (bi, stat) = branchOrHashWith ':' mhash bi ++ showStatusNumbers stat
allStrings mhash (MkGitInfo bi stat) = branchOrHashWith ':' mhash bi ++ showStatusNumbers stat

stringsFromStatus :: Maybe Hash
-> String -- status
Expand Down

0 comments on commit 7d480a9

Please sign in to comment.