MCPcopy
hub / github.com/apache/pouchdb / winningRev

Function winningRev

lib/index.js:805–833  ·  view source on GitHub ↗
(metadata)

Source from the content-addressed store, hash-verified

803// The final sort algorithm is slightly documented in a sidebar here:
804// http://guide.couchdb.org/draft/conflicts.html
805function winningRev(metadata) {
806 var winningId;
807 var winningPos;
808 var winningDeleted;
809 var toVisit = metadata.rev_tree.slice();
810 var node;
811 while ((node = toVisit.pop())) {
812 var tree = node.ids;
813 var branches = tree[2];
814 var pos = node.pos;
815 if (branches.length) { // non-leaf
816 for (var i = 0, len = branches.length; i < len; i++) {
817 toVisit.push({pos: pos + 1, ids: branches[i]});
818 }
819 continue;
820 }
821 var deleted = !!tree[1].deleted;
822 var id = tree[0];
823 // sort by deleted, then pos, then id
824 if (!winningId || (winningDeleted !== deleted ? winningDeleted :
825 winningPos !== pos ? winningPos < pos : winningId < id)) {
826 winningId = id;
827 winningPos = pos;
828 winningDeleted = deleted;
829 }
830 }
831
832 return winningPos + '-' + winningId;
833}
834
835// Pretty much all below can be combined into a higher order function to
836// traverse revisions

Callers 6

collectConflictsFunction · 0.70
isDeletedFunction · 0.70
updateDocFunction · 0.70
insertDocFunction · 0.70
getWinningRevFunction · 0.70
doMigrationTwoFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…