Data.Git

hit-0.6.3: Git operations in haskell

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | unix
Safe Haskell | None
Language | Haskell98

Data.Git

Contents

- Basic types
- Helper & type related to ModePerm
- Revision
- Object resolution
- repo context
- Repository queries and creation
- Context operations
- Get objects
- Set objects
- Work trees
- Named refs

Description

Synopsis

- data Ref
- newtype RefName = RefName {
  - refNameRaw :: String
  }
- data Commit = Commit {
  - commitTreeish :: Ref
  - commitParents :: [Ref]
  - commitAuthor :: Person
  - commitCommitter :: Person
  - commitEncoding :: Maybe ByteString
  - commitExtras :: [CommitExtra]
  - commitMessage :: ByteString
  }
- data Person = Person {
  - personName :: ByteString
  - personEmail :: ByteString
  - personTime :: GitTime
  }
- data CommitExtra = CommitExtra {
  - commitExtraKey :: ByteString
  - commitExtraValue :: ByteString
  }
- data Tree = Tree {
  - treeGetEnts :: [TreeEnt]
  }
- data Blob = Blob {
  - blobGetContent :: ByteString
  }
- data Tag = Tag {
  - tagRef :: Ref
  - tagObjectType :: ObjectType
  - tagBlob :: ByteString
  - tagName :: Person
  - tagS :: ByteString
  }
- data GitTime
- newtype ModePerm = ModePerm Word32
- data EntName
- type EntPath = [EntName]
- entName :: ByteString -> EntName
- entPathAppend :: EntPath -> EntName -> EntPath
- data ObjectFileType
  - = FileTypeDirectory
  - | FileTypeRegularFile
  - | FileTypeSymbolicLink
  - | FileTypeGitLink
- data FilePermissions = FilePermissions {
  - getOwnerPerm :: !Perm
  - getGroupPerm :: !Perm
  - getOtherPerm :: !Perm
  }
- getPermission :: ModePerm -> FilePermissions
- getFiletype :: ModePerm -> ObjectFileType
- data Revision
- resolveRevision :: Git -> Revision -> IO (Maybe Ref)
- resolveTreeish :: Git -> Ref -> IO (Maybe Tree)
- resolvePath :: Git -> Ref -> EntPath -> IO (Maybe Ref)
- data Git
- withCurrentRepo :: (Git -> IO a) -> IO a
- withRepo :: FilePath -> (Git -> IO c) -> IO c
- findRepo :: IO FilePath
- initRepo :: FilePath -> IO ()
- isRepo :: FilePath -> IO Bool
- rewrite :: Git -> (Commit -> IO Commit) -> Revision -> Int -> IO Ref
- getObject :: Git -> Ref -> Bool -> IO (Maybe Object)
- getCommit :: Git -> Ref -> IO Commit
- getTree :: Git -> Ref -> IO Tree
- setObject :: Git -> Object -> IO Ref
- toObject :: Objectable a => a -> Object
- type WorkTree = MVar TreeSt
- data EntType
  - = EntDirectory
  - | EntFile
  - | EntExecutable
- workTreeNew :: IO WorkTree
- workTreeFrom :: Ref -> IO WorkTree
- workTreeDelete :: Git -> WorkTree -> EntPath -> IO ()
- workTreeSet :: Git -> WorkTree -> EntPath -> (EntType, Ref) -> IO ()
- workTreeFlush :: Git -> WorkTree -> IO Ref
- branchWrite :: Git -> RefName -> Ref -> IO ()
- branchList :: Git -> IO (Set RefName)
- tagWrite :: Git -> RefName -> Ref -> IO ()
- tagList :: Git -> IO (Set RefName)
- headSet :: Git -> Either Ref RefName -> IO ()
- headGet :: Git -> IO (Either Ref RefName)

# Basic types

data Ref #

represent a git reference (SHA1)

Instances

Eq Ref # |
Methods (==) :: Ref -> Ref -> Bool # (/=) :: Ref -> Ref -> Bool #
Data Ref # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ref -> c Ref # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Ref # toConstr :: Ref -> Constr # dataTypeOf :: Ref -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Ref) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ref) # gmapT :: (forall b. Data b => b -> b) -> Ref -> Ref # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ref -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ref -> r # gmapQ :: (forall d. Data d => d -> u) -> Ref -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ref -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ref -> m Ref # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ref -> m Ref # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ref -> m Ref #
Ord Ref # |
Methods compare :: Ref -> Ref -> Ordering # (<) :: Ref -> Ref -> Bool # (<=) :: Ref -> Ref -> Bool # (>) :: Ref -> Ref -> Bool # (>=) :: Ref -> Ref -> Bool # max :: Ref -> Ref -> Ref # min :: Ref -> Ref -> Ref #
Show Ref # |
Methods showsPrec :: Int -> Ref -> ShowS # show :: Ref -> String # showList :: [Ref] -> ShowS #

newtype RefName #

Constructors

RefName |
Fields refNameRaw :: String

Instances

Eq RefName # |
Methods (==) :: RefName -> RefName -> Bool # (/=) :: RefName -> RefName -> Bool #
Ord RefName # |
Methods compare :: RefName -> RefName -> Ordering # (<) :: RefName -> RefName -> Bool # (<=) :: RefName -> RefName -> Bool # (>) :: RefName -> RefName -> Bool # (>=) :: RefName -> RefName -> Bool # max :: RefName -> RefName -> RefName # min :: RefName -> RefName -> RefName #
Show RefName # |
Methods showsPrec :: Int -> RefName -> ShowS # show :: RefName -> String # showList :: [RefName] -> ShowS #
IsString RefName # |
Methods fromString :: String -> RefName #

data Commit #

Represent a commit object.

Constructors

Commit |
Fields commitTreeish :: Ref commitParents :: [Ref] commitAuthor :: Person commitCommitter :: Person commitEncoding :: Maybe ByteString commitExtras :: [CommitExtra] commitMessage :: ByteString

Instances

Eq Commit # |
Methods (==) :: Commit -> Commit -> Bool # (/=) :: Commit -> Commit -> Bool #
Show Commit # |
Methods showsPrec :: Int -> Commit -> ShowS # show :: Commit -> String # showList :: [Commit] -> ShowS #
Objectable Commit # |
Methods getType :: Commit -> ObjectType # getRaw :: Commit -> ByteString # isDelta :: Commit -> Bool # toObject :: Commit -> Object #

data Person #

an author or committer line has the format: name email time timezone FIXME: should be a string, but I don't know if the data is stored consistantly in one encoding (UTF8)

Constructors

Person |
Fields personName :: ByteString personEmail :: ByteString personTime :: GitTime

Instances

Eq Person # |
Methods (==) :: Person -> Person -> Bool # (/=) :: Person -> Person -> Bool #
Show Person # |
Methods showsPrec :: Int -> Person -> ShowS # show :: Person -> String # showList :: [Person] -> ShowS #

data CommitExtra #

Constructors

CommitExtra |
Fields commitExtraKey :: ByteString commitExtraValue :: ByteString

Instances

Eq CommitExtra # |
Methods (==) :: CommitExtra -> CommitExtra -> Bool # (/=) :: CommitExtra -> CommitExtra -> Bool #
Show CommitExtra # |
Methods showsPrec :: Int -> CommitExtra -> ShowS # show :: CommitExtra -> String # showList :: [CommitExtra] -> ShowS #

data Tree #

Represent a root tree with zero to many tree entries.

Constructors

Tree |
Fields treeGetEnts :: [TreeEnt]

Instances

Eq Tree # |
Methods (==) :: Tree -> Tree -> Bool # (/=) :: Tree -> Tree -> Bool #
Show Tree # |
Methods showsPrec :: Int -> Tree -> ShowS # show :: Tree -> String # showList :: [Tree] -> ShowS #
Monoid Tree # |
Methods mempty :: Tree # mappend :: Tree -> Tree -> Tree # mconcat :: [Tree] -> Tree #
Objectable Tree # |
Methods getType :: Tree -> ObjectType # getRaw :: Tree -> ByteString # isDelta :: Tree -> Bool # toObject :: Tree -> Object #

data Blob #

Represent a binary blob.

Constructors

Blob |
Fields blobGetContent :: ByteString

Instances

Eq Blob # |
Methods (==) :: Blob -> Blob -> Bool # (/=) :: Blob -> Blob -> Bool #
Show Blob # |
Methods showsPrec :: Int -> Blob -> ShowS # show :: Blob -> String # showList :: [Blob] -> ShowS #
Objectable Blob # |
Methods getType :: Blob -> ObjectType # getRaw :: Blob -> ByteString # isDelta :: Blob -> Bool # toObject :: Blob -> Object #

data Tag #

Represent a signed tag.

Constructors

Tag |
Fields tagRef :: Ref tagObjectType :: ObjectType tagBlob :: ByteString tagName :: Person tagS :: ByteString

Instances

