SVN: Switch Nodes (compared to Partial Checkouts)

In my post on partial checkouts in Subversion (SVN) I provided some scripts to assist a method of checking out related projects using subversions ‘depth’ feature, which allows related changes to be ‘co-committed’, i.e. committed together atomically.

In this post I describe an alternative.

Why is this done at all?

With Subversion (SVN), at version 1.6.x as I write this, you can not commit changes in a pair of separate working copies even if they are from the same repository. That is something that may be improved in a future version of SVN.

There is no theoretical reason why this shouldn’t be possible. The use of partial checkouts was one way to overcome the restriction in the present version of SVN. The use of switch nodes is another. First, to recap on the former…

Partial Checkouts

First, here is what happens with a partial checkout. In the repository there might be a huge tree of branches for which the following is just a fragment:

  • http://repository_root/
    • main_project/
      • trunk/
        • source.cpp
        • source.h
      • branches/
        • many feature branches
        • many maintenance branches
      • tags/
        • many many tags
    • component_library/
      • trunk/
        • utility.cpp
        • utility.h
      • branches/
        • many feature branches
        • many maintenance branches
      • tags/
        • many many tags

With a partial checkout, you might end up with a working copy such as this:

  • main_project_and_components/ → depth=empty checkout of http://repository_root/
    • main_project/
      • trunk/ — depth=infinity
        • source.cpp
        • source.h
    • component_library/
      • trunk/ — depth=infinity
        • utility.cpp
        • utility.h

The root of the working copy may be given a meaningful name, but you’re pretty-much stuck with the hierarchy of directory names below. Here the working copy is a trunk checkout; there would be more levels in that case of a partial checkout of a branch.

Switch Nodes

Suppose instead, we set out our repository like this (here omitting some of the details shown in the tree above):

  • http://repository_root/
    • _switch_nodes_/
      • readme_(general).txt
      • _main_project_switch_node_group_/
        • _scripts_
          • svn_do_switch.bat
        • main_project_node/
          • main_placeholder.txt
        • component_node/
          • component_placeholder.txt
      • _other_project_switch_node_group_/
        • similarly
    • main_project/
      • trunk/
      • branches/
      • tags/
    • component_library/
      • trunk/
      • branches/
      • tags/

Here’s the idea. To be able to ‘co-commit’ changes to the main_project and the component_library, first to an ordinary full checkout (rather than partial checkout) of the _main_project_switch_node_group_. You might call your working copy directory ‘main_project_stuff’:

Then you simply switch the node subdirectories:

  • main_project_stuff/
    • _scripts_
      • svn_do_switch.bat
    • main_project_node/ → switched to ^/main_project/trunk/
      • source.cpp
      • source.h
    • component_node/ → switched to ^/component_library/trunk/
      • utility.cpp
      • utility.h

Alternatively, you might switch to a branch.

The _scripts_ directory might contain scripts to assist with the switching operations. This is especially important to make the checkout process easy.

Pros and Cons

Here’s a comparison of the two methods:

aspect partial checkout switched nodes
set-up requirements
(repository structure)
provision of scripts set up of switch node groups
and provision of scripts
set-up of working copies
(ease of checkout)
careful use of depth
(otherwise too much of the tree is checked out)
very simple, except for care when switching
nature of tree
and subdirectory names
tree has unwanted levels;
subdirectory names e.g. ‘trunk’ are rather anonymous
tree is of an appropriate size;
subdirectory names are meaningful
indication of repository mapping
(“where am I committing to?”)
works well not so obvious;
can be misleading from TortoiseSVN client
ease of ‘conventional’ switching possible but impractical and potentially misleading works well
ease of co-committing equally easy
(just commit from working copy root)
equally easy
(just commit from working copy root)

There may be other practical differences between the two systems that I have not thought of.
I have use both of these method in real projects, and have a slight preference for the switch nodes method.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: