Sunday, February 3, 2013

Limit the scope of the SVN Checkout - Example


Assume We want to checkout WSO2 Carbon branch 4.0.0 source code from [1]. But our target branch source is located under following sub locations.  
  1. https://svn.wso2.org/repos/wso2/carbon/kernel/branches/4.0.0/
  2. https://svn.wso2.org/repos/wso2/carbon/orbit/branches/4.0.0/
  3. https://svn.wso2.org/repos/wso2/carbon/platform/branches/4.0.0/
To give you a better idea, above three svn locations are represented in tree view in the following diagram. 

carbon/
├── kernel
│   ├── branches
│   │   └── 4.0.0
│   ├── graduated
│   ├── tags
│   └── trunk
├── orbit
│   ├── branches
│   │   └── 4.0.0
│   ├── graduated
│   ├── tags
│   └── trunk
└── platform
    ├── branches
    │   └── 4.0.0
    ├── graduated
    ├── tags
    └── trunk


Possible Methods of SVN checkouts for our problem


We can either use following options.

  1. checkout entire Carbon platform ( including trunk, branches, etc.) (  $svn co https://svn.wso2.org/repos/wso2/carbon  )
  2. checkout each above svn code locations separately. ( $svn co https://svn.wso2.org/repos/wso2/carbon/kernel/branches/4.0.0/  . Similarly other two locations.  )

But first method is too time consuming, because it checkout entire Carbon Platform. So second method seems to be a good choice, but is also have some (minor) negative points.
Since codes are not in same svn structure (as in the first method) in file system, maintaining can be a little bit hard. Also If you need to checkout another location ( for example let's say carbon/platform/trunk ), again you need to checkout it separately.
So it is better to have some mechanism to narrow down the svn scope when checkout the code. There are some reference articles in end of this post. Refer them to get more information about this technique. Let's see how we can do this.

Limit the Scope of the SVN checkout


( Here I am using the subversion client which come with Ubuntu )

Let's try to checkout only following structure. 

carbon/
├── kernel
│   └── branches
│       └── 4.0.0
├── orbit
│   └── branches
│       └── 4.0.0
└── platform
    └── branches
        └── 4.0.0



Step 1 - Making svn structure up to 1 level depth. 


type following commands in terminal ( instructions are in bold letters.)

~/wso2 $ svn co https://svn.wso2.org/repos/wso2/carbon --depth immediates
A    carbon/orbit
A    carbon/kernel
A    carbon/platform
Checked out revision 160720.
~/wso2 $ 

this will create following svn structure on the file system.

carbon/
├── kernel
├── orbit
└── platform



Step 2 - Making path kernel/branches/4.0.0


type following commands in terminal ( instructions are in bold letters.)


~/wso2 $ cd carbon/kernel/
~/wso2/carbon/kernel $ svn up --set-depth empty branches
Updating 'branches':
A    branches
Updated to revision 160722. 
~/wso2/carbon/kernel $ cd branches/
~/wso2/carbon/kernel/branches $ svn up --set-depth empty 4.0.0
Updating '4.0.0':
A    4.0.0
Updated to revision 160722.
~/wso2/carbon/kernel/branches $

now we have created following svn structure.
carbon/
├── kernel
│   └── branches
│       └── 4.0.0
├── orbit
└── platform
 But still kernel/branches/4.0.0 doesn't contain any file. So let's update kernel/branches/4.0.0.

move to 4.0.0 directory using 

~/wso2/carbon/kernel/branches $ cd 4.0.0
Then type
~/wso2/carbon/kernel/branches/4.0.0 $ svn up --set-depth infinity
this will update all files located under https://svn.wso2.org/repos/wso2/carbon/kernel/branches/4.0.0/.

Step 3 - Repeat step 2 for other two locations ( for orbit and platform ).




Advantages:

  • All three locations are under some svn tree.
  • Quick.
  • Limits the scope and skips unnecessary locations. 
  • Taking svn up at svn root directory ( in this example carbon ) will update only above three locations which we made using this examples. other will not update.
  • Easy Maintenance.


Reference

  1. http://svnbook.red-bean.com/en/1.7/svn.ref.svn.html
  2. http://svnbook.red-bean.com/en/1.6/svn.advanced.sparsedirs.html