Tree.

applyChanges(source, target)

Given a target tree and a source tree, this:

  1. Obtains the manifests of both trees.
  2. Compares the manifests using Tree.changes.
  3. If there are any changes, it calls Tree.apply to apply just the changes to the target tree.

After the operation, the target should exactly match the source. The function returns the result of the comparison in the same format as Tree.changes so you can see what was changed.

When the target is a tree of files on a network server, calling applyChanges can be much more efficient than clearing the target and copying over all entries from the source. This relies on representing the target using an Origami extension that exposes a manifest() method. See Dev.publish for a discussion of publishing a site this way.

Example #

As in the example for Tree.apply, the Tree.applyChanges function can update a local or network folder with changes.

If the build folder contains some files:

$ ori build
about:
  index.html: About page
index.html: Home page

and an Origami file now includes a change to about.html:

// site.ori
{
  about: {
    index.html: "About page 2"
  }
  index.html: "Home page"
}

If you invoke Tree.applyChanges, it will display what changed, and the build folder will reflect those changes.

$ ori Tree.applyChanges site.ori, build
about:
  index.html: changed
$ ori build
about:
  index.html: About page 2
index.html: Home page