About merging

John A Meinel john at arbash-meinel.com
Tue May 31 17:43:25 BST 2005

tnorth at bluewin.ch wrote:
> Hi,
> First sorry for this email, it's not about bazaar-ng devel. So if you are
> in a hurry, just ignore that.
> I would like to know how merging works. I understand a merge between two
> branches tries to put together two different versions of a file.
> But in most cases, functions have changed, function prototypes aren't the
> same anymore, etc.
> So the "merge" should most of the time just fail and let a big piece of work
> for the guy how merged. 

It just depends how much of a change has actually happened. And how much
of the changes have been divergence versus just independent development.

Meaning if I have a file foo.c, and in that file is something like:

int foo(int a)
	return a + 1;

int bar(int b)
	return foo(b - 1);

If you have one branch which decides that foo should do a lot more, it
can make the changes:

int foo(int a, int c)
	return a + 1 + c;

int bar(int b)
	return foo(b - 1, 2);

Now, if the main branch only does work outside of foo.c, you haven't
broken anything.
Also, notice that I had to modify the reference to foo, in order to get
the branch's version to work.

Which means that when you merge the changes back to the main branch, it
should pull in not only the change to the foo() function, but also the
updates to all of it's references.

Now, if you have added new references in the main branch, those
obviously won't get updated, and will need to be updated before things
will work again.

> In fact, I cannot well understand when merging may be an amazing way to put
> a stable and unstable version together...

It just depends how incompatible they are. If the development is done
well, with good separation between interfaces, and just the internals
change, then there is little difficulty with merging. If things are very
interconnected, then yes, merging can't help much.

> Could someone please tell me what I didn't understand ? I never tried to
> merge anything with any SCM, so no idea what may happen... if I try it with
> bzr and it fails, may I know where ?

I believe bzr leaves conflict markers in the source file (similar to how
cvs does it), I'm not sure if it leaves anything else, though. I know
there are plans to support the 'baz' idea of conflicted files which must
be resolved (so you don't commit the conflicts).

There is certainly an amount of discipline in how changes are made and
how they are merged. If the mainline branch decided to change foo() in a
different way, there is little that a merge tool can do to help you
bring them back together.

> Thanks,
> TNorth

Hopefully this helps you understand. merging is a useful tool that
frequently does help, but it can't do everything.

One other small thing to consider, if you are merging a long lived and
diverged branch, you might try merging it in stages. So that as you are
merging, you can keep everything working and do a little bit of fixup at
a time.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050531/c059e87a/attachment.pgp 

More information about the bazaar mailing list