[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: FW: Merging two unrelated branches deletes files, then recreates them, rather than merging the contents

From: Matthew Sanderson <matthew_at_formtrap.com>
Date: 2005-12-08 05:14:15 CET

Hi Thomas,

Replies below.

On Wed, 7 Dec 2005, Thomas Sturgeon wrote:

> Greetings,
>
>
>
> I have attached a zip of my experiment to this e-mail.
>
>
>
> I am sure that I am missing some major concept when it comes to
> subversion.
>
>
>
> I have also included a set of commands that I followed to get to the
> point where my process broke.
>
>
>
> The question is , how do I take two unrelated directories and merge
> their contents, including file level changes?
>
>
>
> -bash-3.00$ mkdir experiment
>
> -bash-3.00$ cd experiment
>
> -bash-3.00$ mkdir mycode
>
> -bash-3.00$ mkdir vendorcode
>
> -bash-3.00$ cd mycode/
>
> -bash-3.00$ vi words1
>
> -bash-3.00$ vi numbers1
>
> -bash-3.00$ cp numbers1 ../vendorcode/
>
> -bash-3.00$ cp words1 ../vendorcode/
>
> -bash-3.00$ cd ..
>
> -bash-3.00$ cd vendorcode/
>
> -bash-3.00$ ls
>
> numbers1 words1
>
> -bash-3.00$ vi words1
>
> -bash-3.00$ vi numbers1
>
> -bash-3.00$ mkdir includes
>
> -bash-3.00$ cd includes/
>
> -bash-3.00$ vi includes
>
> -bash-3.00$ cd ..
>
> -bash-3.00$ ls
>
> includes numbers1 words1
>
> -bash-3.00$ cd ..
>
> -bash-3.00$ cd ..
>
> -bash-3.00$ svnadmin create my_repos
>
> -bash-3.00$ svn import -m "Importing mycode" ./experiment/mycode/
> file:///home/thomas.sturgeon/my_repos/
>
> Adding experiment/mycode/words1
>
> Adding experiment/mycode/numbers1
>
>
>
> Committed revision 1.
>
>
>
> -bash-3.00$ svn import -m "Importing vendorcode"
> ./experiment/vendorcode/
> file:///home/thomas.sturgeon/my_repos/vendorcode
>
> Adding experiment/vendorcode/words1
>
> Adding experiment/vendorcode/includes
>
> Adding experiment/vendorcode/includes/includes
>
> Adding experiment/vendorcode/numbers1
>
>
>
> Committed revision 2.
>
> -bash-3.00$ pwd
>
> /home/thomas.sturgeon
>
>
>
> -bash-3.00$ svn co file:///home/thomas.sturgeon/my_repos/mycode ./wc
>
> A wc/words1
>
> A wc/numbers1
>
> Checked out revision 2.
>
>
>
> -bash-3.00$ svn merge file:///home/thomas.sturgeon/my_repos/vendorcode
> file:///home/thomas.sturgeon/my_repos/mycode ./wc
>
> D wc/words1
>
> A wc/words1
>
> D wc/numbers1
>
> A wc/numbers1
>
> Skipped missing target: 'wc/includes'
>
> -bash-3.00$
>
>
>
>
>
> Thanks,
>
> Thomas Sturgeon
>
>
>
>
> This electronic transmission is strictly confidential and intended solely for the addressee. It may contain information that is covered by legal, professional, or other privilege. If you are not the intended addressee, you must not disclose, copy or take any action in reliance of this transmission. If you have received this transmission in error, please notify the sender as soon as possible.
>
>

Thomas,

Don't think of a merge operation as combining (in some automagical
fashion) two independant pieces of code from arbitrary repository
locations R1 and R2, then putting the merged result into working copy W.

Instead, think of it as generating a diff from repository location R1 to
the repository location R2 (which is probably a newer revision of R1),
then applying that diff to the code in working copy W. The text in 'svn
help merge' makes this pretty clear.

So conceptually, the command:
# svn merge file:///repo1 file:///repo2 /wc
is equivalent to something like:
# cd /wc && diff -Naur /repo1 /repo2 | patch -p1

When you look at it that way, what Subversion did in your example makes
sense (at least to me).
If the repo arguments refer to two different versions of the same repo
location, then you are changing versions of files, so you're merging file
contents, to use your nomenclature.
But if the repo locations are unrelated, the diff step merely adds and
removes the files which differ. In your example, the files are distinct
files with seperate histories which just happen to currently have the same
name. To Subversion they are not different versions of the same file,
because Subversion did not see you doing 'cp words1 ../vendorcode/'. It
would have seen you do 'svn cp words1 ../vendorcode/', though...

Subversion certainly is doing what it was intended to do in your example.
But maybe you want something else that Subversion isn't doing; I dunno.

> The question is , how do I take two unrelated directories and merge
> their contents, including file level changes?

Another question is: how could Subversion alone 'merge' two pieces of
code, other than in the rather simple way described above which amounts to
diff+patch? I claim that to do anything much more intelligent than what
Subversion currently does would require a human, either to do the work in
the first place, or even worse to clean up the mistakes after Subversion
did it wrongly because it was trying to be too damn clever by half.

So the answer to your question probably is: if not with Subversion for
some reason, then either with careful manual use of diff + patch, or
completely manually using a text editor :-( Or avoid the problem by using
'svn cp' instead of plain 'cp'.

--matt

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Thu Dec 8 05:16:07 2005

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.