Commit e751f5ff authored by Tristan Cavelier's avatar Tristan Cavelier

getRevisionFromDocumentTree method added to revisionstorage.js

parent c9741880
...@@ -117,6 +117,45 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -117,6 +117,45 @@ jIO.addStorageType('revision', function (spec, my) {
return {"rev":revision,"status":status,"children":children || []}; return {"rev":revision,"status":status,"children":children || []};
}; };
/**
* Gets the specific revision from a document tree.
* @method getRevisionFromDocumentTree
* @param {object} document_tree The document tree
* @param {string} revision The specific revision
* @return {array} The good revs info array
*/
priv.getRevisionFromDocumentTree = function (document_tree, revision) {
var i, result, search, revs_info = [];
result = [];
// search method fills "result" with the good revs info
search = function (document_tree) {
var i;
if (typeof document_tree.rev !== "undefined") {
// node is not root
revs_info.unshift({
"rev":document_tree.rev,
"status":document_tree.status
});
if (document_tree.rev === revision) {
result = revs_info;
return;
}
}
// This node has children
for (i = 0; i < document_tree.children.length; i += 1) {
// searching deeper to find the good rev
search(document_tree.children[i]);
if (result.length > 0) {
// The result is already found
return;
}
revs_info.shift();
}
};
search(document_tree);
return result;
};
/** /**
* Gets the winner revision from a document tree. * Gets the winner revision from a document tree.
* The winner is the deeper revision on the left. * The winner is the deeper revision on the left.
......
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