Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

(#635) - make merging status less explicit

If we merge statuses {} and {} we now get {} and not {status: missing}
  • Loading branch information...
commit 769f782599414414cd2c385eecab453bf0a43a86 1 parent 753a23d
@neojski neojski authored
View
2  src/adapters/pouch.websql.js
@@ -698,8 +698,6 @@ var webSqlPouch = function(opts, callback) {
tx.executeSql(sql, [JSON.stringify(metadata), docId], function(tx, result) {
callback();
- }, function(tx, res){
- console.log(res);
});
});
});
View
7 src/pouch.merge.js
@@ -48,10 +48,9 @@ function mergeTree(in_tree1, in_tree2) {
var tree1 = item.tree1;
var tree2 = item.tree2;
- if (tree1[1].status === 'available' || tree2[1].status === 'available') {
- tree1[1].status = 'available';
- } else {
- tree1[1].status = 'missing';
+ if (tree1[1].status || tree2[1].status) {
+ tree1[1].status = (tree1[1].status === 'available' ||
+ tree2[1].status === 'available') ? 'available' : 'missing';
}
for (var i = 0; i < tree2[2].length; i++) {
View
128 tests/test.merge_rev_tree.js
@@ -16,29 +16,29 @@ if (typeof module !== undefined && module.exports) {
qunit('merge rev tree');
-var simple = {pos: 1, ids: ['1', {status: 'missing'}, []]};
-var two0 = {pos: 1, ids: ['1', {status: 'missing'}, [['2_0', {status: 'missing'}, []]]]};
-var two1 = {pos: 1, ids: ['1', {status: 'missing'}, [['2_1', {status: 'missing'}, []]]]};
-var newleaf = {pos: 2, ids: ['2_0', {status: 'missing'}, [['3', {status: 'missing'}, []]]]};
-var withnewleaf = {pos: 1, ids: ['1', {status: 'missing'}, [['2_0', {status: 'missing'}, [['3', {status: 'missing'}, []]]]]]};
-var newbranch = {pos: 1, ids: ['1', {status: 'missing'}, [['2_0', {status: 'missing'}, []], ['2_1', {status: 'missing'}, []]]]};
-var newdeepbranch = {pos: 2, ids: ['2_0', {status: 'missing'}, [['3_1', {status: 'missing'}, []]]]};
-
-var stemmededit = {pos: 3, ids: ['3', {status: 'missing'}, []]};
+var simple = {pos: 1, ids: ['1', {}, []]};
+var two0 = {pos: 1, ids: ['1', {}, [['2_0', {}, []]]]};
+var two1 = {pos: 1, ids: ['1', {}, [['2_1', {}, []]]]};
+var newleaf = {pos: 2, ids: ['2_0', {}, [['3', {}, []]]]};
+var withnewleaf = {pos: 1, ids: ['1', {}, [['2_0', {}, [['3', {}, []]]]]]};
+var newbranch = {pos: 1, ids: ['1', {}, [['2_0', {}, []], ['2_1', {}, []]]]};
+var newdeepbranch = {pos: 2, ids: ['2_0', {}, [['3_1', {}, []]]]};
+
+var stemmededit = {pos: 3, ids: ['3', {}, []]};
var stemmedconflicts = [simple, stemmededit];
-var newbranchleaf = {pos: 1, ids: ['1', {status: 'missing'}, [['2_0', {status: 'missing'}, [['3', {status: 'missing'}, []]]], ['2_1', {status: 'missing'}, []]]]};
-var newbranchleafbranch = {pos: 1, ids: ['1', {status: 'missing'}, [['2_0', {status: 'missing'}, [['3', {status: 'missing'}, []], ['3_1', {status: 'missing'}, []]]], ['2_1', {status: 'missing'}, []]]]};
+var newbranchleaf = {pos: 1, ids: ['1', {}, [['2_0', {}, [['3', {}, []]]], ['2_1', {}, []]]]};
+var newbranchleafbranch = {pos: 1, ids: ['1', {}, [['2_0', {}, [['3', {}, []], ['3_1', {}, []]]], ['2_1', {}, []]]]};
-var stemmed2 = [{pos: 1, ids: ['1', {status: 'missing'}, [['2_1', {status: 'missing'}, []]]]},
- {pos: 2, ids: ['2_0', {status: 'missing'}, [['3', {status: 'missing'}, []], ['3_1', {status: 'missing'}, []]]]}];
+var stemmed2 = [{pos: 1, ids: ['1', {}, [['2_1', {}, []]]]},
+ {pos: 2, ids: ['2_0', {}, [['3', {}, []], ['3_1', {}, []]]]}];
-var stemmed3 = [{pos: 2, ids: ['2_1', {status: 'missing'}, []]},
- {pos: 3, ids: ['3', {status: 'missing'}, []]},
- {pos: 3, ids: ['3_1', {status: 'missing'}, []]}];
-var partialrecover = [{pos: 1, ids: ['1', {status: 'missing'}, [['2_0', {status: 'missing'}, [['3', {status: 'missing'}, []]]]]]},
- {pos: 2, ids: ['2_1', {status: 'missing'}, []]},
- {pos: 3, ids: ['3_1', {status: 'missing'}, []]}];
+var stemmed3 = [{pos: 2, ids: ['2_1', {}, []]},
+ {pos: 3, ids: ['3', {}, []]},
+ {pos: 3, ids: ['3_1', {}, []]}];
+var partialrecover = [{pos: 1, ids: ['1', {}, [['2_0', {}, [['3', {}, []]]]]]},
+ {pos: 2, ids: ['2_1', {}, []]},
+ {pos: 3, ids: ['3_1', {}, []]}];
test('Merging a path into an empty tree is the path', function() {
deepEqual(JSON.stringify(Pouch.merge([], simple, 10)), JSON.stringify({
@@ -148,10 +148,10 @@ test('Merging unstemmed recovers as much as possible without losing info', funct
test('winningRev returns the longest leaf', function() {
var tree = [
{"pos":1,"ids":[
- "bfe70372c90ded1087239e5191984f76", {status: 'missing'}, [
- ["44d71a718b90e4696c06a90e08912c8f", {status: 'missing'}, []],
- ["56e657612d55ab1a402dcb281c874f2a", {status: 'missing'}, [
- ["93c3db16462f656f7172ccabd3cf6cd6", {status: 'missing'}, []]
+ "bfe70372c90ded1087239e5191984f76", {}, [
+ ["44d71a718b90e4696c06a90e08912c8f", {}, []],
+ ["56e657612d55ab1a402dcb281c874f2a", {}, [
+ ["93c3db16462f656f7172ccabd3cf6cd6", {}, []]
]]
]]
}];
@@ -164,17 +164,17 @@ test('winningRev returns the longest leaf again', function() {
// this one is from issue #293
var tree = [
{"pos": 1,"ids": [
- "203db1a1810a838895d561f67b224b5d", {status: 'missing'}, [
- ["bf5e08a4f9fa6d33a53f4a00ae3ea399", {status: 'missing'}, [
- ["28cd77a3ca30f79e1cfffcd6a41ca308", {status: 'missing'}, []]
+ "203db1a1810a838895d561f67b224b5d", {}, [
+ ["bf5e08a4f9fa6d33a53f4a00ae3ea399", {}, [
+ ["28cd77a3ca30f79e1cfffcd6a41ca308", {}, []]
]]
]
]},
{"pos": 1,"ids": [
- "c6d5cce35bcfbef90b20f140d723cbdb", {status: 'missing'}, [
- ["1b8dfbb1267e213328920bae43f2f597", {status: 'missing'}, []],
- ["59ed830b84b276ab776c3c51aaf93a16", {status: 'missing'}, [
- ["64a9842c6aea50bf24660378e496e853", {status: 'missing'}, []]
+ "c6d5cce35bcfbef90b20f140d723cbdb", {}, [
+ ["1b8dfbb1267e213328920bae43f2f597", {}, []],
+ ["59ed830b84b276ab776c3c51aaf93a16", {}, [
+ ["64a9842c6aea50bf24660378e496e853", {}, []]
]]
]]
}
@@ -186,7 +186,7 @@ test('winningRev returns the longest leaf again', function() {
///// These are tests from CouchDB's kt-merging.erl test suite
-var one = {pos: 1, ids: ['1', {status: 'missing'}, []]};
+var one = {pos: 1, ids: ['1', {}, []]};
test('The empty tree is the identity for merge.', function() {
deepEqual(Pouch.merge([], one, 10), {
tree: [one],
@@ -201,7 +201,7 @@ test('Merging is reflexive', function() {
});
});
-var two = {pos: 1, ids: ['2', {status: 'missing'}, []]};
+var two = {pos: 1, ids: ['2', {}, []]};
var twoSibs = [one, two];
test('Merging a prefix of a tree with the tree yields the tree.', function() {
deepEqual(Pouch.merge(twoSibs, one, 10), {
@@ -210,7 +210,7 @@ test('Merging a prefix of a tree with the tree yields the tree.', function() {
});
});
-var three = {pos: 1, ids: ['3', {status: 'missing'}, []]};
+var three = {pos: 1, ids: ['3', {}, []]};
var threeSibs = [one, two, three];
test('Merging a third unrelated branch leads to a conflict.', function() {
deepEqual(Pouch.merge(twoSibs, three, 10), {
@@ -219,9 +219,9 @@ test('Merging a third unrelated branch leads to a conflict.', function() {
});
});
-var twoChild = {pos: 1, ids: ['1', {status: 'missing'}, [
- ['1a', {status: 'missing'}, [
- ['1aa', {status: 'missing'}, []]
+var twoChild = {pos: 1, ids: ['1', {}, [
+ ['1a', {}, [
+ ['1aa', {}, []]
]]
]]};
test('Merging two children is still reflexive.', function() {
@@ -231,9 +231,9 @@ test('Merging two children is still reflexive.', function() {
});
});
-var twoChildSibs = {pos: 1, ids: ['1', {status: 'missing'}, [
- ['1a', {status: 'missing'}, []],
- ['1b', {status: 'missing'}, []]
+var twoChildSibs = {pos: 1, ids: ['1', {}, [
+ ['1a', {}, []],
+ ['1b', {}, []]
]]};
test('Merging a tree to itself is itself.', function() {
deepEqual(Pouch.merge([twoChildSibs], twoChildSibs, 10), {
@@ -242,11 +242,11 @@ test('Merging a tree to itself is itself.', function() {
});
});
-var twoChildPlusSibs = {pos: 1, ids: ['1', {status: 'missing'}, [
- ['1a', {status: 'missing'}, [
- ['1aa', {status: 'missing'}, []]
+var twoChildPlusSibs = {pos: 1, ids: ['1', {}, [
+ ['1a', {}, [
+ ['1aa', {}, []]
]],
- ['1b', {status: 'missing'}, []]
+ ['1b', {}, []]
]]};
test('Merging tree of uneven length at node 2.', function() {
deepEqual(Pouch.merge([twoChild], twoChildSibs, 10), {
@@ -255,7 +255,7 @@ test('Merging tree of uneven length at node 2.', function() {
});
});
-var stemmed1b = {pos: 2, ids: ['1a', {status: 'missing'}, []]};
+var stemmed1b = {pos: 2, ids: ['1a', {}, []]};
test('Merging a tree with a stem.', function() {
deepEqual(Pouch.merge([twoChildSibs], stemmed1b, 10), {
tree: [twoChildSibs],
@@ -263,13 +263,13 @@ test('Merging a tree with a stem.', function() {
});
});
-var twoChildPlusSibs2 = {pos: 1, ids: ['1', {status: 'missing'}, [
- ['1a', {status: 'missing'}, []],
- ['1b', {status: 'missing'}, [
- ['1bb', {status: 'missing'}, []]
+var twoChildPlusSibs2 = {pos: 1, ids: ['1', {}, [
+ ['1a', {}, []],
+ ['1b', {}, [
+ ['1bb', {}, []]
]]
]]};
-var stemmed1bb = {pos:3, ids: ['1bb', {status: 'missing'}, []]};
+var stemmed1bb = {pos:3, ids: ['1bb', {}, []]};
test('Merging a stem at a deeper level.', function() {
deepEqual(Pouch.merge([twoChildPlusSibs2], stemmed1bb, 10), {
tree: [twoChildPlusSibs2],
@@ -278,8 +278,8 @@ test('Merging a stem at a deeper level.', function() {
});
var stemmedTwoChildSibs2 = [
- {pos: 2, ids: ['1a', {status: 'missing'}, []]},
- {pos: 2, ids: ['1b', {status: 'missing'}, [['1bb', {status: 'missing'}, []]]]}
+ {pos: 2, ids: ['1a', {}, []]},
+ {pos: 2, ids: ['1b', {}, [['1bb', {}, []]]]}
];
test('Merging a stem at a deeper level against paths at deeper levels.', function() {
deepEqual(Pouch.merge(stemmedTwoChildSibs2, stemmed1bb, 10), {
@@ -288,7 +288,7 @@ test('Merging a stem at a deeper level against paths at deeper levels.', functio
});
});
-var stemmed1aa = {pos: 3, ids: ['1aa', {status: 'missing'}, []]};
+var stemmed1aa = {pos: 3, ids: ['1aa', {}, []]};
test("Merging a single tree with a deeper stem.", function() {
deepEqual(Pouch.merge([twoChild], stemmed1aa, 10), {
tree: [twoChild],
@@ -296,7 +296,7 @@ test("Merging a single tree with a deeper stem.", function() {
});
});
-var stemmed1a = {pos: 2, ids: ['1a', {status: 'missing'}, [['1aa', {status: 'missing'}, []]]]};
+var stemmed1a = {pos: 2, ids: ['1a', {}, [['1aa', {}, []]]]};
test('Merging a larger stem.', function() {
deepEqual(Pouch.merge([twoChild], stemmed1a, 10), {
tree: [twoChild],
@@ -311,7 +311,7 @@ test('More merging.', function() {
});
});
-var oneChild = {pos: 1, ids: ['1', {status: 'missing'}, [['1a', {status: 'missing'}, []]]]};
+var oneChild = {pos: 1, ids: ['1', {}, [['1a', {}, []]]]};
test('Merging should create conflicts.', function() {
deepEqual(Pouch.merge([oneChild], stemmed1aa, 10), {
tree: [oneChild, stemmed1aa],
@@ -326,19 +326,19 @@ test('Merging should have no conflicts.', function() {
});
});
-var foo = {pos: 1, ids: ['foo', {status: 'missing'}, [
- ['foo2', {status: 'missing'}, []],
- ['foo3', {status: 'missing'}, []]
+var foo = {pos: 1, ids: ['foo', {}, [
+ ['foo2', {}, []],
+ ['foo3', {}, []]
]]};
-var bar = {pos: 1, ids: ['foo', {status: 'missing'}, [
- ['foo3', {status: 'missing'}, [
- ['foo4', {status: 'missing'}, []]
+var bar = {pos: 1, ids: ['foo', {}, [
+ ['foo3', {}, [
+ ['foo4', {}, []]
]]
]]};
-var fooBar = {pos: 1, ids: ['foo', {status: 'missing'}, [
- ['foo2', {status: 'missing'}, []],
- ['foo3', {status: 'missing'}, [
- ['foo4', {status: 'missing'}, []]
+var fooBar = {pos: 1, ids: ['foo', {}, [
+ ['foo2', {}, []],
+ ['foo3', {}, [
+ ['foo4', {}, []]
]]
]]};
test('Merging trees with conflicts ought to behave.', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.