Eq Tag # |
Methods (==) :: Tag -> Tag -> Bool # (/=) :: Tag -> Tag -> Bool #
Show Tag # |
Methods showsPrec :: Int -> Tag -> ShowS # show :: Tag -> String # showList :: [Tag] -> ShowS #
Objectable Tag # |
Methods getType :: Tag -> ObjectType # getRaw :: Tag -> ByteString # isDelta :: Tag -> Bool # toObject :: Tag -> Object #

data GitTime #

Git time is number of seconds since unix epoch in the UTC zone with the current timezone associated

Instances

Eq GitTime # |
Methods (==) :: GitTime -> GitTime -> Bool # (/=) :: GitTime -> GitTime -> Bool #
Show GitTime # |
Methods showsPrec :: Int -> GitTime -> ShowS # show :: GitTime -> String # showList :: [GitTime] -> ShowS #
Timeable GitTime # |
Methods timeGetElapsedP :: GitTime -> ElapsedP # timeGetElapsed :: GitTime -> Elapsed # timeGetNanoSeconds :: GitTime -> NanoSeconds #
Time GitTime # |
Methods timeFromElapsedP :: ElapsedP -> GitTime # timeFromElapsed :: Elapsed -> GitTime #

newtype ModePerm #

Constructors

ModePerm Word32 |

Instances

Eq ModePerm # |
Methods (==) :: ModePerm -> ModePerm -> Bool # (/=) :: ModePerm -> ModePerm -> Bool #
Show ModePerm # |
Methods showsPrec :: Int -> ModePerm -> ShowS # show :: ModePerm -> String # showList :: [ModePerm] -> ShowS #

data EntName #

Entity name

Instances

Eq EntName # |
Methods (==) :: EntName -> EntName -> Bool # (/=) :: EntName -> EntName -> Bool #
Ord EntName # |
Methods compare :: EntName -> EntName -> Ordering # (<) :: EntName -> EntName -> Bool # (<=) :: EntName -> EntName -> Bool # (>) :: EntName -> EntName -> Bool # (>=) :: EntName -> EntName -> Bool # max :: EntName -> EntName -> EntName # min :: EntName -> EntName -> EntName #
Show EntName # |
Methods showsPrec :: Int -> EntName -> ShowS # show :: EntName -> String # showList :: [EntName] -> ShowS #
IsString EntName # |
Methods fromString :: String -> EntName #
Byteable EntName # |
Methods toBytes :: EntName -> ByteString # byteableLength :: EntName -> Int # withBytePtr :: EntName -> (Ptr Word8 -> IO b) -> IO b #

type EntPath = [EntName] #

entName :: ByteString -> EntName #

entPathAppend :: EntPath -> EntName -> EntPath #

# Helper & type related to ModePerm

data ObjectFileType #

Git object file type

Constructors

FileTypeDirectory |
FileTypeRegularFile |
FileTypeSymbolicLink |
FileTypeGitLink |

Instances

Eq ObjectFileType # |
Methods (==) :: ObjectFileType -> ObjectFileType -> Bool # (/=) :: ObjectFileType -> ObjectFileType -> Bool #
Show ObjectFileType # |
Methods showsPrec :: Int -> ObjectFileType -> ShowS # show :: ObjectFileType -> String # showList :: [ObjectFileType] -> ShowS #

data FilePermissions #

traditional unix permission for owner, group and permissions

Constructors

FilePermissions |
Fields getOwnerPerm :: !Perm getGroupPerm :: !Perm getOtherPerm :: !Perm

Instances

Eq FilePermissions # |
Methods (==) :: FilePermissions -> FilePermissions -> Bool # (/=) :: FilePermissions -> FilePermissions -> Bool #
Show FilePermissions # |
Methods showsPrec :: Int -> FilePermissions -> ShowS # show :: FilePermissions -> String # showList :: [FilePermissions] -> ShowS #

getPermission :: ModePerm -> FilePermissions #

getFiletype :: ModePerm -> ObjectFileType #

# Revision

data Revision #

A git revision. this can be many things: * a shorten ref * a ref * a named branch or tag followed by optional modifiers `RevModifier` that can represent: * parenting * type * date

Instances

Eq Revision # |
Methods (==) :: Revision -> Revision -> Bool # (/=) :: Revision -> Revision -> Bool #
Data Revision # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Revision -> c Revision # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Revision # toConstr :: Revision -> Constr # dataTypeOf :: Revision -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Revision) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Revision) # gmapT :: (forall b. Data b => b -> b) -> Revision -> Revision # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Revision -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Revision -> r # gmapQ :: (forall d. Data d => d -> u) -> Revision -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Revision -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Revision -> m Revision # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Revision -> m Revision # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Revision -> m Revision #
Show Revision # |
Methods showsPrec :: Int -> Revision -> ShowS # show :: Revision -> String # showList :: [Revision] -> ShowS #
IsString Revision # |
Methods fromString :: String -> Revision #

