From 2986fec67e8ef0d3883d6f46e3b64c3ee0ab48c4 Mon Sep 17 00:00:00 2001 From: Olivier Verdier Date: Tue, 3 Feb 2015 12:10:53 +0100 Subject: [PATCH] fix hash display (colon and endline) --- src/Main.hs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index cc08cef7..8cab04ae 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -34,13 +34,6 @@ showBranchNumbers distance = show <$> [ahead, behind] (ahead, behind) = fromMaybe (0,0) -- the script needs some value, (0,0) means no display $ pairFromDistance <$> distance -makeHashWith :: Char -- prefix to hashes - -> Maybe Hash - -> String -makeHashWith _ Nothing = "" -- some error in gitrevparse -makeHashWith _ (Just (MkHash "")) = "" -- hash too short -makeHashWith c (Just (MkHash hash)) = c : init hash - {- Git commands -} successOrNothing :: (ExitCode, a, b) -> Maybe a @@ -56,19 +49,19 @@ gitstatus = safeRun "git" ["status", "--porcelain", "--branch"] gitrevparse :: IO (Maybe Hash) gitrevparse = do result <- safeRun "git" ["rev-parse", "--short", "HEAD"] - return $ MkHash <$> result + return $ MkHash . init <$> result {- Combine status info, branch info and hash -} -branchOrHash :: Maybe Hash -> Maybe Branch -> String -branchOrHash _ (Just branch) = show branch -branchOrHash (Just hash) Nothing = getHash hash -branchOrHash Nothing _ = "" +branchOrHashWith :: Char -> Maybe Hash -> Maybe Branch -> String +branchOrHashWith _ _ (Just branch) = show branch +branchOrHashWith c (Just hash) Nothing = c : getHash hash +branchOrHashWith _ Nothing _ = "" allStrings :: Maybe Hash -> (BranchInfo, Status Int) -> [String] -allStrings mhash (MkBranchInfo branch _ behead, stat) = branchOrHash mhash branch : (showBranchNumbers behead ++ showStatusNumbers stat) +allStrings mhash (MkBranchInfo branch _ behead, stat) = branchOrHashWith ':' mhash branch : (showBranchNumbers behead ++ showStatusNumbers stat) stringsFromStatus :: Maybe Hash -> String -- status