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

Method revTreeConflictCheck

db/crud.go:1785–1802  ·  view source on GitHub ↗

revTreeConflictCheck checks for conflicts in the rev tree history and returns the parent revid, currentRevIndex (index of parent rev), and an error if the document is in conflict

(ctx context.Context, revTreeHistory []string, doc *Document, newDocDeleted bool)

Source from the content-addressed store, hash-verified

1783// revTreeConflictCheck checks for conflicts in the rev tree history and returns the parent revid, currentRevIndex
1784// (index of parent rev), and an error if the document is in conflict
1785func (db *DatabaseCollectionWithUser) revTreeConflictCheck(ctx context.Context, revTreeHistory []string, doc *Document, newDocDeleted bool) (string, int, error) {
1786 currentRevIndex := len(revTreeHistory)
1787 parent := ""
1788 if currentRevIndex > 0 {
1789 for i, revid := range revTreeHistory {
1790 if doc.History.contains(revid) {
1791 currentRevIndex = i
1792 parent = revid
1793 break
1794 }
1795 }
1796 // conflict check on rev tree history
1797 if db.IsIllegalConflict(ctx, doc, parent, newDocDeleted, true, revTreeHistory) {
1798 return "", 0, base.HTTPErrorf(http.StatusConflict, "Document revision conflict")
1799 }
1800 }
1801 return parent, currentRevIndex, nil
1802}
1803
1804func buildResolverBody(localDoc, incomingDoc *Document) (Body, Body, error) {
1805 localRevID := localDoc.SyncData.GetRevTreeID()

Callers 3

IsInConflictMethod · 0.80
TestRevTreeConflictCheckFunction · 0.80

Calls 3

IsIllegalConflictMethod · 0.95
HTTPErrorfFunction · 0.92
containsMethod · 0.80

Tested by 1

TestRevTreeConflictCheckFunction · 0.64