diff options
Diffstat (limited to 'Git/Sha.hs')
-rw-r--r-- | Git/Sha.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Git/Sha.hs b/Git/Sha.hs new file mode 100644 index 000000000..475c2ba5f --- /dev/null +++ b/Git/Sha.hs @@ -0,0 +1,27 @@ +{- git SHA stuff + - + - Copyright 2011 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Git.Sha where + +import Common +import Git.Types + +{- Runs an action that causes a git subcommand to emit a sha, and strips + any trailing newline, returning the sha. -} +getSha :: String -> IO String -> IO Sha +getSha subcommand a = do + t <- a + let t' = if last t == '\n' + then init t + else t + when (length t' /= shaSize) $ + error $ "failed to read sha from git " ++ subcommand ++ " (" ++ t' ++ ")" + return $ Ref t' + +{- Size of a git sha. -} +shaSize :: Int +shaSize = 40 |