patch

package
v0.23.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	PATCH_HEADER = iota
	COMMIT_SHA
	COMMIT_DESCRIPTION
	HUNK_HEADER
	ADDITION
	DELETION
	CONTEXT
	NEWLINE_MESSAGE
)

Variables

This section is empty.

Functions

func GetHeaderFromDiff

func GetHeaderFromDiff(diff string) string

func ModifiedPatchForLines

func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string, includedLineIndices []int, reverse bool, keepOriginalHeader bool) string

func ModifiedPatchForRange

func ModifiedPatchForRange(log *logrus.Entry, filename string, diffText string, firstLineIdx int, lastLineIdx int, reverse bool, keepOriginalHeader bool) string

Types

type PatchHunk

type PatchHunk struct {
	FirstLineIdx int
	// contains filtered or unexported fields
}

func GetHunksFromDiff

func GetHunksFromDiff(diff string) []*PatchHunk

func (*PatchHunk) LastLineIdx

func (hunk *PatchHunk) LastLineIdx() int

func (*PatchHunk) LineNumberOfLine

func (hunk *PatchHunk) LineNumberOfLine(idx int) int

I want to know, given a hunk, what line a given index is on

type PatchLine

type PatchLine struct {
	Kind    int
	Content string // something like '+ hello' (note the first character is not removed)
}

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 (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool, keepOriginalHeader bool) string

func (*PatchManager) Reset

func (p *PatchManager) Reset()

clears the patch

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

type PatchModifier struct {
	Log *logrus.Entry
	// contains filtered or unexported fields
}

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 (d *PatchModifier) ModifiedPatchForRange(firstLineIdx int, lastLineIdx int, reverse bool, keepOriginalHeader bool) string

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

func (*PatchParser) Render

func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndices []int) string

Render returns the coloured string of the diff with any selected lines highlighted

Jump to

Keyboard shortcuts

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