Merge commit '18aea4bfe89b83c5e2d6d55daa68efa6180655cc'
This commit is contained in:
commit
dff9badc05
40
diff.go
40
diff.go
|
@ -190,6 +190,46 @@ func (diff *Diff) FindSimilar(opts *DiffFindOptions) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DiffStats struct {
|
||||||
|
ptr *C.git_diff_stats
|
||||||
|
}
|
||||||
|
|
||||||
|
func (stats *DiffStats) Free() error {
|
||||||
|
if stats.ptr == nil {
|
||||||
|
return ErrInvalid
|
||||||
|
}
|
||||||
|
runtime.SetFinalizer(stats, nil)
|
||||||
|
C.git_diff_stats_free(stats.ptr)
|
||||||
|
stats.ptr = nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (stats *DiffStats) Insertions() int {
|
||||||
|
return int(C.git_diff_stats_insertions(stats.ptr))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (stats *DiffStats) Deletions() int {
|
||||||
|
return int(C.git_diff_stats_deletions(stats.ptr))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (stats *DiffStats) FilesChanged() int {
|
||||||
|
return int(C.git_diff_stats_files_changed(stats.ptr))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (diff *Diff) Stats() (*DiffStats, error) {
|
||||||
|
stats := new(DiffStats)
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
if ecode := C.git_diff_get_stats(&stats.ptr, diff.ptr); ecode < 0 {
|
||||||
|
return nil, MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
runtime.SetFinalizer(stats, (*DiffStats).Free)
|
||||||
|
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
type diffForEachData struct {
|
type diffForEachData struct {
|
||||||
FileCallback DiffForEachFileCallback
|
FileCallback DiffForEachFileCallback
|
||||||
HunkCallback DiffForEachHunkCallback
|
HunkCallback DiffForEachHunkCallback
|
||||||
|
|
14
diff_test.go
14
diff_test.go
|
@ -148,6 +148,20 @@ func TestDiffTreeToTree(t *testing.T) {
|
||||||
|
|
||||||
if want1, want2 := "x1/README", "y1/README"; !strings.Contains(patches[0], want1) || !strings.Contains(patches[0], want2) {
|
if want1, want2 := "x1/README", "y1/README"; !strings.Contains(patches[0], want1) || !strings.Contains(patches[0], want2) {
|
||||||
t.Errorf("Diff patch doesn't contain %q or %q\n\n%s", want1, want2, patches[0])
|
t.Errorf("Diff patch doesn't contain %q or %q\n\n%s", want1, want2, patches[0])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
stats, err := diff.Stats()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if stats.Insertions() != 1 {
|
||||||
|
t.Fatal("Incorrect number of insertions in diff")
|
||||||
|
}
|
||||||
|
if stats.Deletions() != 1 {
|
||||||
|
t.Fatal("Incorrect number of deletions in diff")
|
||||||
|
}
|
||||||
|
if stats.FilesChanged() != 1 {
|
||||||
|
t.Fatal("Incorrect number of changed files in diff")
|
||||||
}
|
}
|
||||||
|
|
||||||
errTest := errors.New("test error")
|
errTest := errors.New("test error")
|
||||||
|
|
Loading…
Reference in New Issue