atom-archive / xray

An experimental next-generation Electron-based text editor
MIT License
8.48k stars 235 forks source link

Build CRDT state on top of a Git commit #133

Closed nathansobo closed 5 years ago

nathansobo commented 5 years ago

This PR replaces the Timeline with a new CRDT called WorkTree. In the previous implementation, every file in the CRDT was created via an operation. Now, we only create operations for changes since a base commit. This exploits the fact that Git commits can be thought of as global synchronization points across all replicas, having fixed contents that all replicas agree upon.

When the work tree is first created, operations from existing replicas can be applied immediately, but the tree also needs to be populated with paths from the base commit via the append_base_entries method before most of these operations can be interpreted. When a buffer is opened for the first time on any replica, the buffers base text also needs to be supplied from the underlying base commit in the Git repository.

This PR also incorporates buffers and brings our API into a usable state for the first time. Next, we plan to expose this core API to JavaScript via WebAssembly so this can be used in web-based projects to get some feedback.