Working Copy Sync Plan

1. The Problem

It is somewhat common in the real world to have generated files alongside source files in the working copy. When a merge happens, generated files that are modified on both ends are likely to cause rebase conflicts. The best way to resolve these conflicts is usually to regenerate these files, and that's what developers have to typically do by hand.

1.1. But isn't checking in generated files bad?

While there are a lot of ways checking in generated files is bad, there are also valid use cases for it. For example:

Each of the above points has been true for at least one repository at at least one large organization.

Ultimately, software engineering is often about tradeoffs, and in some cases checking in generated files is the right tradeoff to make. This feature will make working with such files less painful.

1.2. Doesn't the merge tool support already in Mercurial solve this problem?

Mercurial does support custom merge tools for arbitrary globs of files, but the current merge tool support lacks some important features:

There's no way we can reasonably bake all of the above into configuration -- it is incredibly specific to the codebase.

2. The Solution

  1. Add support to Mercurial for driver-resolved files. A driver-resolved file is a file that will be handled by the driver outside of the usual resolve mechanism.

  2. Add support to Mercurial for custom merge drivers. A merge driver is an in-process piece of code that controls the overall merge process. It defines two top-level functions: preprocess and conclude.

    • preprocess runs right before files are resolved. Typically, this is where files will be marked driver-resolved.

    • conclude runs right after all non-driver-resolved files have been resolved by the user.

  3. Make merge.update (which implies merge, update, graft, rebase etc) and resolve driver-aware. This includes, among other things: