improve type signatures with a Ref newtype

In git, a Ref can be a Sha, or a Branch, or a Tag. I added type aliases for
those. Note that this does not prevent mixing up of eg, refs and branches
at the type level. Since git really doesn't care, except rare cases like
git update-ref, or git tag -d, that seems ok for now.

There's also a tree-ish, but let's just use Ref for it. A given Sha or Ref
may or may not be a tree-ish, depending on the object type, so there seems
no point in trying to represent it at the type level.
This commit is contained in:
Joey Hess 2011-11-16 02:23:34 -04:00
parent 272a67921c
commit 9290095fc2
10 changed files with 86 additions and 71 deletions

View file

@ -19,8 +19,6 @@ import qualified Data.ByteString.Lazy.Char8 as L
import Git
import Utility.SafeCommand
type Treeish = String
data TreeItem = TreeItem
{ mode :: FileMode
, typeobj :: String
@ -28,10 +26,10 @@ data TreeItem = TreeItem
, file :: FilePath
} deriving Show
{- Lists the contents of a Treeish -}
lsTree :: Treeish -> Repo -> IO [TreeItem]
{- Lists the contents of a Ref -}
lsTree :: Ref -> Repo -> IO [TreeItem]
lsTree t repo = map parseLsTree <$>
pipeNullSplitB [Params "ls-tree --full-tree -z -r --", File t] repo
pipeNullSplitB [Params "ls-tree --full-tree -z -r --", File $ show t] repo
{- Parses a line of ls-tree output.
- (The --long format is not currently supported.) -}