amit-jain commented on code in PR #880:
URL: https://github.com/apache/jackrabbit-oak/pull/880#discussion_r1155472517
##########
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/version/VersionCopier.java:
##########
@@ -111,6 +125,72 @@ public boolean copyVersionHistory(String versionableUuid,
Calendar minDate, bool
return false;
}
+ private boolean hasNoConflicts(String versionHistoryPath, String
versionableUuid, boolean preserveOnTarget, NodeState sourceVersionHistory) {
+ // if preserveOnTarget is true then check no conflicts which means
version history has moved forward only
+ if (preserveOnTarget) {
+ NodeBuilder targetVersionHistory =
getVersionHistoryBuilder(targetVersionStorage, versionableUuid);
+ if (targetVersionHistory.exists()) {
+ VersionComparator versionComparator = new VersionComparator();
+
+ // version history id not equal
+ boolean conflictingVersionHistory =
!targetVersionHistory.getString(JCR_UUID).equals(sourceVersionHistory.getString(JCR_UUID));
+ if (conflictingVersionHistory) {
+ logger.info("Skipping version history for {}: Conflicting
version history found",
+ versionHistoryPath);
+ return false;
+ }
+
+ // Get the version names except jcr:rootVersion
+ List<String> targetVersions =
+
StreamSupport.stream(targetVersionHistory.getChildNodeNames().spliterator(),
false).filter(s -> !s.equals(JCR_ROOTVERSION) && !s.equals(JCR_VERSIONLABELS))
+
.sorted(versionComparator).collect(Collectors.toList());
+ List<String> sourceVersions =
+
StreamSupport.stream(sourceVersionHistory.getChildNodeNames().spliterator(),
false).filter(s -> !s.equals(JCR_ROOTVERSION) && !s.equals(JCR_VERSIONLABELS))
+
.sorted(versionComparator).collect(Collectors.toList());
+ // source version only has a rootVersion which means nothing
to update
+ boolean noUpdate = sourceVersions.isEmpty() ||
targetVersions.containsAll(sourceVersions);
+ if (noUpdate) {
+ logger.info("Skipping version history for {}: No update
required", versionHistoryPath);
+ return false;
+ }
+
+ // highest source version does not exist on target or
+ // all source versions already exist on target (diverged or no
diff)
+ boolean diverged =
!targetVersions.contains(sourceVersions.get(0));
+ if (diverged) {
+ logger.info("Skipping version history for {}: Versions
diverged", versionHistoryPath);
+ return false;
+ }
+
+ // highest source version UUID does not match the
corresponding version on target (diverged)
+ boolean conflictingHighestVersion =
+
!sourceVersionHistory.getChildNode(sourceVersions.get(0)).getString(JCR_UUID).equals(targetVersionHistory.getChildNode(sourceVersions.get(0)).getString(JCR_UUID));
+ if (conflictingHighestVersion) {
+ logger.info("Skipping version history for {}: Old base
version id changed", versionHistoryPath);
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ static class VersionComparator implements Comparator<String> {
Review Comment:
Maybe adding javadoc will convey the same purpose
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]