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

Method CheckProposedRev

db/crud.go:3662–3692  ·  view source on GitHub ↗

CheckProposedRev checks withether revid can be pushed without conflict.

(ctx context.Context, docid string, revid string, parentRevID string)

Source from the content-addressed store, hash-verified

3660
3661// CheckProposedRev checks withether revid can be pushed without conflict.
3662func (db *DatabaseCollectionWithUser) CheckProposedRev(ctx context.Context, docid string, revid string, parentRevID string) (status ProposedRevStatus, currentRev string) {
3663 if strings.HasPrefix(docid, "_design/") && db.user != nil {
3664 return ProposedRev_OK, "" // Users can't upload design docs, so ignore them
3665 }
3666
3667 level := DocUnmarshalRev
3668 if parentRevID == "" {
3669 level = DocUnmarshalHistory // doc.History only needed in this case (see below)
3670 }
3671 syncData, _, err := db.GetDocSyncDataNoImport(ctx, docid, level)
3672 if err != nil {
3673 if !base.IsDocNotFoundError(err) && !base.IsXattrNotFoundError(err) {
3674 base.WarnfCtx(ctx, "CheckProposedRev(%q) --> %T %v", base.UD(docid), err, err)
3675 return ProposedRev_Error, ""
3676 }
3677 // Doc doesn't exist locally; adding it is OK (even if it has a history)
3678 return ProposedRev_OK_IsNew, ""
3679 } else if syncData.GetRevTreeID() == revid {
3680 // Proposed rev already exists here:
3681 return ProposedRev_Exists, ""
3682 } else if syncData.GetRevTreeID() == parentRevID {
3683 // Proposed rev's parent is my current revision; OK to add:
3684 return ProposedRev_OK, ""
3685 } else if parentRevID == "" && syncData.History[syncData.GetRevTreeID()].Deleted {
3686 // Proposed rev has no parent and doc is currently deleted; OK to add:
3687 return ProposedRev_OK, ""
3688 } else {
3689 // Parent revision mismatch, so this is a conflict:
3690 return ProposedRev_Conflict, syncData.GetRevTreeID()
3691 }
3692}
3693
3694// CheckProposedVersion - given DocID and a version in string form, check whether it can be added without conflict.
3695// proposedVersionStr is the string representation of the proposed version's CV.

Callers 2

handleProposeChangesMethod · 0.80
TestDatabaseFunction · 0.80

Calls 6

IsDocNotFoundErrorFunction · 0.92
IsXattrNotFoundErrorFunction · 0.92
WarnfCtxFunction · 0.92
UDFunction · 0.92
GetRevTreeIDMethod · 0.45

Tested by 1

TestDatabaseFunction · 0.64