How safe are automatic mergers in Mercurial?

5 answers

Well, they are safe enough until you start reorganizing your code.

Consider the following example:

 class A { public void methodA() { // do something here // that should be great } public void methodB() { // And now I'll // do something here // and it gonna be good. } public void methodC() { // Finally, let // do something here } } 

Now you get started and decide to add some instructions to methodC.
During this time, the employee decided that method C should be placed on top of the class for some reason.

As a result, you will have two versions for merging.
Yours faithfully:

 class A { public void methodA() { // do something here // that should be great } public void methodB() { // And now I'll // do something here // and it gonna be good. } public void methodC() { // Finally, let // do something here // and here your marvelous changes } } 

And your colleagues:

 class A { public void methodC() { // Finally, let // do something here } public void methodA() { // do something here // that should be great } public void methodB() { // And now I'll // do something here // and it gonna be good. } } 

When a merge occurs, since the default context has a width of three lines, automatic merging may consider the following to be a valid result:

 class A { public void methodC() { // Finally, let // do something here } public void methodA() { // do something here // that should be great } public void methodB() { // And now I'll // do something here // and it gonna be good. } public void methodC() { // Finally, let // do something here // and here your marvelous changes } } 

For this reason, if possible, I try to ensure that the methods are organized so that accessors are grouped, and pristine, ordinary are grouped according to common logic, etc. But this is not always possible.

I hope this is a rare case, and if there are too many changes, Mercurial will ask you to merge the classes manually.

+3
source

I have been using Mercurial at work for several months now. The general team - 50+ SW developers, are divided into subgroups of 5-10 developers. We have yet to see a failed merge, which was not the result:

  • the parent file that is broken / damaged goes into merge (i.e.: encoding error)
  • incorrect merge conflict resolution by the developer

So, we were completely satisfied with the merge results for standard text files (.c, .h, .pl, makefile, linkerfiles, etc.).

We have identified a case where combining is a bad idea and can lead to some problems, and this includes automatically generated code or models that are stored as text files. Mercurial will not try to combine binary files, but it will be happy to combine models, automatically generated .c / .h files, etc. You can specify merge strategies for each directory or file type, but even with these settings in place, an inappropriate merge may occur due to the premiere of Mercurial. Outside of these cases, Hg fusion was very effective for us.

ps: if you are interested in a model / oscillator, find an offer here .

+2
source

Merge negotiation is as serious as commit code that modifies commit. Thus, all the rules of regular development are also applied for mergers. There is no magic that causes any VCS to do the right thing with the code during the merge, mostly they use sophisticated search and replace algorithms to put the changes of both branches into the output document. Merge conflicts only occur if text replacement fails, but not when the semantics of the code go wrong.

The merge developer must decide whether these changes are correct, usually by reviewing the differences between and the merging of the parents (and by checking that the software is compiled and unit tests performed, and that there is an expert assessment, and ... you know, exercise).

+2
source

I use hg fetch all the time. I give him auto pull / merge / commit, and then I build + test. If this fails, you can either hg backout last transaction, or simply fix what is broken and then commit a new set of changes before clicking.

+2
source

If you are suspicious of the merger process, the horse has already left the barn.

Coordinated development requires exactly this: coordination. You do not have to work on the same code segment at the same time. Regardless of whether it means not working in the same function, the class or file depends on your circumstances and the scope of your changes, the topic is too deep for a simple explanation here.

The fact is that if you do not know that you changed the situation with good coordination, neither the automated merger process, nor manual, as it were, smoothly, guaranteed a good result. At best, this can tell you that you end up not working in the same piece of code, but you don’t get comfort from semantic and logical changes that violate your code or, even worse, subtly pollute it. This is true regardless of whether it merges without complaint or even if it compiles.

The best defense is a test suite that automates the process of checking the final product. Lucikily is also perhaps one of the best approaches to ongoing maintenance and development.

All that said, most of the mergers that I completed went without a hitch. Those that caused the troubles became known as conflicts during the merger, which was enough to tell us to study this code more carefully, and, more importantly, the methods that we used to separate our work. It’s better to understand what is happening, but it’s also difficult to understand what is “right” until you have mixed up a couple of times. This does not mean that we did not introduce logical errors, and we do not check all of our code, but the world is also not perfect.

Which boils down to the fact that the merurial merge process is the same, but better than the process without it, pure positive. You can skip manually merging all those things that seem harmless, that even if they had logical errors, you would probably miss a cursory inspection, such as manual merging. This is simply faster and a null value for those that are conflicts, which in any case are your best smoking gun for logical errors.

The only real answer is to explicitly coordinate your efforts forward, as well as invest in a testing methodology such as TDD with unit testing. The merger charge is weak.

-3
source

All Articles