MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / winningRevision

Method winningRevision

db/revtree.go:357–376  ·  view source on GitHub ↗

Finds the "winning" revision, the one that should be treated as the default. This is the leaf revision whose (!deleted, generation, hash) tuple compares the highest.

(ctx context.Context)

Source from the content-addressed store, hash-verified

355// Finds the "winning" revision, the one that should be treated as the default.
356// This is the leaf revision whose (!deleted, generation, hash) tuple compares the highest.
357func (tree RevTree) winningRevision(ctx context.Context) (winner string, branched bool, inConflict bool) {
358 winnerExists := false
359 leafCount := 0
360 activeLeafCount := 0
361 tree.forEachLeaf(func(info *RevInfo) {
362 exists := !info.Deleted
363 leafCount++
364 if exists {
365 activeLeafCount++
366 }
367 if (exists && !winnerExists) ||
368 ((exists == winnerExists) && compareRevIDs(ctx, info.ID, winner) > 0) {
369 winner = info.ID
370 winnerExists = exists
371 }
372 })
373 branched = (leafCount > 1)
374 inConflict = (activeLeafCount > 1)
375 return
376}
377
378// Given a revision and a set of possible ancestors, finds the one that is the most recent
379// ancestor of the revision; if none are ancestors, returns "".

Callers 3

UnmarshalJSONMethod · 0.95
TestRevTreeWinningRevFunction · 0.80

Calls 2

forEachLeafMethod · 0.95
compareRevIDsFunction · 0.85

Tested by 1

TestRevTreeWinningRevFunction · 0.64