gitdiff

package
v1.21.4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const BlobExcerptChunkSize = 20

BlobExcerptChunkSize represent max lines of excerpt

Variables

View Source
var ErrorUndefinedCell = errors.New("undefined cell")

ErrorUndefinedCell is for when a row, column coordinates do not exist in the CSV

Functions

func GetWhitespaceFlag added in v1.14.0

func GetWhitespaceFlag(whitespaceBehavior string) git.TrustedCmdArgs

GetWhitespaceFlag returns git diff flag for treating whitespaces

Types

type Diff

type Diff struct {
	Start, End                   string
	NumFiles                     int
	TotalAddition, TotalDeletion int
	Files                        []*DiffFile
	IsIncomplete                 bool
	NumViewedFiles               int // user-specific
}

Diff represents a difference between two git trees.

func CommentAsDiff

func CommentAsDiff(c *issues_model.Comment) (*Diff, error)

CommentAsDiff returns c.Patch as *Diff

func CommentMustAsDiff

func CommentMustAsDiff(c *issues_model.Comment) *Diff

CommentMustAsDiff executes AsDiff and logs the error instead of returning

func GetDiff added in v1.16.0

func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error)

GetDiff builds a Diff between two commits of a repository. Passing the empty string as beforeCommitID returns a diff from the parent commit. The whitespaceBehavior is either an empty string or a git flag

func ParsePatch

func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader, skipToFile string) (*Diff, error)

ParsePatch builds a Diff object from a io.Reader and some parameters.

func SyncAndGetUserSpecificDiff added in v1.17.0

func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error)

SyncAndGetUserSpecificDiff is like GetDiff, except that user specific data such as which files the given user has already viewed on the given PR will also be set Additionally, the database asynchronously is updated if files have changed since the last review

func (*Diff) LoadComments

func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error

LoadComments loads comments into each line

type DiffFile

type DiffFile struct {
	Name                      string
	NameHash                  string
	OldName                   string
	Index                     int
	Addition, Deletion        int
	Type                      DiffFileType
	IsCreated                 bool
	IsDeleted                 bool
	IsBin                     bool
	IsLFSFile                 bool
	IsRenamed                 bool
	IsAmbiguous               bool
	IsSubmodule               bool
	Sections                  []*DiffSection
	IsIncomplete              bool
	IsIncompleteLineTooLong   bool
	IsProtected               bool
	IsGenerated               bool
	IsVendored                bool
	IsViewed                  bool // User specific
	HasChangedSinceLastReview bool // User specific
	Language                  string
	Mode                      string
	OldMode                   string
}

DiffFile represents a file diff.

func (*DiffFile) GetDiffFileName added in v1.17.0

func (diffFile *DiffFile) GetDiffFileName() string

GetDiffFileName returns the name of the diff file, or its old name in case it was deleted

func (*DiffFile) GetTailSection added in v1.11.0

func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommitID, rightCommitID string) *DiffSection

GetTailSection creates a fake DiffLineSection if the last section is not the end of the file

func (*DiffFile) GetType

func (diffFile *DiffFile) GetType() int

GetType returns type of diff file.

func (*DiffFile) ModeTranslationKey added in v1.20.3

func (diffFile *DiffFile) ModeTranslationKey(mode string) string

func (*DiffFile) ShouldBeHidden added in v1.17.0

func (diffFile *DiffFile) ShouldBeHidden() bool

type DiffFileType

type DiffFileType uint8

DiffFileType represents the type of DiffFile.

const (
	DiffFileAdd DiffFileType = iota + 1
	DiffFileChange
	DiffFileDel
	DiffFileRename
	DiffFileCopy
)

DiffFileType possible values.

type DiffInline added in v1.16.0

type DiffInline struct {
	EscapeStatus *charset.EscapeStatus
	Content      template.HTML
}

DiffInline is a struct that has a content and escape status

func DiffInlineWithHighlightCode added in v1.16.0

func DiffInlineWithHighlightCode(fileName, language, code string, locale translation.Locale) DiffInline

DiffInlineWithHighlightCode makes a DiffInline with code highlight and hidden unicode characters escaped

func DiffInlineWithUnicodeEscape added in v1.16.0

func DiffInlineWithUnicodeEscape(s template.HTML, locale translation.Locale) DiffInline

DiffInlineWithUnicodeEscape makes a DiffInline with hidden unicode characters escaped

type DiffLine

type DiffLine struct {
	LeftIdx     int
	RightIdx    int
	Match       int
	Type        DiffLineType
	Content     string
	Comments    []*issues_model.Comment
	SectionInfo *DiffLineSectionInfo
}

