In-Memory Commit Plan

1. The Overall Problem

There should be a lightweight way to transparently sync working copies across repositories in the background. This document covers one part of a proposed implementation.

The initial implementation's goals are:

* Enable instantaneous one-way sync of a Mercurial working directory from one machine to another. * Do not require explicit commits or pushes to make the sync happen. * Assume that network flakiness is a rare event and will not generally happen. (This makes it unsuitable for many laptop-based use cases. This will likely be addressed in future iterations.)

Outside this document's scope are:

* How to detect whether a working copy has been changed (that will likely be handled by HgwatchmanExtension)

1.1. Why would you even want to sync working copies?

Imagine that you're working in a local repository and have local changes. At many organizations, to test your changes you would need to sync the contents over to a remote server to e.g. test by sending a small amount of production traffic.

The usual way to do that is to make an explicit commit and push, then have a hook on the server that updates the test repo to that commit.

hg commit && hg push test-server -r .

This sucks. Making a commit is a heavyweight operation that requires a mental context switch. It adds unnecessary friction to what should be a seamless process -- for a web application, if the server were running locally you would just need to save the file you're editing, run build steps if any, then hit refresh in your browser.

The overall plan allows developers to get the same workflow as with a local server.

1.2. Why not just make real commits on disk and strip them when we're done?

That is not atomic -- if hg log is run while a commit is being made and pushed, it's going to result in weird temporary commits being visible. Even if that is taken care of with e.g. a 'pre-secret' phase, the fact that the lock is taken by a background process is still going to be visible.

2. The Plan

1. Introduce a class called memrepo that represents a localrepository with in-memory commits. Any commits to it will be stored and serialized in memory. For safety this will be backed by a readonlyvfs, preventing writes to disk from any source.