This is a library to assist the parsing of git diff
output and subsequent display.
fromString : String -> Result Error (List Diff)
Parse the full output of git diff
.
A diff for a single file. There may be several
of these in a single git diff
output.
Note: This does not include all possible modes, like changing permissions of file, symlinks etc. If you need that though, you're welcome to add it.
{ path : Path
, commit : Hash
, chunks : List Chunk
}
{ path : Path
, commit : Hash
, chunks : List Chunk
}
{ path : Path
, commit1 : Hash
, commit2 : Hash
, chunks : List Chunk
}
{ from : Path
, to : Path
, similarity : Basics.Int
, commit1 : Hash
, commit2 : Hash
, chunks : List Chunk
}
{ lineNum1 : Basics.Int
, lineCount1 : Basics.Int
, lineNum2 : Basics.Int
, lineCount2 : Basics.Int
, changes : List ( Action
, List Word )
}
The diff is parsed as Elm code. This incidentally
also works fairly well for JSON. For any other file extensions
other than .elm and .json, the line of code is just left in its
entirety in the Other
type.
Since we're working with diffs, this is meant to parse incomplete code. There are thus certain limits for highlighting as we don't have access to the full code. E.g. it is difficult (sometimes impossible) to highlight multiline comments / quotes correctly. This has thus been omitted.
String
String
{ subject : String
, message : String
}
The parser error. The subject
is what has
been parsed, and the message is what went wrong.
You shouldn't run into this if you're parsing correct diffs, but if there are any bugs in the parser, this output is helpful.
You can display it using Ui.Diff.viewError
.
toPath : Diff -> Path
Helper to get the path for the diff. In the case of renames, this is the latest path.
toChunks : Diff -> List Chunk
Helper to get the diff chunks.