localWinsConflictResolutionRevTreeHandling handles the revision tree updates required for local wins conflict resolution. This is used for both legacy conflict resolution and HLV conflict resolution
(ctx context.Context, localDoc, remoteDoc *Document, docBodyBytes []byte, docHistory []string)
| 1935 | // localWinsConflictResolutionRevTreeHandling handles the revision tree updates required for local wins conflict |
| 1936 | // resolution. This is used for both legacy conflict resolution and HLV conflict resolution |
| 1937 | func localWinsConflictResolutionRevTreeHandling(ctx context.Context, localDoc, remoteDoc *Document, docBodyBytes []byte, docHistory []string) (string, []string) { |
| 1938 | remoteRevID := remoteDoc.RevID |
| 1939 | remoteGeneration, _ := ParseRevID(ctx, remoteRevID) |
| 1940 | var newRevID string |
| 1941 | |
| 1942 | if !localDoc.Deleted { |
| 1943 | // If the local doc is not a tombstone, we're just rewriting it as a child of the remote |
| 1944 | newRevID = CreateRevIDWithBytes(remoteGeneration+1, remoteRevID, docBodyBytes) |
| 1945 | } else { |
| 1946 | // If the local doc is a tombstone, we're going to end up with both the local and remote branches tombstoned, |
| 1947 | // and need to ensure the remote branch is the winning branch. To do that, we inject entries into the remote |
| 1948 | // branch's history until it's generation is longer than the local branch. |
| 1949 | remoteDoc.Deleted = localDoc.Deleted |
| 1950 | localGeneration, _ := ParseRevID(ctx, localDoc.GetRevTreeID()) |
| 1951 | |
| 1952 | requiredAdditionalRevs := localGeneration - remoteGeneration |
| 1953 | injectedRevBody := []byte("{}") |
| 1954 | injectedGeneration := remoteGeneration |
| 1955 | for i := 0; i < requiredAdditionalRevs; i++ { |
| 1956 | injectedGeneration++ |
| 1957 | remoteLeafRevID := docHistory[0] |
| 1958 | injectedRevID := CreateRevIDWithBytes(injectedGeneration, remoteLeafRevID, injectedRevBody) |
| 1959 | docHistory = append([]string{injectedRevID}, docHistory...) |
| 1960 | } |
| 1961 | newRevID = CreateRevIDWithBytes(injectedGeneration+1, docHistory[0], docBodyBytes) |
| 1962 | } |
| 1963 | return newRevID, docHistory |
| 1964 | } |
| 1965 | |
| 1966 | // localWinsConflictResolutionDocumentHandling handles the document updates required for local wins conflict resolution. |
| 1967 | // This is used for both legacy conflict resolution and HLV conflict resolution. |
no test coverage detected