Avoid CouchDB conflicts on shared directories
Avoid CouchDB conflicts on shared directories

In a sharing context, we used to apply all the revisions list sent by
the remote instance after a change on a directory, e.g. a renaming,
through the _revisions field. This behaviour follows the CouchDB replication
protocol:
https://docs.couchdb.org/en/stable/replication/protocol.html#upload-batch-of-changed-documents

However, the revisions list might differ for a directory between instances when local
updates are applied before the remote changes. Typically, a directory
renaming implies a path change for all the children: the remote instance
sends all the changes to apply, while the local instance will first
treat the parent directory and recursively change the path of the
children to ensure integrity, generating new revisions.

A CouchDB conflict occurs in the following situation:

* Directory D has the following revision list on instance A: `{1-aa, 2-aa}`
* Directory D has the following revision list on instance B: `{1-aa, 2-bb}`
* Instance A sends the following revision list to instance B after changes on D:
`{1-aa, 2-aa, 3-aa, 4-aa}`
* Instance B applies the revision list sent by A: `2-aa` is unknown and
conflicts with `2-bb`.

To solve this, we do not apply the whole revision list anymore but
rather start from the last local revision and include all the remote
revisions greater than this one. So, in the example above, the final
revision list on instance B would be:

* `{1-aa, 2-bb, 3-aa, 4-aa}`

nono/cozy-stack,nono/cozy-stack,nono/cozy-stack,nono/cozy-stack,nono/cozy-stack