Documentation
¶
Index ¶
- Constants
- Variables
- func GetWhitespaceFlag(whitespaceBehavior string) git.TrustedCmdArgs
- func SyncUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, ...) (*pull_model.ReviewState, error)
- type Diff
- func CommentAsDiff(ctx context.Context, c *issues_model.Comment) (*Diff, error)
- func CommentMustAsDiff(ctx context.Context, c *issues_model.Comment) *Diff
- func GetDiffForAPI(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, ...) (*Diff, error)
- func GetDiffForRender(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, ...) (*Diff, error)
- func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, ...) (*Diff, error)
- type DiffFile
- func (diffFile *DiffFile) GetDiffFileName() string
- func (diffFile *DiffFile) GetTailSectionAndLimitedContent(leftCommit, rightCommit *git.Commit) (_ *DiffSection, diffLimitedContent DiffLimitedContent)
- func (diffFile *DiffFile) GetType() int
- func (diffFile *DiffFile) ModeTranslationKey(mode string) string
- func (diffFile *DiffFile) ShouldBeHidden() bool
- type DiffFileType
- type DiffHTMLOperation
- type DiffInline
- type DiffLimitedContent
- type DiffLine
- func (d *DiffLine) CanComment() bool
- func (d *DiffLine) GetBlobExcerptQuery() string
- func (d *DiffLine) GetCommentSide() string
- func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection
- func (d *DiffLine) GetHTMLDiffLineType() string
- func (d *DiffLine) GetLineTypeMarker() string
- func (d *DiffLine) GetType() int
- type DiffLineExpandDirection
- type DiffLineSectionInfo
- type DiffLineType
- type DiffOptions
- type DiffSection
- type DiffShortStat
- type DiffTree
- type DiffTreeRecord
- type SubmoduleDiffInfo
- func (si *SubmoduleDiffInfo) CommitRefIDLinkHTML(ctx context.Context, commitID string) template.HTML
- func (si *SubmoduleDiffInfo) CompareRefIDLinkHTML(ctx context.Context) template.HTML
- func (si *SubmoduleDiffInfo) PopulateURL(diffFile *DiffFile, leftCommit, rightCommit *git.Commit)
- func (si *SubmoduleDiffInfo) SubmoduleRepoLinkHTML(ctx context.Context) template.HTML
- type TableDiffCell
- type TableDiffCellType
- type TableDiffRow
- type TableDiffSection
Constants ¶
const BlobExcerptChunkSize = 20
BlobExcerptChunkSize represent max lines of excerpt
const MaxDiffHighlightEntireFileSize = 1 * 1024 * 1024
MaxDiffHighlightEntireFileSize is the maximum file size that will be highlighted with "entire file diff"
Variables ¶
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
func SyncUserSpecificDiff ¶
func SyncUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, gitRepo *git.Repository, diff *Diff, opts *DiffOptions) (*pull_model.ReviewState, error)
SyncUserSpecificDiff inserts user-specific data such as which files the user has already viewed on the given diff Additionally, the database is updated asynchronously if files have changed since the last review
Types ¶
type Diff ¶
type Diff struct {
Start, End string
Files []*DiffFile
IsIncomplete bool
NumViewedFiles int // user-specific
}
Diff represents a difference between two git trees.
func CommentAsDiff ¶
CommentAsDiff returns c.Patch as *Diff
func CommentMustAsDiff ¶
func CommentMustAsDiff(ctx context.Context, c *issues_model.Comment) *Diff
CommentMustAsDiff executes AsDiff and logs the error instead of returning
func GetDiffForAPI ¶
func GetDiffForAPI(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error)
func GetDiffForRender ¶
func GetDiffForRender(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error)
func ParsePatch ¶
func ParsePatch(ctx context.Context, maxLines, maxLineCharacters, maxFiles int, reader io.Reader, skipToFile string) (*Diff, error)
ParsePatch builds a Diff object from a io.Reader and some parameters.
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 { // basic fields (parsed from diff result) Name string NameHash string OldName string Addition int Deletion int Type DiffFileType Mode string OldMode string IsCreated bool IsDeleted bool IsBin bool IsLFSFile bool IsRenamed bool IsSubmodule bool // basic fields but for render purpose only Sections []*DiffSection IsIncomplete bool IsIncompleteLineTooLong bool // will be filled by the extra loop in GitDiffForRender Language string IsGenerated bool IsVendored bool SubmoduleDiffInfo *SubmoduleDiffInfo // IsSubmodule==true, then there must be a SubmoduleDiffInfo // will be filled by route handler IsProtected bool // will be filled by SyncUserSpecificDiff IsViewed bool // User specific HasChangedSinceLastReview bool // User specific // contains filtered or unexported fields }
DiffFile represents a file diff.
func (*DiffFile) GetDiffFileName ¶ added in v1.17.0
GetDiffFileName returns the name of the diff file, or its old name in case it was deleted
func (*DiffFile) GetTailSectionAndLimitedContent ¶
func (diffFile *DiffFile) GetTailSectionAndLimitedContent(leftCommit, rightCommit *git.Commit) (_ *DiffSection, diffLimitedContent DiffLimitedContent)
GetTailSectionAndLimitedContent creates a fake DiffLineSection if the last section is not the end of the file
func (*DiffFile) ModeTranslationKey ¶ added in v1.20.3
func (*DiffFile) ShouldBeHidden ¶ added in v1.17.0
type DiffFileType ¶
type DiffFileType uint8
DiffFileType represents the type of DiffFile.
const ( DiffFileAdd DiffFileType = iota + 1 DiffFileChange DiffFileDel DiffFileRename DiffFileCopy )
DiffFileType possible values.
type DiffHTMLOperation ¶
type DiffHTMLOperation struct { Type diffmatchpatch.Operation HTML template.HTML }
DiffHTMLOperation is the HTML version of diffmatchpatch.Diff
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 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 DiffLimitedContent ¶
type DiffLimitedContent struct {
LeftContent, RightContent *limitByteWriter
}
type DiffLine ¶
type DiffLine struct { LeftIdx int // line number, 1-based RightIdx int // line number, 1-based Match int // the diff matched index. -1: no match. 0: plain and no need to match. >0: for add/del, "Lines" slice index of the other side Type DiffLineType Content string Comments issues_model.CommentList // related PR code comments SectionInfo *DiffLineSectionInfo }
DiffLine represents a line difference in a DiffSection.
func (*DiffLine) CanComment ¶
CanComment returns whether a line can get commented
func (*DiffLine) GetBlobExcerptQuery ¶ added in v1.11.0
GetBlobExcerptQuery builds query string to get blob excerpt
func (*DiffLine) GetCommentSide ¶
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
GetHTMLDiffLineType returns the diff line type name for HTML
func (*DiffLine) GetLineTypeMarker ¶
GetLineTypeMarker returns the line type marker
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 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(idx int) *DiffLine
type DiffShortStat ¶
type DiffShortStat struct {
NumFiles, TotalAddition, TotalDeletion int
}
func GetDiffShortStat ¶
func GetDiffShortStat(gitRepo *git.Repository, beforeCommitID, afterCommitID string) (*DiffShortStat, error)
type DiffTree ¶
type DiffTree struct {
Files []*DiffTreeRecord
}
func GetDiffTree ¶
func GetDiffTree(ctx context.Context, gitRepo *git.Repository, useMergeBase bool, baseSha, headSha string) (*DiffTree, error)
GetDiffTree returns the list of path of the files that have changed between the two commits. If useMergeBase is true, the diff will be calculated using the merge base of the two commits. This is the same behavior as using a three-dot diff in git diff.
type DiffTreeRecord ¶
type DiffTreeRecord struct { // Status is one of 'added', 'deleted', 'modified', 'renamed', 'copied', 'typechanged', 'unmerged', 'unknown' Status string // For renames and copies, the percentage of similarity between the source and target of the move/rename. Score uint8 HeadPath string BasePath string HeadMode git.EntryMode BaseMode git.EntryMode HeadBlobID string BaseBlobID string }
type SubmoduleDiffInfo ¶
type SubmoduleDiffInfo struct { SubmoduleName string SubmoduleFile *git.CommitSubmoduleFile // it might be nil if the submodule is not found or unable to parse NewRefID string PreviousRefID string }
func (*SubmoduleDiffInfo) CommitRefIDLinkHTML ¶
func (*SubmoduleDiffInfo) CompareRefIDLinkHTML ¶
func (si *SubmoduleDiffInfo) CompareRefIDLinkHTML(ctx context.Context) template.HTML
func (*SubmoduleDiffInfo) PopulateURL ¶
func (si *SubmoduleDiffInfo) PopulateURL(diffFile *DiffFile, leftCommit, rightCommit *git.Commit)
func (*SubmoduleDiffInfo) SubmoduleRepoLinkHTML ¶
func (si *SubmoduleDiffInfo) SubmoduleRepoLinkHTML(ctx context.Context) template.HTML
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.