hit-0.6.3: Git operations in haskell

License | BSD-style
Maintainer | Nicolas DI PRIMA <nicolas@di-prima.fr>
Stability | experimental
Portability | unix
Safe Haskell | None
Language | Haskell98

Data.Git.Diff

Contents

- Basic features
- Default helpers

Description

Basic Git diff methods.

Synopsis

- data BlobContent
  - = FileContent [ByteString]
  - | BinaryContent ByteString
- data BlobState = BlobState {
  - bsFilename :: EntPath
  - bsMode :: ModePerm
  - bsRef :: Ref
  - bsContent :: BlobContent
  }
- data BlobStateDiff
  - = OnlyOld BlobState
  - | OnlyNew BlobState
  - | OldAndNew BlobState BlobState
- getDiffWith :: (BlobStateDiff -> a -> a) -> a -> Ref -> Ref -> Git -> IO a
- data HitDiff = HitDiff {
  - hFileName :: EntPath
  - hFileContent :: HitFileContent
  - hFileMode :: HitFileMode
  - hFileRef :: HitFileRef
  }
- data HitFileContent
  - = NewBinaryFile
  - | OldBinaryFile
  - | NewTextFile [TextLine]
  - | OldTextFile [TextLine]
  - | ModifiedBinaryFile
  - | ModifiedFile [FilteredDiff]
  - | UnModifiedFile
- data FilteredDiff
  - = NormalLine (Item TextLine)
  - | Separator
- data HitFileRef
  - = NewRef Ref
  - | OldRef Ref
  - | ModifiedRef Ref Ref
  - | UnModifiedRef Ref
- data HitFileMode
  - = NewMode ModePerm
  - | OldMode ModePerm
  - | ModifiedMode ModePerm ModePerm
  - | UnModifiedMode ModePerm
- data TextLine = TextLine {
  - lineNumber :: Integer
  - lineContent :: ByteString
  }
- defaultDiff :: Int -> BlobStateDiff -> [HitDiff] -> [HitDiff]
- getDiff :: Ref -> Ref -> Git -> IO [HitDiff]

# Basic features

data BlobContent Source #

represents a blob's content (i.e., the content of a file at a given reference).

Constructors

FileContent [ByteString] | Text file's lines
BinaryContent ByteString | Binary content

Instances

Show BlobContent Source # |
Methods showsPrec :: Int -> BlobContent -> ShowS # show :: BlobContent -> String # showList :: [BlobContent] -> ShowS #

data BlobState Source #

This is a blob description at a given state (revision)

Constructors

BlobState |

Fields

- bsFilename :: EntPath
- bsMode :: ModePerm
- bsRef :: Ref
- bsContent :: BlobContent

Instances

Eq BlobState Source #

Two `BlobState` are equal if they have the same filename, i.e.,

    ((BlobState x _ _ _) == (BlobState y _ _ _)) = (x == y)

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

data BlobStateDiff Source #

Represents a file state between two revisions A file (a blob) can be present in the first Tree's revision but not in the second one, then it has been deleted. If only in the second Tree's revision, then it has been created. If it is in the both, maybe it has been changed.

Constructors

OnlyOld BlobState |
OnlyNew BlobState |
OldAndNew BlobState BlobState |

getDiffWith Source #

Arguments

:: (BlobStateDiff -> a -> a) | diff helper (State -> accumulator -> accumulator)
-> a | accumulator
-> Ref | commit reference (the original state)
-> Ref | commit reference (the new state)
-> Git | repository
-> IO a |

generate a diff list between two revisions with a given diff helper.

Useful to extract any kind of information from two different revisions. For example you can get the number of deleted files:

    getdiffwith f 0 head^ head git
        where f (OnlyOld _) acc = acc+1
              f _           acc = acc

Or save the list of new files:

    getdiffwith f [] head^ head git
        where f (OnlyNew bs) acc = (bsFilename bs):acc
              f _            acc = acc

# Default helpers

data HitDiff Source #

This is a proposed diff records for a given file. It contains useful information: * the filename (with its path in the root project) * a file diff (with the Data.Algorithm.Patience method) * the file's mode (i.e. the file priviledge) * the file's ref

Constructors

HitDiff |

Fields

- hFileName :: EntPath
- hFileContent :: HitFileContent
- hFileMode :: HitFileMode
- hFileRef :: HitFileRef

data HitFileContent Source #

Constructors

NewBinaryFile |
OldBinaryFile |
NewTextFile [TextLine] |
OldTextFile [TextLine] |
ModifiedBinaryFile |
ModifiedFile [FilteredDiff] |
UnModifiedFile |

data FilteredDiff Source #

Constructors

NormalLine (Item TextLine) |
Separator |

data HitFileRef Source #

Constructors

NewRef Ref |
OldRef Ref |
ModifiedRef Ref Ref |
UnModifiedRef Ref |

data HitFileMode Source #

Constructors

NewMode ModePerm |
OldMode ModePerm |
ModifiedMode ModePerm ModePerm |
UnModifiedMode ModePerm |

data TextLine Source #

Constructors

TextLine |

Fields

- lineNumber :: Integer
- lineContent :: ByteString

Instances

Eq TextLine Source # |
Methods (==) :: TextLine -> TextLine -> Bool # (/=) :: TextLine -> TextLine -> Bool #
Ord TextLine Source # |
Methods compare :: TextLine -> TextLine -> Ordering # (<) :: TextLine -> TextLine -> Bool # (<=) :: TextLine -> TextLine -> Bool # (>) :: TextLine -> TextLine -> Bool # (>=) :: TextLine -> TextLine -> Bool # max :: TextLine -> TextLine -> TextLine # min :: TextLine -> TextLine -> TextLine #

defaultDiff Source #

Arguments

:: Int | Number of line for context
-> BlobStateDiff |
-> [HitDiff] | Accumulator
-> [HitDiff] | Accumulator with a new content

A default diff helper. It is an example about how you can write your own diff helper or you can use it if you want to get all of differences.

getDiff :: Ref -> Ref -> Git -> IO [HitDiff] Source #

A default Diff getter which returns all diff information (Mode, Content and Binary) with a context of 5 lines.

    getDiff = getDiffWith (defaultDiff 5) []