resolveRevision :: Git -> Revision -> IO (Maybe Ref) #

try to resolve a string to a specific commit ref for example: HEAD, HEAD^, master~3, shortRef

# Object resolution

resolveTreeish :: Git -> Ref -> IO (Maybe Tree) #

returns a tree from a ref that might be either a commit, a tree or a tag.

resolvePath #

Arguments

:: Git | repository
-> Ref | commit reference
-> EntPath | paths
-> IO (Maybe Ref) |

resolve the ref (tree or blob) related to a path at a specific commit ref

# repo context

data Git #

represent a git repo, with possibly already opened filereaders for indexes and packs

withCurrentRepo :: (Git -> IO a) -> IO a #

execute a function on the current repository.

check findRepo to see how the git repository is found.

withRepo :: FilePath -> (Git -> IO c) -> IO c #

execute a function f with a git context.

findRepo :: IO FilePath #

Find the git repository from the current directory.

If the environment variable GIT_DIR is set then it's used, otherwise iterate from current directory, up to 128 parents for a .git directory

# Repository queries and creation

initRepo :: FilePath -> IO () #

initialize a new repository at a specific location.

isRepo :: FilePath -> IO Bool #

basic checks to see if a specific path looks like a git repo.

# Context operations

rewrite #

Arguments

:: Git | Repository
-> (Commit -> IO Commit) | Mapping function
-> Revision | revision to start from
-> Int | the number of parents to map
-> IO Ref | return the new head REF

Rewrite a set of commits from a revision and returns the new ref.

If during revision traversal (diving) there's a commit with zero or multiple parents then the traversal will stop regardless of the amount of parent requested.

calling "rewrite f 2 (revisionOf d)" on the following tree:

a <-- b <-- c <-- d

result in the following tree after mapping with f:

a <-- f(b) <-- f(c) <-- f(d)

# Get objects

getObject #

Arguments

:: Git | repository
-> Ref | the object's reference to
-> Bool | whether to resolve deltas if found
-> IO (Maybe Object) | returned object if found

get an object from repository using a ref.

getCommit :: Git -> Ref -> IO Commit #

get a specified commit but raises an exception if doesn't exists or type is not appropriate

getTree :: Git -> Ref -> IO Tree #

get a specified tree but raise

# Set objects

setObject :: Git -> Object -> IO Ref #

set an object in the store and returns the new ref this is always going to create a loose object.

toObject :: Objectable a => a -> Object #

# Work trees

type WorkTree = MVar TreeSt #

data EntType #

Constructors

EntDirectory |
EntFile |
EntExecutable |

Instances

Eq EntType # |
Methods (==) :: EntType -> EntType -> Bool # (/=) :: EntType -> EntType -> Bool #
Show EntType # |
Methods showsPrec :: Int -> EntType -> ShowS # show :: EntType -> String # showList :: [EntType] -> ShowS #

workTreeNew :: IO WorkTree #

Create a new worktree

workTreeFrom :: Ref -> IO WorkTree #

Create a worktree from a tree reference.

workTreeDelete :: Git -> WorkTree -> EntPath -> IO () #

delete a path from a working tree

if the path doesn't exist, no error is raised

workTreeSet :: Git -> WorkTree -> EntPath -> (EntType, Ref) -> IO () #

Set a file in this working tree to a specific ref.

The ref should point to a valid blob or tree object, and it's safer to write the referenced tree or blob object first.

workTreeFlush :: Git -> WorkTree -> IO Ref #

Flush the worktree by creating all the necessary trees in the git store and return the root ref of the work tree.

# Named refs

branchWrite #

Arguments

:: Git | repository
-> RefName | the name of the branch to write
-> Ref | the reference to set
-> IO () |

Write a branch to point to a specific reference

branchList :: Git -> IO (Set RefName) #

Return the list of branches

tagWrite #

Arguments

:: Git | repository
-> RefName | the name of the tag to write
-> Ref | the reference to set
-> IO () |

Write a tag to point to a specific reference

tagList :: Git -> IO (Set RefName) #

Return the list of branches

headSet #

Arguments

:: Git | repository
-> Either Ref RefName | either a raw reference or a branch name
-> IO () |

Set head to point to either a reference or a branch name.

headGet :: Git -> IO (Either Ref RefName) #

Get what the head is pointing to, or the reference otherwise