Skip to content

Commit

Permalink
refactoring per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jianminzhao committed Jan 16, 2025
1 parent 9845c7d commit 4619b11
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions Replicator/Pusher+Revs.cc
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 4619b11

Please sign in to comment.