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 Source

represent a git reference (SHA1)

Instances

Eq Ref Source |
Data Ref Source |
Ord Ref Source |
Show Ref Source |

newtype RefName Source

Constructors

RefName |

Fields

refNameRaw :: String

Instances

Eq RefName Source |
Ord RefName Source |
Show RefName Source |
IsString RefName Source |

data Commit Source

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 Source |
Show Commit Source |
Objectable Commit Source |

data Person Source

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 Source |
Show Person Source |

data CommitExtra Source

Constructors

CommitExtra |

Fields

commitExtraKey :: ByteString
commitExtraValue :: ByteString

Instances

Eq CommitExtra Source |
Show CommitExtra Source |

data Tree Source

Represent a root tree with zero to many tree entries.

Constructors

Tree |

Fields

treeGetEnts :: [TreeEnt]

Instances

Eq Tree Source |
Show Tree Source |
Monoid Tree Source |
Objectable Tree Source |

data Blob Source

Represent a binary blob.

Constructors

Blob |

Fields

blobGetContent :: ByteString

Instances

Eq Blob Source |
Show Blob Source |
Objectable Blob Source |

data Tag Source

Represent a signed tag.

Constructors

Tag |

Fields

tagRef :: Ref
tagObjectType :: ObjectType
tagBlob :: ByteString
tagName :: Person
tagS :: ByteString

Instances

Eq Tag Source |
Show Tag Source |
Objectable Tag Source |

data GitTime Source

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

Instances

Eq GitTime Source |
Show GitTime Source |
Timeable GitTime Source |
Time GitTime Source |

newtype ModePerm Source

Constructors

ModePerm Word32 |

Instances

Eq ModePerm Source |
Show ModePerm Source |

data EntName Source

Entity name

Instances

Eq EntName Source |
Ord EntName Source |
Show EntName Source |
IsString EntName Source |
Byteable EntName Source |

type EntPath = [EntName] Source

entName :: ByteString -> EntName Source

entPathAppend :: EntPath -> EntName -> EntPath Source

# Helper & type related to ModePerm

data ObjectFileType Source

Git object file type

Constructors

FileTypeDirectory |
FileTypeRegularFile |
FileTypeSymbolicLink |
FileTypeGitLink |

Instances

Eq ObjectFileType Source |
Show ObjectFileType Source |

data FilePermissions Source

traditional unix permission for owner, group and permissions

Constructors

FilePermissions |

Fields

getOwnerPerm :: !Perm
getGroupPerm :: !Perm
getOtherPerm :: !Perm

Instances

Eq FilePermissions Source |
Show FilePermissions Source |

getPermission :: ModePerm -> FilePermissions Source

getFiletype :: ModePerm -> ObjectFileType Source

# Revision

data Revision Source

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 Source |
Data Revision Source |
Show Revision Source |
IsString Revision Source |

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

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) Source

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

resolvePath Source

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 Source

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

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

execute a function on the current repository.

check findRepo to see how the git repository is found.

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

execute a function f with a git context.

findRepo :: IO FilePath Source

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 () Source

initialize a new repository at a specific location.

isRepo :: FilePath -> IO Bool Source

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

# Context operations

rewrite Source

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 Source

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 Source

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

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

get a specified tree but raise

# Set objects

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

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 Source

# Work trees

type WorkTree = MVar TreeSt Source

data EntType Source

Constructors

EntDirectory |
EntFile |
EntExecutable |

Instances

Eq EntType Source |
Show EntType Source |

workTreeNew :: IO WorkTree Source

Create a new worktree

workTreeFrom :: Ref -> IO WorkTree Source

Create a worktree from a tree reference.

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

delete a path from a working tree

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

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

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 Source

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 Source

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) Source

Return the list of branches

tagWrite Source

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) Source

Return the list of branches

headSet Source

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) Source

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