Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ func (patch *Patch) Free() error {
return nil
}

func (patch *Patch) LineStats() (uint, uint, error) {
if patch.ptr == nil {
return 0, 0, ErrInvalid
}

runtime.LockOSThread()
defer runtime.UnlockOSThread()

var context, additions, deletions C.size_t
ecode := C.git_patch_line_stats(&context, &additions, &deletions, patch.ptr)
runtime.KeepAlive(patch)
if ecode < 0 {
return 0, 0, MakeGitError(ecode)
}

return uint(additions), uint(deletions), nil
}

func (patch *Patch) String() (string, error) {
if patch.ptr == nil {
return "", ErrInvalid
Expand Down
9 changes: 9 additions & 0 deletions patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ func TestPatch(t *testing.T) {
if strings.Index(patchStr, "diff --git a/README b/README\nindex 257cc56..820734a 100644\n--- a/README\n+++ b/README\n@@ -1 +1 @@\n-foo\n+file changed") == -1 {
t.Fatalf("patch was bad")
}

numAdditions, numDeletions, err := patch.LineStats()
checkFatal(t, err)
if numAdditions != 1 {
t.Fatal("Incorrect number of additions in line stats")
}
if numDeletions != 1 {
t.Fatal("Incorrect number of deletions in line stats")
}
}