Documentation ¶
Index ¶
- func GetHeaderFromDiff(diff string) string
- func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string, includedLineIndices []int, ...) string
- func ModifiedPatchForRange(log *logrus.Entry, filename string, diffText string, firstLineIdx int, ...) string
- type PatchHunk
- type PatchLine
- type PatchLineKind
- type PatchManager
- func (p *PatchManager) Active() bool
- func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
- func (p *PatchManager) AddFileWhole(filename string) error
- func (p *PatchManager) ApplyPatches(reverse bool) error
- func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error)
- func (p *PatchManager) GetFileStatus(filename string, parent string) PatchStatus
- func (p *PatchManager) IsEmpty() bool
- func (p *PatchManager) NewPatchRequired(from string, to string, reverse bool) bool
- func (p *PatchManager) RemoveFile(filename string) error
- func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
- func (p *PatchManager) RenderAggregatedPatchColored(plain bool) string
- func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool, keepOriginalHeader bool) string
- func (p *PatchManager) Reset()
- func (p *PatchManager) Start(from, to string, reverse bool, canRebase bool)
- type PatchModifier
- type PatchParser
- func (p *PatchParser) GetHunkContainingLine(lineIndex int, offset int) *PatchHunk
- func (p *PatchParser) GetNextStageableLineIndex(currentIndex int) int
- func (p *PatchParser) PlainRenderLines(firstLineIndex, lastLineIndex int) string
- func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndices []int) string
- type PatchStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHeaderFromDiff ¶
func ModifiedPatchForLines ¶
Types ¶
type PatchHunk ¶
type PatchHunk struct { FirstLineIdx int // contains filtered or unexported fields }
func GetHunksFromDiff ¶
func (*PatchHunk) LastLineIdx ¶
func (*PatchHunk) LineNumberOfLine ¶
I want to know, given a hunk, what line a given index is on
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 COMMIT_SHA COMMIT_DESCRIPTION HUNK_HEADER ADDITION DELETION CONTEXT NEWLINE_MESSAGE )
type PatchManager ¶
type PatchManager struct { // To is the commit sha if we're dealing with files of a commit, or a stash ref for a stash To string From string Reverse bool // 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 ApplyPatch applyPatchFunc // LoadFileDiff loads the diff of a file, for a given to (typically a commit SHA) LoadFileDiff loadFileDiffFunc // contains filtered or unexported fields }
PatchManager 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 NewPatchManager ¶
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc, loadFileDiff loadFileDiffFunc) *PatchManager
NewPatchManager returns a new PatchManager
func (*PatchManager) Active ¶
func (p *PatchManager) Active() bool
func (*PatchManager) AddFileLineRange ¶
func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
func (*PatchManager) AddFileWhole ¶ added in v0.27.1
func (p *PatchManager) AddFileWhole(filename string) error
func (*PatchManager) ApplyPatches ¶
func (p *PatchManager) ApplyPatches(reverse bool) error
func (*PatchManager) GetFileIncLineIndices ¶
func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error)
func (*PatchManager) GetFileStatus ¶
func (p *PatchManager) GetFileStatus(filename string, parent string) PatchStatus
func (*PatchManager) IsEmpty ¶
func (p *PatchManager) IsEmpty() bool
func (*PatchManager) NewPatchRequired ¶
func (p *PatchManager) 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 (*PatchManager) RemoveFile ¶ added in v0.27.1
func (p *PatchManager) RemoveFile(filename string) error
func (*PatchManager) RemoveFileLineRange ¶
func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
func (*PatchManager) RenderAggregatedPatchColored ¶
func (p *PatchManager) RenderAggregatedPatchColored(plain bool) string
func (*PatchManager) RenderPatchForFile ¶
type PatchModifier ¶
func NewPatchModifier ¶
func NewPatchModifier(log *logrus.Entry, filename string, diffText string) *PatchModifier
func (*PatchModifier) ModifiedPatchForLines ¶
func (d *PatchModifier) ModifiedPatchForLines(lineIndices []int, reverse bool, keepOriginalHeader bool) string
func (*PatchModifier) ModifiedPatchForRange ¶
func (*PatchModifier) OriginalPatchLength ¶
func (d *PatchModifier) OriginalPatchLength() int
type PatchParser ¶
type PatchParser struct { Log *logrus.Entry PatchLines []*PatchLine PatchHunks []*PatchHunk HunkStarts []int StageableLines []int // rename to mention we're talking about indexes }
func NewPatchParser ¶
func NewPatchParser(log *logrus.Entry, patch string) *PatchParser
NewPatchParser builds a new branch list builder
func (*PatchParser) GetHunkContainingLine ¶
func (p *PatchParser) GetHunkContainingLine(lineIndex int, offset int) *PatchHunk
GetHunkContainingLine takes a line index and an offset and finds the hunk which contains the line index, then returns the hunk considering the offset. e.g. if the offset is 1 it will return the next hunk.
func (*PatchParser) GetNextStageableLineIndex ¶
func (p *PatchParser) GetNextStageableLineIndex(currentIndex int) int
GetNextStageableLineIndex takes a line index and returns the line index of the next stageable line note this will actually include the current index if it is stageable
func (*PatchParser) PlainRenderLines ¶ added in v0.30.1
func (p *PatchParser) PlainRenderLines(firstLineIndex, lastLineIndex int) string
PlainRenderLines returns the non-coloured string of diff part from firstLineIndex to lastLineIndex
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 )