gitea: code.gitea.io/gitea/services/gitdiff Index | Examples | Files

package gitdiff

import "code.gitea.io/gitea/services/gitdiff"

Index

Examples

Package Files

gitdiff.go

Constants

const BlobExceprtChunkSize = 20

BlobExceprtChunkSize represent max lines of excerpt

func CutDiffAroundLine Uses

func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLine int) string

CutDiffAroundLine cuts a diff of a file in way that only the given line + numberOfLine above it will be shown it also recalculates hunks and adds the appropriate headers to the new diff. Warning: Only one-file diffs are allowed.

Code:

const diff = `diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
 # gitea-github-migrator
+
+ Build Status
- Latest Release
 Docker Pulls
+ cut off
+ cut off`
result := CutDiffAroundLine(strings.NewReader(diff), 4, false, 3)
println(result)

func GetRawDiff Uses

func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error

GetRawDiff dumps diff results of repository in given commit ID to io.Writer. TODO: move this function to gogits/git-module

func GetRawDiffForFile Uses

func GetRawDiffForFile(repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error

GetRawDiffForFile dumps diff results of file in given commit ID to io.Writer. TODO: move this function to gogits/git-module

type Diff Uses

type Diff struct {
    TotalAddition, TotalDeletion int
    Files                        []*DiffFile
    IsIncomplete                 bool
}

Diff represents a difference between two git trees.

func CommentAsDiff Uses

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

CommentAsDiff returns c.Patch as *Diff

func CommentMustAsDiff Uses

func CommentMustAsDiff(c *models.Comment) *Diff

CommentMustAsDiff executes AsDiff and logs the error instead of returning

func GetDiffCommit Uses

func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacters, maxFiles int) (*Diff, error)

GetDiffCommit builds a Diff representing the given commitID.

func GetDiffRange Uses

func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacters, maxFiles int) (*Diff, error)

GetDiffRange builds a Diff between two commits of a repository. passing the empty string as beforeCommitID returns a diff from the parent commit.

func GetDiffRangeWithWhitespaceBehavior Uses

func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacters, maxFiles int, whitespaceBehavior string) (*Diff, error)

GetDiffRangeWithWhitespaceBehavior 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 Uses

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

ParsePatch builds a Diff object from a io.Reader and some parameters. TODO: move this function to gogits/git-module

func (*Diff) LoadComments Uses

func (diff *Diff) LoadComments(issue *models.Issue, currentUser *models.User) error

LoadComments loads comments into each line

func (*Diff) NumFiles Uses

func (diff *Diff) NumFiles() int

NumFiles returns number of files changes in a diff.

type DiffFile Uses

type DiffFile struct {
    Name               string
    OldName            string
    Index              int
    Addition, Deletion int
    Type               DiffFileType
    IsCreated          bool
    IsDeleted          bool
    IsBin              bool
    IsLFSFile          bool
    IsRenamed          bool
    IsSubmodule        bool
    Sections           []*DiffSection
    IsIncomplete       bool
}

DiffFile represents a file diff.

func (*DiffFile) GetHighlightClass Uses

func (diffFile *DiffFile) GetHighlightClass() string

GetHighlightClass returns highlight class for a filename.

func (*DiffFile) GetTailSection Uses

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 Uses

func (diffFile *DiffFile) GetType() int

GetType returns type of diff file.

type DiffFileType Uses

type DiffFileType uint8

DiffFileType represents the type of a DiffFile.

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

DiffFileType possible values.

type DiffLine Uses

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

DiffLine represents a line difference in a DiffSection.

func (*DiffLine) CanComment Uses

func (d *DiffLine) CanComment() bool

CanComment returns whether or not a line can get commented

func (*DiffLine) GetBlobExcerptQuery Uses

func (d *DiffLine) GetBlobExcerptQuery() string

GetBlobExcerptQuery builds query string to get blob excerpt

func (*DiffLine) GetCommentSide Uses

func (d *DiffLine) GetCommentSide() string

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

func (*DiffLine) GetExpandDirection Uses

func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection

GetExpandDirection gets DiffLineExpandDirection

func (*DiffLine) GetLineTypeMarker Uses

func (d *DiffLine) GetLineTypeMarker() string

GetLineTypeMarker returns the line type marker

func (*DiffLine) GetType Uses

func (d *DiffLine) GetType() int

GetType returns the type of a DiffLine.

type DiffLineExpandDirection Uses

type DiffLineExpandDirection uint8

DiffLineExpandDirection represents the DiffLineSection expand direction

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

DiffLineExpandDirection possible values.

type DiffLineSectionInfo Uses

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 Uses

type DiffLineType uint8

DiffLineType represents the type of a DiffLine.

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

DiffLineType possible values.

type DiffSection Uses

type DiffSection struct {
    Name  string
    Lines []*DiffLine
}

DiffSection represents a section of a DiffFile.

func (*DiffSection) GetComputedInlineDiffFor Uses

func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) template.HTML

GetComputedInlineDiffFor computes inline diff for the given line.

func (*DiffSection) GetLine Uses

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

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

type RawDiffType Uses

type RawDiffType string

RawDiffType type of a raw diff.

const (
    RawDiffNormal RawDiffType = "diff"
    RawDiffPatch  RawDiffType = "patch"
)

RawDiffType possible values.

Package gitdiff imports 26 packages (graph) and is imported by 9 packages. Updated 2019-12-16. Refresh now. Tools for package owners.