Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596package types
import ( "github.com/bluekeyes/go-gitdiff/gitdiff")
type DiffOpts struct { Split bool `json:"split"`}
type TextFragment struct { Header string `json:"comment"` Lines []gitdiff.Line `json:"lines"`}
type Diff struct { Name struct { Old string `json:"old"` New string `json:"new"` } `json:"name"` TextFragments []gitdiff.TextFragment `json:"text_fragments"` IsBinary bool `json:"is_binary"` IsNew bool `json:"is_new"` IsDelete bool `json:"is_delete"` IsCopy bool `json:"is_copy"` IsRename bool `json:"is_rename"`}
type DiffStat struct { Insertions int64 Deletions int64}
func (d *Diff) Stats() DiffStat { var stats DiffStat for _, f := range d.TextFragments { stats.Insertions += f.LinesAdded stats.Deletions += f.LinesDeleted } return stats}
// A nicer git diff representation.type NiceDiff struct { Commit Commit `json:"commit"` Stat struct { FilesChanged int `json:"files_changed"` Insertions int `json:"insertions"` Deletions int `json:"deletions"` } `json:"stat"` Diff []Diff `json:"diff"`}
type DiffTree struct { Rev1 string `json:"rev1"` Rev2 string `json:"rev2"` Patch string `json:"patch"` Diff []*gitdiff.File `json:"diff"`}
func (d *NiceDiff) ChangedFiles() []string { files := make([]string, len(d.Diff))
for i, f := range d.Diff { if f.IsDelete { files[i] = f.Name.Old } else { files[i] = f.Name.New } }
return files}
// used by html elements as a unique ID for hrefsfunc (d *Diff) Id() string { return d.Name.New}
func (d *Diff) Split() *SplitDiff { fragments := make([]SplitFragment, len(d.TextFragments)) for i, fragment := range d.TextFragments { leftLines, rightLines := SeparateLines(&fragment) fragments[i] = SplitFragment{ Header: fragment.Header(), LeftLines: leftLines, RightLines: rightLines, } }
return &SplitDiff{ Name: d.Id(), TextFragments: fragments, }}