Documentation ¶
Index ¶
- Constants
- 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 PatchManager
- func (p *PatchManager) Active() bool
- func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
- func (p *PatchManager) ApplyPatches(reverse bool) error
- func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error)
- func (p *PatchManager) GetFileStatus(filename string) int
- func (p *PatchManager) IsEmpty() bool
- func (p *PatchManager) NewPatchRequired(from string, to string, reverse bool) bool
- 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)
- func (p *PatchManager) ToggleFileWhole(filename string) error
- type PatchModifier
- type PatchParser
Constants ¶
const ( // UNSELECTED is for when the commit file has not been added to the patch in any way UNSELECTED = 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 )
const ( PATCH_HEADER = iota COMMIT_SHA COMMIT_DESCRIPTION HUNK_HEADER ADDITION DELETION CONTEXT NEWLINE_MESSAGE )
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 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) 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) int
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) RemoveFileLineRange ¶
func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error
func (*PatchManager) RenderAggregatedPatchColored ¶
func (p *PatchManager) RenderAggregatedPatchColored(plain bool) string
func (*PatchManager) RenderPatchForFile ¶
func (*PatchManager) Start ¶
func (p *PatchManager) Start(from, to string, reverse bool, canRebase bool)
NewPatchManager returns a new PatchManager
func (*PatchManager) ToggleFileWhole ¶
func (p *PatchManager) ToggleFileWhole(filename string) error
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, error)
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