Actually type constants; unwrap DiffFile, DiffDelta, DiffHunk.
This commit is contained in:
parent
45b0f17c04
commit
9acd67e388
78
diff.go
78
diff.go
|
@ -13,14 +13,14 @@ import (
|
||||||
|
|
||||||
type DiffFlag int
|
type DiffFlag int
|
||||||
const (
|
const (
|
||||||
DiffFlagBinary = C.GIT_DIFF_FLAG_BINARY
|
DiffFlagBinary = DiffFlag(C.GIT_DIFF_FLAG_BINARY)
|
||||||
DiffFlagNotBinary = C.GIT_DIFF_FLAG_NOT_BINARY
|
DiffFlagNotBinary = C.GIT_DIFF_FLAG_NOT_BINARY
|
||||||
DiffFlagValidOid = C.GIT_DIFF_FLAG_VALID_OID
|
DiffFlagValidOid = C.GIT_DIFF_FLAG_VALID_OID
|
||||||
)
|
)
|
||||||
|
|
||||||
type Delta int
|
type Delta int
|
||||||
const (
|
const (
|
||||||
DeltaUnmodified = C.GIT_DELTA_UNMODIFIED
|
DeltaUnmodified = Delta(C.GIT_DELTA_UNMODIFIED)
|
||||||
DeltaAdded = C.GIT_DELTA_ADDED
|
DeltaAdded = C.GIT_DELTA_ADDED
|
||||||
DeltaDeleted = C.GIT_DELTA_DELETED
|
DeltaDeleted = C.GIT_DELTA_DELETED
|
||||||
DeltaModified = C.GIT_DELTA_MODIFIED
|
DeltaModified = C.GIT_DELTA_MODIFIED
|
||||||
|
@ -33,7 +33,7 @@ const (
|
||||||
|
|
||||||
type DiffLineType int
|
type DiffLineType int
|
||||||
const (
|
const (
|
||||||
DiffLineContext = C.GIT_DIFF_LINE_CONTEXT
|
DiffLineContext = DiffLineType(C.GIT_DIFF_LINE_CONTEXT)
|
||||||
DiffLineAddition = C.GIT_DIFF_LINE_ADDITION
|
DiffLineAddition = C.GIT_DIFF_LINE_ADDITION
|
||||||
DiffLineDeletion = C.GIT_DIFF_LINE_DELETION
|
DiffLineDeletion = C.GIT_DIFF_LINE_DELETION
|
||||||
DiffLineContextEOFNL = C.GIT_DIFF_LINE_CONTEXT_EOFNL
|
DiffLineContextEOFNL = C.GIT_DIFF_LINE_CONTEXT_EOFNL
|
||||||
|
@ -46,89 +46,61 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiffFile struct {
|
type DiffFile struct {
|
||||||
file C.git_diff_file
|
|
||||||
Path string
|
Path string
|
||||||
|
Oid *Oid
|
||||||
|
Size int
|
||||||
|
Flags DiffFlag
|
||||||
|
Mode uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDiffFile(file *C.git_diff_file) *DiffFile {
|
func newDiffFile(file *C.git_diff_file) *DiffFile {
|
||||||
return &DiffFile{
|
return &DiffFile{
|
||||||
file: *file,
|
|
||||||
Path: C.GoString(file.path),
|
Path: C.GoString(file.path),
|
||||||
|
Oid: newOidFromC(&file.oid),
|
||||||
|
Size: int(file.size),
|
||||||
|
Flags: DiffFlag(file.flags),
|
||||||
|
Mode: uint16(file.mode),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (df *DiffFile) Oid() *Oid {
|
|
||||||
return newOidFromC(&df.file.oid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (df *DiffFile) Size() int {
|
|
||||||
return int(df.file.size)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (df *DiffFile) Flags() uint32 {
|
|
||||||
return uint32(df.file.flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (df *DiffFile) Mode() uint16 {
|
|
||||||
return uint16(df.file.mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
type DiffDelta struct {
|
type DiffDelta struct {
|
||||||
delta C.git_diff_delta
|
Status Delta
|
||||||
|
Flags DiffFlag
|
||||||
|
Similarity uint16
|
||||||
OldFile *DiffFile
|
OldFile *DiffFile
|
||||||
NewFile *DiffFile
|
NewFile *DiffFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDiffDelta(delta *C.git_diff_delta) *DiffDelta {
|
func newDiffDelta(delta *C.git_diff_delta) *DiffDelta {
|
||||||
return &DiffDelta{
|
return &DiffDelta{
|
||||||
delta: *delta,
|
Status: Delta(delta.status),
|
||||||
|
Flags: DiffFlag(delta.flags),
|
||||||
|
Similarity: uint16(delta.similarity),
|
||||||
OldFile: newDiffFile(&delta.old_file),
|
OldFile: newDiffFile(&delta.old_file),
|
||||||
NewFile: newDiffFile(&delta.new_file),
|
NewFile: newDiffFile(&delta.new_file),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dd *DiffDelta) Status() Delta {
|
|
||||||
return Delta(dd.delta.status)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dd *DiffDelta) Flags() DiffFlag {
|
|
||||||
return DiffFlag(dd.delta.flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dd *DiffDelta) Similarity() uint16 {
|
|
||||||
return uint16(dd.delta.similarity)
|
|
||||||
}
|
|
||||||
|
|
||||||
type DiffHunk struct {
|
type DiffHunk struct {
|
||||||
hunk C.git_diff_hunk
|
OldStart int
|
||||||
|
OldLines int
|
||||||
|
NewStart int
|
||||||
|
NewLines int
|
||||||
Header string
|
Header string
|
||||||
DiffDelta
|
DiffDelta
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDiffHunk(delta *C.git_diff_delta, hunk *C.git_diff_hunk) *DiffHunk {
|
func newDiffHunk(delta *C.git_diff_delta, hunk *C.git_diff_hunk) *DiffHunk {
|
||||||
return &DiffHunk{
|
return &DiffHunk{
|
||||||
hunk: *hunk,
|
OldStart: int(hunk.old_start),
|
||||||
|
OldLines: int(hunk.old_lines),
|
||||||
|
NewStart: int(hunk.new_start),
|
||||||
|
NewLines: int(hunk.new_lines),
|
||||||
Header: C.GoStringN(&hunk.header[0], C.int(hunk.header_len)),
|
Header: C.GoStringN(&hunk.header[0], C.int(hunk.header_len)),
|
||||||
DiffDelta: *newDiffDelta(delta),
|
DiffDelta: *newDiffDelta(delta),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dh *DiffHunk) OldStart() int {
|
|
||||||
return int(dh.hunk.old_start)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dh *DiffHunk) OldLines() int {
|
|
||||||
return int(dh.hunk.old_lines)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dh *DiffHunk) NewStart() int {
|
|
||||||
return int(dh.hunk.new_start)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dh *DiffHunk) NewLines() int {
|
|
||||||
return int(dh.hunk.new_lines)
|
|
||||||
}
|
|
||||||
|
|
||||||
type DiffLine struct {
|
type DiffLine struct {
|
||||||
Origin DiffLineType
|
Origin DiffLineType
|
||||||
OldLineno int
|
OldLineno int
|
||||||
|
|
Loading…
Reference in New Issue