There is no magic merge bullet going on here; Mercurial (which has a great name (see definition 4)) doesn't track every refactoring operation the developer performs. It doesn't know (or care) that the developer moved a function from file A to file B. Rather, just like any other VCS it simply tracks the changes to the individual files A and B. While it can and should know that stuff was removed from file A and that stuff was added to file B, it cannot and should not know whether what was removed from A was transferred over to B. So, what is it that really differentiates a DVCS from other VCS applications?
According to Joel's own Mercurial manual the developer should use the tool as follows:
- check in often
- branch to test new approaches (branch to spike)
- synchronize branches quickly
- propagate changes (push and pull) often
- add new code into the VCS quickly
It isn't (just) about whether or not the tool tracks changesets or file versions, it is about whether the tool facilitates best practices for SCM. It turns out that Mercurial does an outstanding job across the board:
- it makes cloning (branching) incredibly fast and easy. This encourages developers to branch quickly and often when working on spikes or adding new features.
- it makes pushing and pulling fast and easy. This reduces the probability of sharing workspaces and allows easy synchronization of new code between developers.
- it differentiates between commits (which are local to the current repository) and push/pulls (where code is shared). This encourages developers to commit more frequently, because the fear of "breaking the build" is removed.
- it separates the operation of pulling changes from other developers and merging those changes into your own repository. This means that a developer can accept a change to their repository at any time without having to worry about breaking their own build, until such time they are ready to perform the merge.
- it enables developers working on a new feature to distribute changes between themselves without affecting the central repository (yes, CRs are allowed in Mercurial, they just don't take as "central" a "role" as with VCS tools). Again, fear of "breaking the build" is completely removed.
- it does an outstanding job merging changes, in part because merges occur more frequently than in other systems, and in part because it does have an excellent merge algorithm.
For example, compare Mercurial with Subversion (a popular open-source VCS).
- the latter has no cloning operation, to "clone" a repository requires performing a complete checkout of the source tree from the Central Repository [CR]. Checking code out from the CR is a lengthy operation, because full copies of everything has to be transferred (probably across a network) to your development machine.
- the Mercurial "clone" operation actually creates a new branch. In Subversion you "copy" an entire directory tree to another location in your repository. The former is local, the latter requires interaction with the CR, which means that a branch in Subversion is forever embedded in the SVN database, even if it was for a spike.
- it has no concept of push/pull, you commit code directly to the CR. The only way to get new code to other developers are either through creating and emailing diffs (that may or may not break when applied to their repository, depending on the changes they made) or by committing your changes. The former is painful, the latter raises the specter of breaking the build and is hence relatively distasteful.
- it has no concept of a "local" commit, the only mechanism available to the developer to "place a stake in the ground" is to commit code to the CR. Again, this raises the specter of breaking the build.
- it requires that changes must be merged prior to the next commit. If you branch then merging isn't required, but branches are more painful to use, and are merged less frequently.
In any case, using Subversion (and similar VCS tools) actually reduces the likely-hood of the developer to use SCM best practices because proper use of the VCS actually encourages you to do things that cause pain. DVCS tools, on the other hand, makes the branching to explore new ideas and add new features a natural, meaningful way of thinking and working with your code. That is the real reason that DVCS tools deserve praise.