SvnHelp >

  1. Set up and optimize SVN to access the GCC repository.

  2. A conceptual introduction to SVN for CVS users.

  3. SVN Basic commands.

  4. Moving patches around: merging and backporting.

  5. How to maintain a branch.

  6. Various tricks and recipes.

  7. Troubleshooting.

Moving patches around: merging and backporting

Merging vs. Using patches

When you need to move a patch from a directory to another (so moving across branches, trunk or whatever), the correct thing to do is to invoke svn merge svn merge analyzes a set of revisions, extracts the differences and applies them to the specified working copy, as local modifications. The differences can then be reviewed as usual svn status svn diff and committed svn commit .

So, why couldn't this be done using svn diff + (GNU) patch There are at least two very good reasons.

Backporting a patch

Let's say you have just done a commit in the trunk. The revision number of this change is r62450 (if you did not take note of this, you can use svn log to find it out, or look into the gcc-cvs mailing list archives). You want to backport it to a release branch, say GCC 4.0. The first thing to do is getting a working copy of the GCC 4.0 branch. If you have one already around, fine. Otherwise you can switch your trunk working copy:

$ svn info | grep URL
URL: svn+ssh://gcc.gnu.org/svn/gcc/trunk

$ svn switch svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_0-branch
U   gcc/reload.c
U   gcc/expr.c
[...]
Updated to revision 62453.

$ svn info | grep URL
URL: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_0-branch

Advisory Note: If you experience SSH connection problems, you may need to include your username in the path to svn. (e.g. svn+ssh://myusername@gcc.gnu.org/svn/gcc/trunk)

Switching a working copy is much much faster than checking out the whole branch: it only downloads and applies the differences svn switch is just a smart version of svn update . svn switch will also keep any local modifications you have in your tree and try to reapply them against the new branch (but obviously if they don't apply correctly you'll have to resolve the conflicts).

Now, it's time for merging the change. This is as simple as:

$ svn merge -r62449:62450 svn+ssh://gcc.gnu.org/svn/gcc/trunk
G   gcc/cp/parser.c
A   gcc/cp/reflection.c
G   gcc/cp/Make-lang.in

This merge modified two files parser.c and Make-lang.in and added a new file reflection.c . Now, if you check for the status, it should reflect exactly what the merge did:

$ svn status
G   gcc/cp/parser.c
A   gcc/cp/reflection.c
G   gcc/cp/Make-lang.in

You can further review the changes with svn diff solve any conflict that might happen (and remember to use svn resolved after that!) and finally commit the patch (with svn commit . Remember to test it though! :)

Alternative: use svnmerge

It seems that the svnmerge utility (also known as svnmerge.py) is a simpler way to do that. See SvnBranch.

None: SvnMerge (last edited 2013-04-25 16:37:19 by 217)