JournalEntry extends Document { static void applyTo(@NotNull Iterable<String> changedPaths, @NotNull DiffCache diffCache, @NotNull Path path, @NotNull RevisionVector from, @NotNull RevisionVector to) throws IOException { LOG.debug("applyTo: starting for {} from {} to {}", path, from, to); LOG.debug("applyTo: sorting done."); final DiffCache.Entry entry = checkNotNull(diffCache).newEntry(from, to, false); final Iterator<String> it = changedPaths.iterator(); if (!it.hasNext()) { entry.append(path, ""); entry.done(); return; } String previousPath = it.next(); TreeNode node = new TreeNode(); node = node.getOrCreatePath(previousPath); int totalCnt = 0; int deDuplicatedCnt = 0; while (it.hasNext()) { totalCnt++; final String currentPath = it.next(); if (previousPath.equals(currentPath)) { continue; } final TreeNode currentNode = node.getOrCreatePath(currentPath); while (node != null && !node.isAncestorOf(currentNode)) { if (inScope(node, path)) { entry.append(node.getPath(), getChanges(node)); } deDuplicatedCnt++; node.children = TreeNode.NO_CHILDREN; node = node.parent; } if (node == null) { node = new TreeNode(); node = node.getOrCreatePath(currentPath); } else { node = currentNode; } previousPath = currentPath; } while (node != null && inScope(node, path)) { entry.append(node.getPath(), getChanges(node)); deDuplicatedCnt++; node = node.parent; } entry.done(); LOG.debug("applyTo: done. totalCnt: {}, deDuplicatedCnt: {}", totalCnt, deDuplicatedCnt); } JournalEntry(DocumentStore store);   JournalEntry(DocumentStore store, boolean concurrent, ChangeSetBuilder changeSetBuilder,
                 JournalPropertyHandler journalPropertyHandler); void readFrom(CommitInfo info); static final String MODIFIED; }
@Test public void applyTo() throws Exception { DiffCache cache = new MemoryDiffCache(new DocumentMK.Builder()); List<Path> paths = Lists.newArrayList(); addRandomPaths(paths); StringSort sort = JournalEntry.newSorter(); add(sort, paths); RevisionVector from = new RevisionVector(new Revision(1, 0, 1)); RevisionVector to = new RevisionVector(new Revision(2, 0, 1)); sort.sort(); JournalEntry.applyTo(sort, cache, Path.ROOT, from, to); for (Path p : paths) { String changes = cache.getChanges(from, to, p, null); assertNotNull("missing changes for " + p, changes); for (String c : getChildren(changes)) { assertTrue(paths.contains(new Path(p, c))); } } sort.close(); }