Fix diff implementation to generate patches
This commit is contained in:
parent
58470b930e
commit
4d233de449
2 changed files with 7 additions and 7 deletions
|
@ -239,9 +239,9 @@ func (o *operations) patch(old map[string]interface{}) (now map[string]interface
|
||||||
case "change":
|
case "change":
|
||||||
if txt, ok := obj.Get(path...).Data().(string); ok {
|
if txt, ok := obj.Get(path...).Data().(string); ok {
|
||||||
dmp := diffmatchpatch.New()
|
dmp := diffmatchpatch.New()
|
||||||
if dif, err := dmp.DiffFromDelta(txt, v.value.(string)); err == nil {
|
if pch, err := dmp.PatchFromText(v.value.(string)); err == nil {
|
||||||
str := dmp.DiffText2(dif)
|
txt, _ := dmp.PatchApply(pch, txt)
|
||||||
obj.Set(str, path...)
|
obj.Set(txt, path...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,9 +256,9 @@ func (o *operations) text(old, now string, path string) {
|
||||||
|
|
||||||
dmp := diffmatchpatch.New()
|
dmp := diffmatchpatch.New()
|
||||||
|
|
||||||
dif := dmp.DiffMain(old, now, false)
|
pch := dmp.PatchMake(old, now)
|
||||||
|
|
||||||
txt := dmp.DiffToDelta(dif)
|
txt := dmp.PatchToText(pch)
|
||||||
|
|
||||||
o.op("change", "", path, old, txt)
|
o.op("change", "", path, old, txt)
|
||||||
|
|
||||||
|
|
|
@ -109,12 +109,12 @@ var chg = []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"op": "change",
|
"op": "change",
|
||||||
"path": "/name/first",
|
"path": "/name/first",
|
||||||
"value": "=1\t+obie",
|
"value": "@@ -1 +1,5 @@\n T\n+obie\n",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"op": "change",
|
"op": "change",
|
||||||
"path": "/name/last",
|
"path": "/name/last",
|
||||||
"value": "=1\t+organ\t=2\t+itchcock",
|
"value": "@@ -1,3 +1,16 @@\n M\n- H\n+organ Hitchcock\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue