Documentation ¶
Index ¶
- func ExpandRange(start int, end int) []int
- type FormatViewOpts
- type Hunk
- type Patch
- func (self *Patch) AdjustLineNumber(lineNumber int) int
- func (self *Patch) ContainsChanges() bool
- func (self *Patch) FormatPlain() string
- func (self *Patch) FormatRangePlain(startIdx int, endIdx int) string
- func (self *Patch) FormatView(opts FormatViewOpts) string
- func (self *Patch) GetNextChangeIdx(idx int) int
- func (self *Patch) HunkContainingLine(idx int) int
- func (self *Patch) HunkCount() int
- func (self *Patch) HunkEndIdx(hunkIndex int) int
- func (self *Patch) HunkStartIdx(hunkIndex int) int
- func (self *Patch) LineCount() int
- func (self *Patch) LineNumberOfLine(idx int) int
- func (self *Patch) Lines() []*PatchLine
- func (self *Patch) Transform(opts TransformOpts) *Patch
- type PatchBuilder
- func (p *PatchBuilder) Active() bool
- func (p *PatchBuilder) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
- func (p *PatchBuilder) AddFileWhole(filename string) error
- func (p *PatchBuilder) AllFilesInPatch() []string
- func (p *PatchBuilder) GetFileIncLineIndices(filename string) ([]int, error)
- func (p *PatchBuilder) GetFileStatus(filename string, parent string) PatchStatus
- func (p *PatchBuilder) IsEmpty() bool
- func (p *PatchBuilder) NewPatchRequired(from string, to string, reverse bool) bool
- func (p *PatchBuilder) PatchToApply(reverse bool, turnAddedFilesIntoDiffAgainstEmptyFile bool) string
- func (p *PatchBuilder) RemoveFile(filename string) error
- func (p *PatchBuilder) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
- func (p *PatchBuilder) RenderAggregatedPatch(plain bool) string
- func (p *PatchBuilder) RenderPatchForFile(opts RenderPatchForFileOpts) string
- func (p *PatchBuilder) Reset()
- func (p *PatchBuilder) Start(from, to string, reverse bool, canRebase bool)
- type PatchLine
- type PatchLineKind
- type PatchStatus
- type RenderPatchForFileOpts
- type TransformOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandRange ¶ added in v0.38.0
helper function that takes a start and end index and returns a slice of all indexes inbetween (inclusive)
Types ¶
type FormatViewOpts ¶ added in v0.38.0
type Patch ¶ added in v0.38.0
type Patch struct {
// contains filtered or unexported fields
}
func (*Patch) AdjustLineNumber ¶ added in v0.45.0
Adjust the given line number (one-based) according to the current patch. The patch is supposed to be a diff of an old file state against the working directory; the line number is a line number in that old file, and the function returns the corresponding line number in the working directory file.
func (*Patch) ContainsChanges ¶ added in v0.38.0
func (*Patch) FormatPlain ¶ added in v0.38.0
Returns the patch as a plain string
func (*Patch) FormatRangePlain ¶ added in v0.38.0
Returns a range of lines from the patch as a plain string (range is inclusive)
func (*Patch) FormatView ¶ added in v0.38.0
func (self *Patch) FormatView(opts FormatViewOpts) string
Returns the patch as a string with ANSI color codes for displaying in a view
func (*Patch) GetNextChangeIdx ¶ added in v0.38.0
Returns the patch line index of the next change (i.e. addition or deletion).
func (*Patch) HunkContainingLine ¶ added in v0.38.0
Returns hunk index containing the line at the given patch line index
func (*Patch) HunkEndIdx ¶ added in v0.38.0
Returns the patch line index of the last line in the given hunk
func (*Patch) HunkStartIdx ¶ added in v0.38.0
Returns the patch line index of the first line in the given hunk
func (*Patch) LineNumberOfLine ¶ added in v0.38.0
Takes a line index in the patch and returns the line number in the new file. If the line is a header line, returns 1. If the line is a hunk header line, returns the first file line number in that hunk. If the line is out of range below, returns the last file line number in the last hunk.
func (*Patch) Transform ¶ added in v0.38.0
func (self *Patch) Transform(opts TransformOpts) *Patch
Returns a new patch with the specified transformation applied (e.g. only selecting a subset of changes). Leaves the original patch unchanged.
type PatchBuilder ¶ added in v0.38.0
type PatchBuilder struct { // To is the commit hash if we're dealing with files of a commit, or a stash ref for a stash To string From string // CanRebase tells us whether we're allowed to modify our commits. CanRebase should be true for commits of the currently checked out branch and false for everything else // TODO: move this out into a proper mode struct in the gui package: it doesn't really belong here CanRebase bool Log *logrus.Entry // contains filtered or unexported fields }
PatchBuilder manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility
func NewPatchBuilder ¶ added in v0.38.0
func NewPatchBuilder(log *logrus.Entry, loadFileDiff loadFileDiffFunc) *PatchBuilder
func (*PatchBuilder) Active ¶ added in v0.38.0
func (p *PatchBuilder) Active() bool
func (*PatchBuilder) AddFileLineRange ¶ added in v0.38.0
func (p *PatchBuilder) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
func (*PatchBuilder) AddFileWhole ¶ added in v0.38.0
func (p *PatchBuilder) AddFileWhole(filename string) error
func (*PatchBuilder) AllFilesInPatch ¶ added in v0.38.0
func (p *PatchBuilder) AllFilesInPatch() []string
func (*PatchBuilder) GetFileIncLineIndices ¶ added in v0.38.0
func (p *PatchBuilder) GetFileIncLineIndices(filename string) ([]int, error)
func (*PatchBuilder) GetFileStatus ¶ added in v0.38.0
func (p *PatchBuilder) GetFileStatus(filename string, parent string) PatchStatus
func (*PatchBuilder) IsEmpty ¶ added in v0.38.0
func (p *PatchBuilder) IsEmpty() bool
func (*PatchBuilder) NewPatchRequired ¶ added in v0.38.0
func (p *PatchBuilder) NewPatchRequired(from string, to string, reverse bool) bool
if any of these things change we'll need to reset and start a new patch
func (*PatchBuilder) PatchToApply ¶ added in v0.39.0
func (p *PatchBuilder) PatchToApply(reverse bool, turnAddedFilesIntoDiffAgainstEmptyFile bool) string
func (*PatchBuilder) RemoveFile ¶ added in v0.38.0
func (p *PatchBuilder) RemoveFile(filename string) error
func (*PatchBuilder) RemoveFileLineRange ¶ added in v0.38.0
func (p *PatchBuilder) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
func (*PatchBuilder) RenderAggregatedPatch ¶ added in v0.38.0
func (p *PatchBuilder) RenderAggregatedPatch(plain bool) string
func (*PatchBuilder) RenderPatchForFile ¶ added in v0.38.0
func (p *PatchBuilder) RenderPatchForFile(opts RenderPatchForFileOpts) string
type PatchLine ¶
type PatchLine struct { Kind PatchLineKind Content string // something like '+ hello' (note the first character is not removed) }
type PatchLineKind ¶ added in v0.27.1
type PatchLineKind int
const ( PATCH_HEADER PatchLineKind = iota HUNK_HEADER ADDITION DELETION CONTEXT NEWLINE_MESSAGE )
type PatchStatus ¶ added in v0.27.1
type PatchStatus int
const ( // UNSELECTED is for when the commit file has not been added to the patch in any way UNSELECTED PatchStatus = iota // WHOLE is for when you want to add the whole diff of a file to the patch, // including e.g. if it was deleted WHOLE // PART is for when you're only talking about specific lines that have been modified PART )
type RenderPatchForFileOpts ¶ added in v0.43.0
type TransformOpts ¶ added in v0.38.0
type TransformOpts struct { // Create a patch that will applied in reverse with `git apply --reverse`. // This affects how unselected lines are treated when only parts of a hunk // are selected: usually, for unselected lines we change '-' lines to // context lines and remove '+' lines, but when Reverse is true we need to // turn '+' lines into context lines and remove '-' lines. Reverse bool // If set, we will replace the original header with one referring to this file name. // For staging/unstaging lines we don't want the original header because // it makes git confused e.g. when dealing with deleted/added files // but with building and applying patches the original header gives git // information it needs to cleanly apply patches FileNameOverride string // Custom patches tend to work better when treating new files as diffs // against an empty file. The only case where we need this to be false is // when moving a custom patch to an earlier commit; in that case the patch // command would fail with the error "file does not exist in index" if we // treat it as a diff against an empty file. TurnAddedFilesIntoDiffAgainstEmptyFile bool // The indices of lines that should be included in the patch. IncludedLineIndices []int }