diff --git a/Replicator/Pusher+Revs.cc b/Replicator/Pusher+Revs.cc index 380dd6ab0..0a833476a 100644 --- a/Replicator/Pusher+Revs.cc +++ b/Replicator/Pusher+Revs.cc @@ -24,6 +24,24 @@ using namespace std; using namespace litecore::blip; +namespace { + using namespace fleece; + using namespace litecore; + + // Return the input revID if it's not a VersionVector ID. + // Otherwise, return ID of the current version of the input VersionVector. + alloc_slice extractCurrentVersion(alloc_slice revID) { + constexpr slice vvSeparator = ",;"_sl; + if ( revID && revID.findAnyByteOf(vvSeparator) ) { + VersionVector vv = VersionVector::fromASCII(revID); + return vv.current().asASCII(); + } else { + return revID; + } + } + +} // anonymous namespace + namespace litecore::repl { void Pusher::maybeSendMoreRevs() { @@ -107,31 +125,12 @@ namespace litecore::repl { } } - auto fullRevID = alloc_slice(_db->convertVersionToAbsolute(request->revID)); - alloc_slice currentRevID = fullRevID; - constexpr slice vvSeparator = ",;"_sl; - if ( currentRevID.findAnyByteOf(vvSeparator) ) { - try { - VersionVector vv = VersionVector::fromASCII(currentRevID); - currentRevID = vv.current().asASCII(); - } catch ( ... ) { - // it's not a VV even with comma or semi-colon in it. - throw; - } - } + auto fullRevID = alloc_slice(_db->convertVersionToAbsolute(request->revID)); + alloc_slice currentRevID = extractCurrentVersion(fullRevID); auto fullReplacementRevID = replacementRevID ? alloc_slice(_db->convertVersionToAbsolute(replacementRevID)) : nullslice; - alloc_slice currentReplacementRevID = fullReplacementRevID; - if ( currentReplacementRevID && currentReplacementRevID.findAnyByteOf(vvSeparator) ) { - try { - VersionVector vv = VersionVector::fromASCII(currentReplacementRevID); - currentReplacementRevID = vv.current().asASCII(); - } catch ( ... ) { - // it's not a VV even with comma or semi-colon in it. - throw; - } - } + alloc_slice currentReplacementRevID = extractCurrentVersion(fullReplacementRevID); // Now send the BLIP message. Normally it's "rev", but if this is an error we make it // "norev" and include the error code: