Merge pull request #150 from sqs/DiffOptions_OldPrefix_and_NewPrefix
Diff: heed DiffOptions fields OldPrefix and NewPrefix
This commit is contained in:
commit
42414248f9
6
diff.go
6
diff.go
|
@ -371,6 +371,8 @@ func DefaultDiffOptions() (DiffOptions, error) {
|
||||||
InterhunkLines: uint32(opts.interhunk_lines),
|
InterhunkLines: uint32(opts.interhunk_lines),
|
||||||
IdAbbrev: uint16(opts.id_abbrev),
|
IdAbbrev: uint16(opts.id_abbrev),
|
||||||
MaxSize: int(opts.max_size),
|
MaxSize: int(opts.max_size),
|
||||||
|
OldPrefix: "a",
|
||||||
|
NewPrefix: "b",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,6 +481,8 @@ func diffOptionsToC(opts *DiffOptions) (copts *C.git_diff_options, notifyData *d
|
||||||
interhunk_lines: C.uint32_t(opts.InterhunkLines),
|
interhunk_lines: C.uint32_t(opts.InterhunkLines),
|
||||||
id_abbrev: C.uint16_t(opts.IdAbbrev),
|
id_abbrev: C.uint16_t(opts.IdAbbrev),
|
||||||
max_size: C.git_off_t(opts.MaxSize),
|
max_size: C.git_off_t(opts.MaxSize),
|
||||||
|
old_prefix: C.CString(opts.OldPrefix),
|
||||||
|
new_prefix: C.CString(opts.NewPrefix),
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.NotifyCallback != nil {
|
if opts.NotifyCallback != nil {
|
||||||
|
@ -493,6 +497,8 @@ func freeDiffOptions(copts *C.git_diff_options) {
|
||||||
if copts != nil {
|
if copts != nil {
|
||||||
cpathspec := copts.pathspec
|
cpathspec := copts.pathspec
|
||||||
freeStrarray(&cpathspec)
|
freeStrarray(&cpathspec)
|
||||||
|
C.free(unsafe.Pointer(copts.old_prefix))
|
||||||
|
C.free(unsafe.Pointer(copts.new_prefix))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
diff_test.go
19
diff_test.go
|
@ -3,6 +3,7 @@ package git
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -75,6 +76,8 @@ func TestDiffTreeToTree(t *testing.T) {
|
||||||
callbackInvoked = true
|
callbackInvoked = true
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
OldPrefix: "x1/",
|
||||||
|
NewPrefix: "y1/",
|
||||||
}
|
}
|
||||||
|
|
||||||
diff, err := repo.DiffTreeToTree(originalTree, newTree, &opts)
|
diff, err := repo.DiffTreeToTree(originalTree, newTree, &opts)
|
||||||
|
@ -90,7 +93,19 @@ func TestDiffTreeToTree(t *testing.T) {
|
||||||
files := make([]string, 0)
|
files := make([]string, 0)
|
||||||
hunks := make([]DiffHunk, 0)
|
hunks := make([]DiffHunk, 0)
|
||||||
lines := make([]DiffLine, 0)
|
lines := make([]DiffLine, 0)
|
||||||
|
patches := make([]string, 0)
|
||||||
err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
|
err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
|
||||||
|
patch, err := diff.Patch(len(patches))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer patch.Free()
|
||||||
|
patchStr, err := patch.String()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
patches = append(patches, patchStr)
|
||||||
|
|
||||||
files = append(files, file.OldFile.Path)
|
files = append(files, file.OldFile.Path)
|
||||||
return func(hunk DiffHunk) (DiffForEachLineCallback, error) {
|
return func(hunk DiffHunk) (DiffForEachLineCallback, error) {
|
||||||
hunks = append(hunks, hunk)
|
hunks = append(hunks, hunk)
|
||||||
|
@ -131,6 +146,10 @@ func TestDiffTreeToTree(t *testing.T) {
|
||||||
t.Fatal("Incorrect lines in diff")
|
t.Fatal("Incorrect lines in diff")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
|
||||||
errTest := errors.New("test error")
|
errTest := errors.New("test error")
|
||||||
|
|
||||||
err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
|
err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
|
||||||
|
|
Loading…
Reference in New Issue