DiffLine represents a line difference in a DiffSection.

func (*DiffLine) CanComment

func (d *DiffLine) CanComment() bool

CanComment returns whether a line can get commented

func (*DiffLine) GetBlobExcerptQuery added in v1.11.0

func (d *DiffLine) GetBlobExcerptQuery() string

GetBlobExcerptQuery builds query string to get blob excerpt

func (*DiffLine) GetCommentSide

func (d *DiffLine) GetCommentSide() string

GetCommentSide returns the comment side of the first comment, if not set returns empty string

func (*DiffLine) GetExpandDirection added in v1.11.0

func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection

GetExpandDirection gets DiffLineExpandDirection

func (*DiffLine) GetHTMLDiffLineType added in v1.20.0

func (d *DiffLine) GetHTMLDiffLineType() string

GetHTMLDiffLineType returns the diff line type name for HTML

func (*DiffLine) GetLineTypeMarker

func (d *DiffLine) GetLineTypeMarker() string

GetLineTypeMarker returns the line type marker

func (*DiffLine) GetType

func (d *DiffLine) GetType() int

GetType returns the type of DiffLine.

type DiffLineExpandDirection added in v1.11.0

type DiffLineExpandDirection uint8

DiffLineExpandDirection represents the DiffLineSection expand direction

const (
	DiffLineExpandNone DiffLineExpandDirection = iota + 1
	DiffLineExpandSingle
	DiffLineExpandUpDown
	DiffLineExpandUp
	DiffLineExpandDown
)

DiffLineExpandDirection possible values.

type DiffLineSectionInfo added in v1.11.0

type DiffLineSectionInfo struct {
	Path          string
	LastLeftIdx   int
	LastRightIdx  int
	LeftIdx       int
	RightIdx      int
	LeftHunkSize  int
	RightHunkSize int
}

DiffLineSectionInfo represents diff line section meta data

type DiffLineType

type DiffLineType uint8

DiffLineType represents the type of DiffLine.

const (
	DiffLinePlain DiffLineType = iota + 1
	DiffLineAdd
	DiffLineDel
	DiffLineSection
)

DiffLineType possible values.

type DiffOptions added in v1.16.0

type DiffOptions struct {
	BeforeCommitID     string
	AfterCommitID      string
	SkipTo             string
	MaxLines           int
	MaxLineCharacters  int
	MaxFiles           int
	WhitespaceBehavior git.TrustedCmdArgs
	DirectComparison   bool
}

DiffOptions represents the options for a DiffRange

type DiffSection

type DiffSection struct {
	FileName string
	Name     string
	Lines    []*DiffLine
	// contains filtered or unexported fields
}

DiffSection represents a section of a DiffFile.

func (*DiffSection) GetComputedInlineDiffFor

func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, locale translation.Locale) DiffInline

GetComputedInlineDiffFor computes inline diff for the given line.

func (*DiffSection) GetLine

func (diffSection *DiffSection) GetLine(lineType DiffLineType, idx int) *DiffLine

GetLine gets a specific line by type (add or del) and file line number

type PullDiffStats added in v1.21.0

type PullDiffStats struct {
	TotalAddition, TotalDeletion int
}

func GetPullDiffStats added in v1.21.0

func GetPullDiffStats(gitRepo *git.Repository, opts *DiffOptions) (*PullDiffStats, error)

GetPullDiffStats

type TableDiffCell added in v1.15.0

type TableDiffCell struct {
	LeftCell  string
	RightCell string
	Type      TableDiffCellType
}

TableDiffCell represents a cell of a TableDiffRow

type TableDiffCellType added in v1.15.0

type TableDiffCellType uint8

TableDiffCellType represents the type of a TableDiffCell.

const (
	TableDiffCellUnchanged TableDiffCellType = iota + 1
	TableDiffCellChanged
	TableDiffCellAdd
	TableDiffCellDel
	TableDiffCellMovedUnchanged
	TableDiffCellMovedChanged
)

TableDiffCellType possible values.

type TableDiffRow added in v1.15.0

type TableDiffRow struct {
	RowIdx int
	Cells  []*TableDiffCell
}

TableDiffRow represents a row of a TableDiffSection.

type TableDiffSection added in v1.15.0

type TableDiffSection struct {
	Rows []*TableDiffRow
}

TableDiffSection represents a section of a DiffFile.

func CreateCsvDiff added in v1.15.0

func CreateCsvDiff(diffFile *DiffFile, baseReader, headReader *csv.Reader) ([]*TableDiffSection, error)

CreateCsvDiff creates a tabular diff based on two CSV readers.

Jump to

Keyboard shortcuts

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