Skip to content

Commit

Permalink
strong hash type
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierverdier committed Feb 3, 2015
1 parent 87a0dc0 commit ac74acf
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import System.IO.Unsafe (unsafeInterleaveIO)

{- Type aliases -}

type Hash = String
newtype Hash = MkHash {getHash :: String}
type Numbers = [String]

{- Combining branch and status parsing -}
Expand Down Expand Up @@ -38,8 +38,8 @@ makeHashWith :: Char -- prefix to hashes
-> Maybe Hash
-> String
makeHashWith _ Nothing = "" -- some error in gitrevparse
makeHashWith _ (Just "") = "" -- hash too short
makeHashWith c (Just hash) = c : init hash
makeHashWith _ (Just (MkHash "")) = "" -- hash too short
makeHashWith c (Just (MkHash hash)) = c : init hash

{- Git commands -}

Expand All @@ -54,13 +54,15 @@ gitstatus :: IO (Maybe String)
gitstatus = safeRun "git" ["status", "--porcelain", "--branch"]

gitrevparse :: IO (Maybe Hash)
gitrevparse = safeRun "git" ["rev-parse", "--short", "HEAD"]
gitrevparse = do
result <- safeRun "git" ["rev-parse", "--short", "HEAD"]
return $ MkHash <$> result

{- Combine status info, branch info and hash -}

branchOrHash :: Maybe Hash -> Maybe Branch -> String
branchOrHash _ (Just branch) = show branch
branchOrHash (Just hash) Nothing = hash
branchOrHash (Just hash) Nothing = getHash hash
branchOrHash Nothing _ = ""

allStrings :: Maybe Hash
Expand Down

0 comments on commit ac74acf

Please sign in to comment.