move hashObject to HashObject library and generalize it to support all git object types

This commit is contained in:
Joey Hess 2012-06-06 02:31:31 -04:00
parent f1bd72ea54
commit f596084a59
4 changed files with 36 additions and 22 deletions

View file

@ -21,6 +21,7 @@ import Common
import Git
import Git.Sha
import Git.Command
import Git.Types
import qualified Utility.CoProcess as CoProcess
type CatFileHandle = CoProcess.CoProcessHandle
@ -52,7 +53,7 @@ catObject h object = CoProcess.query h send receive
case words header of
[sha, objtype, size]
| length sha == shaSize &&
validobjtype objtype ->
isJust (readObjectType objtype) ->
case reads size of
[(bytes, "")] -> readcontent bytes from
_ -> dne
@ -67,8 +68,3 @@ catObject h object = CoProcess.query h send receive
error "missing newline from git cat-file"
return $ L.fromChunks [content]
dne = return L.empty
validobjtype t
| t == "blob" = True
| t == "commit" = True
| t == "tree" = True
| otherwise = False