alignRevTreeHistoryForHLVWrite will take incoming rev tree list and add any newer revisions to the local document. If skipHistoryCheck is false here and the history between the incoming rev tree and local rev tree differs then the local docs current rev will be tombstoned and incoming history will b
(ctx context.Context, db *DatabaseCollectionWithUser, newDoc *Document, revTreeHistory []string, skipHistoryCheck bool)
| 3796 | // rev will be tombstoned and incoming history will be active branch. If skipHistoryCheck is true then we are either allowing |
| 3797 | // conflicting tombstones or we are aligning a rev tree post conflict resolution so here in this situation we want to avoid history check. |
| 3798 | func (doc *Document) alignRevTreeHistoryForHLVWrite(ctx context.Context, db *DatabaseCollectionWithUser, newDoc *Document, revTreeHistory []string, skipHistoryCheck bool) error { |
| 3799 | currentRevIndex, parent := doc.findWhereRevBranchesFromHistory(revTreeHistory) |
| 3800 | |
| 3801 | if !skipHistoryCheck { |
| 3802 | localRevID := doc.GetRevTreeID() |
| 3803 | if parent != localRevID { |
| 3804 | base.DebugfCtx(ctx, base.KeyCRUD, "incoming rev tree history has different history than local doc %s, tombstoning local active branch and writing incoming tree", base.UD(doc.ID)) |
| 3805 | |
| 3806 | _, err := db.tombstoneActiveRevision(ctx, doc, localRevID) |
| 3807 | if err != nil { |
| 3808 | return err |
| 3809 | } |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | newRev, err := doc.addNewerRevisionsToRevTreeHistory(newDoc, currentRevIndex, parent, revTreeHistory) |
| 3814 | if err != nil { |
| 3815 | return err |
| 3816 | } |
| 3817 | // If we are skipping history check we are either allowing conflicting tombstones or we are aligning a rev tree post |
| 3818 | // conflict resolution. In both cases we do not want to update the current rev here on the document. |
| 3819 | if !skipHistoryCheck { |
| 3820 | doc.SetRevTreeID(newRev) |
| 3821 | } |
| 3822 | return nil |
| 3823 | } |
| 3824 | |
| 3825 | // addNewerRevisionsToRevTreeHistory will add any newer rev tree id's to the local document history |
| 3826 | func (doc *Document) addNewerRevisionsToRevTreeHistory(newDoc *Document, currentRevIndex int, parent string, docHistory []string) (string, error) { |