Skip to content

Commit

Permalink
Merge pull request #8 from arekfu/master
Browse files Browse the repository at this point in the history
A couple of trivial improvements
  • Loading branch information
kaitanie committed Jan 15, 2012
2 parents 8fd7e17 + ff2fa5c commit 7ca3269
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/GitRunner.hs
Expand Up @@ -19,15 +19,12 @@ data GitCommand = GitRevisionInfoCmd
gitCommandArgs :: GitCommand -> [String]
gitCommandArgs GitUpdateIndexCmd = ["update-index", "-q", "--refresh"]
gitCommandArgs GitDiffIndexNamesCmd = ["diff-index", "--name-only", "HEAD", "--"]
gitCommandArgs GitRevisionInfoCmd = ["describe", "--tags"]
gitCommandArgs GitRevisionInfoCmd = ["describe", "--tags", "--dirty"]

buildGitRevisionString :: GitRepo -> IO String
buildGitRevisionString repo = do
isDirty <- gitIsDirtyTree repo
(_, revStr) <- runGit repo GitRevisionInfoCmd
if isDirty
then return $ revStr ++ "-dirty"
else return revStr
return revStr

gitIsDirtyTree :: GitRepo -> IO Bool
gitIsDirtyTree repo = do
Expand All @@ -36,6 +33,10 @@ gitIsDirtyTree repo = do
let changedFiles = length output
return $ changedFiles > 0

concatenateArgs :: [String] -> String
concatenateArgs [] = []
concatenateArgs (x:xs) = x ++ " " ++ concatenateArgs xs

runGit :: GitRepo -> GitCommand -> IO (ExitCode, String)
runGit repo command = do
let gitArgs = gitCommandArgs command
Expand All @@ -53,5 +54,5 @@ runGit repo command = do
return (ExitSuccess, trimmedOutput)
(ExitFailure errorCode) -> do
gitErrorStr <- hGetContents gitErrorStream
let msg = "Git failed with code " ++ (show errorCode) ++ " and message:\n" ++ gitErrorStr
let msg = "`git " ++ (concatenateArgs gitArgs) ++ "` failed with code " ++ (show errorCode) ++ " and message:\n" ++ gitErrorStr
return (exitCode, msg)
14 changes: 4 additions & 10 deletions src/SedRunner.hs
Expand Up @@ -15,27 +15,24 @@ data SedCommand = SedIntToG4Int
| SedCommentIncludeCassert
| SedFixG4G4
| SedFixUnsignedG4Int
| SedFixG4boolalpha
deriving (Show, Eq)

--toG4TypeRegexp t = ["\\'s/\\b\\(" ++ t ++"\\)\\b/G4\\1/g\'"]
toG4TypeRegexp :: String -> [String]
toG4TypeRegexp t = ["s/" ++ t ++ "/G4" ++ t ++ "/g"]
toG4TypeRegexp t = ["s/\\(\\b\\)" ++ t ++ "\\(\\b\\)/\\1G4" ++ t ++ "\\2/g"]

--let substitute x y s = subRegex (mkRegex x) s y
-- substitute "int" "G4int"

sedCommandArgs :: SedCommand -> [String]
sedCommandArgs SedIntToG4Int = ["s/int/G4int/g"]
--sedCommandArgs SedIntToG4Int = toG4TypeRegexp "int"
sedCommandArgs SedIntToG4Int = toG4TypeRegexp "int"
sedCommandArgs SedFloatToG4Float = toG4TypeRegexp "float"
sedCommandArgs SedDoubleToG4Double = toG4TypeRegexp "double"
sedCommandArgs SedBoolToG4Bool = toG4TypeRegexp "bool"
sedCommandArgs SedCommentAsserts = ["s/^ *assert/\\/\\/ assert/g"]
sedCommandArgs SedCommentAsserts = ["s/^\\s*assert/\\/\\/ assert/g"]
sedCommandArgs SedCommentIncludeCassert = ["s/#include \\+<cassert>/\\/\\/ #include <cassert>/g"]
sedCommandArgs SedFixG4G4 = ["s/G4G4/G4/g"]
sedCommandArgs SedFixUnsignedG4Int = ["s/unsigned\\ G4int/unsigned\\ int/g"]
sedCommandArgs SedFixG4boolalpha = ["s/G4boolalpha/boolalpha/g"]

useG4Int :: String -> IO String
useG4Int = runSed SedIntToG4Int
Expand Down Expand Up @@ -64,13 +61,10 @@ fixG4G4 = runSed SedFixG4G4
fixUnsignedG4int :: String -> IO String
fixUnsignedG4int = runSed SedFixUnsignedG4Int

fixG4boolalpha :: String -> IO String
fixG4boolalpha = runSed SedFixG4boolalpha

-- Chain the useG4<type> functions together.
useG4Types :: String -> IO String
--useG4Types code = (useG4Int code)
useG4Types code = (useG4Int code) >>= useG4Float >>= useG4Double >>= useG4Bool >>= fixG4G4 >>= fixUnsignedG4int >>= fixG4boolalpha
useG4Types code = (useG4Int code) >>= useG4Float >>= useG4Double >>= useG4Bool >>= fixG4G4 >>= fixUnsignedG4int

runSed :: SedCommand -> String -> IO String
runSed command inputData = do
Expand Down

0 comments on commit 7ca3269

Please sign in to comment.