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

Function winningRev

lib/index.es.js:800–828  ·  view source on GitHub ↗
(metadata)

Source from the content-addressed store, hash-verified

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