Showing posts with label svn. Show all posts
Showing posts with label svn. Show all posts

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

Sunday, February 19, 2012

[TIP] Use Linux Pipelines and Make your life easier

Suppose you want to get the history of your terminal (commands, that you have typed  in the terminal) and find out a command that you have used log time ago.

So you can simply use history command to list down command history and find it.

$ history

( By default Linux store only last 1000 history of your command line. you can find the history file and size of history by typing following command. you can change these values changing global profile value of the terminal. )

$ echo $HISTFILE 
$ echo $HISTSIZE

But if your list is bigger one you may need to do a search to find your command. 
for example you can use grep command to find it. See following command set.

$ history > history.txt 
$ grep -i "dpkg" history.txt
 1761  dpkg -s jflex
 1974  dpkg -s cup
$ rm history.txt

In first command it writes history into a text file. In the second line, it search for "dpkg" with ignoring the case in the history.txt and it shows the results in next two lines. After that in the 5th line it removes the history.txt file.

But we can do this easily using Linux pipelines. It generates no intermediate files and can obtain result using one line. here is the command.

$ history | grep -i "dpkg" 
 1761  dpkg -s jflex
 1974  dpkg -s cup 

This is a simple example that use Linux pipelines. You can use this for very complex stuffs.  Read this Wikipedia page to learn more on Linux pipelines.

Here is another example that use pipeline.

$ find . -name .svn | xargs rm -fr

this command removes all .svn directories in current path.( Also you can use non pipeline solution to do this. see following command )

find . -name .svn -exec rm -rf {} \;