Documentation ¶
Index ¶
- func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLine int) string
- func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error
- func GetRawDiffForFile(repoPath, startCommit, endCommit string, diffType RawDiffType, file string, ...) error
- type Diff
- func CommentAsDiff(c *models.Comment) (*Diff, error)
- func CommentMustAsDiff(c *models.Comment) *Diff
- func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacters, maxFiles int) (*Diff, error)
- func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, ...) (*Diff, error)
- func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID string, ...) (*Diff, error)
- func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*Diff, error)
- type DiffFile
- type DiffFileType
- type DiffLine
- type DiffLineType
- type DiffSection
- type RawDiffType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CutDiffAroundLine ¶
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.
Example ¶
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)
Output:
func GetRawDiff ¶
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 ¶
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
Types ¶
type Diff ¶
Diff represents a difference between two git trees.
func CommentAsDiff ¶
CommentAsDiff returns c.Patch as *Diff
func CommentMustAsDiff ¶
CommentMustAsDiff executes AsDiff and logs the error instead of returning
func GetDiffCommit ¶
func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacters, maxFiles int) (*Diff, error)
GetDiffCommit builds a Diff representing the given commitID.
func GetDiffRange ¶
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 ¶
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 ¶
ParsePatch builds a Diff object from a io.Reader and some parameters. TODO: move this function to gogits/git-module
func (*Diff) LoadComments ¶
LoadComments loads comments into each line
type DiffFile ¶
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 ¶
GetHighlightClass returns highlight class for a filename.
type DiffFileType ¶
type DiffFileType uint8
DiffFileType represents the type of a DiffFile.
const ( DiffFileAdd DiffFileType = iota + 1 DiffFileChange DiffFileDel DiffFileRename )
DiffFileType possible values.
type DiffLine ¶
type DiffLine struct { LeftIdx int RightIdx int Type DiffLineType Content string Comments []*models.Comment }
DiffLine represents a line difference in a DiffSection.
func (*DiffLine) CanComment ¶
CanComment returns whether or not a line can get commented
func (*DiffLine) GetCommentSide ¶
GetCommentSide returns the comment side of the first comment, if not set returns empty string
func (*DiffLine) GetLineTypeMarker ¶
GetLineTypeMarker returns the line type marker
type DiffLineType ¶
type DiffLineType uint8
DiffLineType represents the type of a DiffLine.
const ( DiffLinePlain DiffLineType = iota + 1 DiffLineAdd DiffLineDel DiffLineSection )
DiffLineType possible values.
type DiffSection ¶
DiffSection represents a section of a DiffFile.
func (*DiffSection) GetComputedInlineDiffFor ¶
func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) template.HTML
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 RawDiffType ¶
type RawDiffType string
RawDiffType type of a raw diff.
const ( RawDiffNormal RawDiffType = "diff" RawDiffPatch RawDiffType = "patch" )
RawDiffType possible values.