summaryrefslogtreecommitdiff
path: root/Git/Sha.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-14 15:30:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-14 15:43:13 -0400
commit02f1bd2bf47d3ff49a222e9428ec27708ef55f64 (patch)
tree456548530c65850a829a1a85609070bc111de1b9 /Git/Sha.hs
parent2b24e16a633575703a43e1fb991f34b290a1d7e4 (diff)
split more stuff out of Git.hs
Diffstat (limited to 'Git/Sha.hs')
-rw-r--r--Git/Sha.hs27
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