module VCSWrapper.Git.Parsers (
parseStatus
, parseBranches
, parseRemotes
, parseSimpleLog
, parsePullMergeConflict
) where
import Data.List.Utils
import Data.List
import Text.ParserCombinators.Parsec
import VCSWrapper.Common.Types
parseStatus :: String
-> [Status]
parseStatus status = [ GITStatus filepath Modified | (_:x:_:filepath) <- lines, x == 'M']
++ [ GITStatus filepath Untracked | (x:_:_:filepath) <- lines, x == '?']
++ [ GITStatus filepath Added | (x:_:_:filepath) <- lines, x == 'A']
++ [ GITStatus filepath Deleted | (x:y:_:filepath) <- lines, x == 'D' || y == 'D']
where
lines = split "\n" status
parseBranches :: String -> (String, [String])
parseBranches string = (head [branchname | ('*':_:branchname) <- lined],
[branchname | (' ':' ':branchname) <- lined])
where
lined = lines string
parseRemotes :: String -> [String]
parseRemotes = split "\n"
parsePullMergeConflict :: String -> Bool
parsePullMergeConflict s = isPrefixOf "CONFLICT" s
parseSimpleLog :: String -> [LogEntry]
parseSimpleLog log =
case parsed of
Right entries -> entries
Left _ -> []
where parsed = parse logEntries "" log
logEntry :: Parser LogEntry
logEntry = do
string "commit:"
commitID <- wholeLine
author <- wholeLine
email <- wholeLine
date <- wholeLine
subject <- wholeLine
body <- bodyLines
char '\n'
return $ LogEntry Nothing commitID author email date subject body
bodyLines = manyTill anyChar (nullChar)
logEntries :: Parser [LogEntry]
logEntries = manyTill logEntry eof
wholeLine = manyTill anyChar newline
nullChar = satisfy (=='\0') >> return ()