git_diff_parser

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 5 Imported by: 4 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnhandled = errors.New("unhandled git diff syntax")

Functions

func SignificantChange

func SignificantChange(diff string, isSignificant func(*FileDiff, *ContentChange) (bool, string)) (bool, string, error)

SignificantChange Allows a structured diff to be passed into the `isSignificant` function to determine significance. That function can return a message, which is optionally passed as the final argument Returns the first significant change found, or false if non found.

Types

type BinaryDeltaType

type BinaryDeltaType string
const (
	BinaryDeltaTypeLiteral BinaryDeltaType = "literal"
	BinaryDeltaTypeDelta   BinaryDeltaType = "delta"
)

type BinaryPatch

type BinaryPatch struct {
	Type    BinaryDeltaType `json:"type"`
	Count   int
	Content string
}

type ChangeList

type ChangeList []ContentChange

func (*ChangeList) IsSignificant

func (changes *ChangeList) IsSignificant() bool

type ContentChange

type ContentChange struct {
	Type ContentChangeType `json:"type"`
	From string            `json:"from"`
	To   string            `json:"to"`
}

ContentChange is a part of the line that starts with ` `, `-`, `+` Consecutive ContentChange build a line. A `~` is a special case of ContentChange that is used to indicate a new line.

type ContentChangeType

type ContentChangeType string
const (
	ContentChangeTypeAdd    ContentChangeType = "add"
	ContentChangeTypeDelete ContentChangeType = "delete"
	ContentChangeTypeModify ContentChangeType = "modify"
	ContentChangeTypeNOOP   ContentChangeType = ""
)

type Diff

type Diff struct {
	FileDiff []FileDiff `json:"file_diff"`
}

func Parse

func Parse(diff string) (Diff, []error)

Converts git diff --word-diff=porcelain output to a Diff object.

type FileDiff

type FileDiff struct {
	FromFile    string        `json:"from_file"`
	ToFile      string        `json:"to_file"`
	Type        FileDiffType  `json:"type"`
	IsBinary    bool          `json:"is_binary"`
	NewMode     string        `json:"new_mode"`
	Hunks       []Hunk        `json:"hunks"`
	BinaryPatch []BinaryPatch `json:"binary_patch"`
}

FileDiff Source of truth: https://github.com/git/git/blob/master/diffcore.h#L106 Implemented in https://github.com/git/git/blob/master/diff.c#L3496

type FileDiffType

type FileDiffType string
const (
	FileDiffTypeAdded    FileDiffType = "add"
	FileDiffTypeDeleted  FileDiffType = "delete"
	FileDiffTypeModified FileDiffType = "modify"
)

type Hunk

type Hunk struct {
	ChangeList         ChangeList `json:"change_list"`
	StartLineNumberOld int        `json:"start_line_number_old"`
	CountOld           int        `json:"count_old"`
	StartLineNumberNew int        `json:"start_line_number_new"`
	CountNew           int        `json:"count_new"`
}

Hunk is a line that starts with @@. Each hunk shows one area where the files differ Unified format hunks look like this: @@ from-file-line-numbers to-file-line-numbers @@

line-from-either-file
line-from-either-file…

If a hunk contains just one line, only its start line number appears. Otherwise its line numbers look like ‘start,count’. An empty hunk is considered to start at the line that follows the hunk.

func NewHunk

func NewHunk(line string) (Hunk, error)

type ParserMode

type ParserMode int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL