diff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package diff diff块

Package diff 常量

Package diff 处理go语言git diff解析 `git diff source target`

Package diff 输入数据源

Package diff 图例

Package diff diff行

Package diff 元数据

Index

Constants

View Source
const (
	MarkDelete = "---" // 源文件图例
	MarkInsert = "+++" // 目标文件图例
)
View Source
const (
	ChunkPrefix = "@@" // diff块前缀
)
View Source
const (
	InputPrefix = "diff --git " // diff输入前缀
)
View Source
const (
	MetaIndex = "index" // 索引
)
View Source
const (
	Space = " " // 空格
)

Variables

This section is empty.

Functions

func IsChunk

func IsChunk(diffLine string) bool

IsChunk 是否为diff块起始行

func IsInput

func IsInput(diffLine string) bool

IsInput 是否为diff输入行

func IsLegend

func IsLegend(diffLine string) bool

IsLegend 是否为diff图例起始行

func IsMeta

func IsMeta(diffLine string) bool

IsMeta 是否为diff元数据行

Types

type Chunk

type Chunk struct {
	Header      string // 块头部
	SourceRange *Range // 源文件行范围
	TargetRange *Range // 目标文件行范围
}

Chunk diff块

func NewChunk

func NewChunk() *Chunk

NewChunk 创建diff块实例

func (*Chunk) Parse

func (c *Chunk) Parse(diffLine string) *Chunk

Parse 解析diff块

type Diff

type Diff struct {
	Files []*File `json:"files,omitempty"` // 文件列表
}

Diff diff

func NewDiff

func NewDiff() *Diff

NewDiff 创建diff实例

func (*Diff) Parse

func (d *Diff) Parse(diffText string) *Diff

Parse 解析diff

type File

type File struct {
	Mode    FileMode  `json:"mode,omitempty"`    // 文件变动模式
	Input   *Input    `json:"input,omitempty"`   // diff输入
	Metas   []*Meta   `json:"metas,omitempty"`   // diff元数据
	Legends []*Legend `json:"legends,omitempty"` // diff图例
	Chunks  []*Chunk  `json:"chunks,omitempty"`  // diff块
}

File 文件

func NewFile

func NewFile() *File

NewFile 创建文件实例

type FileMode

type FileMode int

FileMode 文件变动模式

const (
	FileDeleted  FileMode = 1 // 删除
	FileModified FileMode = 2 // 修改
	FileInserted FileMode = 3 //新增
)

type Input

type Input struct {
	Source string `json:"source,omitempty"` // 源文件
	Target string `json:"target,omitempty"` // 目标文件
}

Input diff输入

func NewInput

func NewInput() *Input

NewInput 创建diff输入实例

func (*Input) Parse

func (i *Input) Parse(diffLine string) *Input

Parse 解析diff输入

type Legend

type Legend struct {
	Mark    string `json:"mark,omitempty"`
	Content string `json:"content,omitempty"`
}

Legend diff图例

func NewLegend

func NewLegend() *Legend

NewLegend 创建diff图例实例

func (*Legend) Parse

func (l *Legend) Parse(diffLine string) *Legend

Parse 解析diff图例

type Line

type Line struct {
	Mode   LineMode `json:"mode,omitempty"`   // 行变动类型
	Number int32    `json:"number,omitempty"` // 行号
}

Line diff行

func (*Line) LineMode

func (l *Line) LineMode(diffLine string)

LineMode 设置行变动类型

type LineMode

type LineMode int

LineMode 行变动类型

const (
	InsertPrefix = "+" // 新增行前缀
	DeletePrefix = "-" // 删除行前缀

	LineUnchanged LineMode = 1 // 上下文
	LineInsert    LineMode = 2 // 新增
	LineDelete    LineMode = 3 // 删除
)

type Meta

type Meta struct {
	MetaType MetaType `json:"meta_type,omitempty"` // 元数据类型
	Content  string   `json:"content,omitempty"`   // 内容
}

Meta diff元数据

func NewMeta

func NewMeta() *Meta

NewMeta 创建diff元数据实例

func (*Meta) Parse

func (m *Meta) Parse(diffLine string) *Meta

Parse 解析diff元数据

type MetaType

type MetaType string

MetaType 元数据类型

type Range

type Range struct {
	Start  int32   // 起始行号
	Length int32   // 范围长度
	Lines  []*Line // 行列表
}

Range 行范围

Jump to

Keyboard shortcuts

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