Commit f75085c4 authored by Tristan Cavelier's avatar Tristan Cavelier

isRevisionALeaf method updated

parent f1a032a0
...@@ -318,14 +318,36 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -318,14 +318,36 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {array} leaves all leaves on tree * @param {array} leaves all leaves on tree
* @return {boolean} true/false * @return {boolean} true/false
*/ */
priv.isRevisionALeaf = function (revision, leaves) { priv.isRevisionALeaf = function (document_tree, revision) {
var i; var i, result, search;
for (i = 0; i < leaves.length; i+=1) { result = undefined;
if (leaves[i] === revision){ // search method fills "result" with the good revs info
return true; search = function (document_tree) {
var i;
if (typeof document_tree.rev !== "undefined") {
// node is not root
if (document_tree.rev === revision) {
if (document_tree.children.length === 0) {
// This node is a leaf
result = true
return;
}
result = false;
return;
}
} }
} // This node has children
return false; for (i = 0; i < document_tree.children.length; i += 1) {
// searching deeper to find the good rev
search(document_tree.children[i]);
if (result !== undefined) {
// The result is already found
return;
}
}
};
search(document_tree);
return result || false;
}; };
/** /**
......
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