Commit 6270a51d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9fa6ad5e
...@@ -344,33 +344,24 @@ func (δBtail *ΔBtail) treediff(ctx context.Context, root zodb.Oid, δZT SetOid ...@@ -344,33 +344,24 @@ func (δBtail *ΔBtail) treediff(ctx context.Context, root zodb.Oid, δZT SetOid
return nil, err return nil, err
} }
ta := zodb.ClassOf(xa) a, ok := xa.(Node)
tb := zodb.ClassOf(xb) if !ok {
if ta != tb { return nil, fmt.Errorf("object %s@%s: type unexpected: %s",
return nil, fmt.Errorf("object %s: type mutated: %s -> %s", top, ta, tb) top, zconnOld.At(), zodb.ClassOf(xa))
} }
b, ok := xb.(Node)
// XXX activate/deactivate if !ok {
var δtop map[Key]Value return nil, fmt.Errorf("object %s@%s: type unexpected: %s",
top, zconnNew.At(), zodb.ClassOf(xb))
switch a := xa.(type) {
default:
return nil, fmt.Errorf("object %s: type unexpected: %s", top, ta)
case *Tree:
fmt.Printf(" T%s\n", a.POid())
b := xb.(*Tree) // must not fail
δtop, err = diffT(ctx, a, b, δZTC)
case *Bucket:
fmt.Printf(" B%s\n", a.POid())
b := xb.(*Bucket) // must not fail
δtop, err = diffB(ctx, a, b)
} }
δtop, err := diffX(ctx, a, b, δZTC)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// FIXME -> merge (VDEL vs add)
for k,v := range δtop { for k,v := range δtop {
δT[k] = v δT[k] = v
} }
...@@ -392,6 +383,44 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]Value, err ...@@ -392,6 +383,44 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]Value, err
panic("BUG: both a & b == nil") panic("BUG: both a & b == nil")
} }
/*
type Kind int
const (
KEmpty Kind = iota
KBucket
KTree
)
akind, bkind := KEmpty, KEmpty
*/
var aT, bT *Tree
var aB, bB *Bucket
if a != nil {
aT, _ = a.(*Tree)
aB, _ = a.(*Bucket)
if (aT == nil && aB == nil) {
panicf("a: bad type %T", a)
}
}
if b != nil {
bT, _ = b.(*Tree)
bB, _ = b.(*Bucket)
if (bT == nil && bB == nil) {
panicf("b: bad type %T", b)
}
}
if a != nil && b != nil {
if a.POid() != b.POid() {
panicf("BUG: a.oid != b.oid ; a: %s b: %s", a.POid(), b.POid())
}
if !((aT != nil && bT != nil) || (aB != nil && bB != nil)) {
return nil, fmt.Errorf("object %s: type mutated %s -> %s", a.POid(),
zodb.ClassOf(a), zodb.ClassOf(b))
}
}
panic("TODO") panic("TODO")
} }
...@@ -400,6 +429,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]Value, err ...@@ -400,6 +429,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]Value, err
// a, b point to top of the subtree @old and @new revisions. // a, b point to top of the subtree @old and @new revisions.
// δZTC is connected set of objects covering δZT (objects changed in this tree in old..new). // δZTC is connected set of objects covering δZT (objects changed in this tree in old..new).
func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]Value, err error) { func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]Value, err error) {
fmt.Printf(" T%s\n", a.POid())
defer xerr.Contextf(&err, "diffT %s", a.POid()) defer xerr.Contextf(&err, "diffT %s", a.POid())
if a.POid() != b.POid() { if a.POid() != b.POid() {
panic("different trees") panic("different trees")
...@@ -475,6 +505,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]Value, err ...@@ -475,6 +505,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]Value, err
// diffB computes difference in between two revisions of a bucket. // diffB computes difference in between two revisions of a bucket.
// see diffX for details. // see diffX for details.
func diffB(ctx context.Context, a, b *Bucket) (δ map[Key]Value, err error) { func diffB(ctx context.Context, a, b *Bucket) (δ map[Key]Value, err error) {
fmt.Printf(" B%s\n", a.POid())
defer xerr.Contextf(&err, "diffB %s", a.POid()) defer xerr.Contextf(&err, "diffB %s", a.POid())
// XXX oid can be InvalidOid for T/B... (i.e. B is part of T and is not yet committed separately) // XXX oid can be InvalidOid for T/B... (i.e. B is part of T and is not yet committed separately)
if a.POid() != b.POid() { if a.POid() != b.POid() {
......
...@@ -286,12 +286,12 @@ func (rbs RBucketSet) Get(k Key) *RBucket { ...@@ -286,12 +286,12 @@ func (rbs RBucketSet) Get(k Key) *RBucket {
return rbs[i].hi > k return rbs[i].hi > k
}) })
if i == len(rbs) { if i == len(rbs) {
panic(fmt.Sprintf("BUG: key %v not covered; coverage: %s", k, rbs.coverage())) panicf("BUG: key %v not covered; coverage: %s", k, rbs.coverage())
} }
rb := rbs[i] rb := rbs[i]
if !(rb.lo <= k && k < rb.hi) { if !(rb.lo <= k && k < rb.hi) {
panic(fmt.Sprintf("BUG: get(%v) -> [%v, %v); coverage: %s", k, rb.lo, rb.hi, rbs.coverage())) panicf("BUG: get(%v) -> [%v, %v); coverage: %s", k, rb.lo, rb.hi, rbs.coverage())
} }
return rb return rb
...@@ -650,7 +650,7 @@ func ΔBTest(xtest interface{}) ΔBTestEntry { ...@@ -650,7 +650,7 @@ func ΔBTest(xtest interface{}) ΔBTestEntry {
case ΔBTestEntry: case ΔBTestEntry:
test = xtest test = xtest
default: default:
panic(fmt.Sprintf("BUG: ΔBTest: bad type %T", xtest)) panicf("BUG: ΔBTest: bad type %T", xtest)
} }
return test return test
} }
...@@ -1047,7 +1047,7 @@ func kvtxt(kv map[Key]string) string { ...@@ -1047,7 +1047,7 @@ func kvtxt(kv map[Key]string) string {
for _, k := range keyv { for _, k := range keyv {
v := kv[k] v := kv[k]
if strings.ContainsAny(v, " \n\t,:") { if strings.ContainsAny(v, " \n\t,:") {
panic(fmt.Sprintf("[%v]=%q: invalid value", k, v)) panicf("[%v]=%q: invalid value", k, v)
} }
sv = append(sv, fmt.Sprintf("%v:%s", k, v)) sv = append(sv, fmt.Sprintf("%v:%s", k, v))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment