Allow mutable documents to be returned from ConflictResolver:

- This required a refactor of the DocumentRevision class hierarchy:

  - DocumentRevision becomes minimal parent interface of
    BasicDocumentRevision and MutableDocumentRevision

  - Almost all existing usages of DocumentRevision change to
    BasicDocumentRevision

- Also ensure that attachments are correctly set for the new winning
  revision

Also fix transactionality of attachment handling:

New prepareAttachments method makes it easier to prepare attachments
and split out prepared and already-saved attachments, before starting
a transaction and committing them to the database.