Showing posts with label Apache Subversion. Show all posts
Showing posts with label Apache Subversion. Show all posts

Sunday, January 22, 2012

How to set up Apache Subversion to be accessed via a proxy (With Ubuntu))

I was going to access a subversion repository from my university network proxy for the first time and it was then that i realized that it is not possible with the usual subversion configuration. There are many options can be used in overcoming this  but the following simple solution worked for me very well.

Apache Subversion uses the 'servers' file to keep track of its' server configurations. If we need to use subversion through a proxy server the proxy-host and the port must be first configured in this file as it is not enabled by default. The simple steps to do this is;

1. We have to add the proxy server configuration into the 'servers' file in both locations.
  • /etc/subversion directory in our root directory 
  • .subversion directory in our home directory. 
However it would be sufficient only changing the 'servers' file in  .subversion directory to make this works.
2.However we can't edit the 'servers' file in etc/subversion directory since it demands root permission to edit it. So we have to open file as the root.
Open a terminal window by using ctrl+alt+T keys and enter the following command.

isha@pc:~$ sudo su
[sudo] password for isha: 

This will demand you for the password before providing root privileges.Enter the password and now we have root access in our computer. Go to the directory and open 'servers' file in text editor now.
root@isha-pc:/home/isha# cd /etc/subversion 
root@isha-pc:/etc/subversion# gedit servers
The 'servers' file will be opened now in the text editor. Look for the [global] settings section you will see some lines like this.

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
# http-proxy-host = my.proxy.domain.com
# http-proxy-port = 7000
# http-proxy-username = defaultusername
# http-proxy-password = defaultpassword

Change the 'http-proxy-host' with the address of your proxy server (excluding http:// part) and enter the port number into 'http-proxy-port' line. If you need edit the username and password settings too.

Important: Remove # symbol and all the spaces in front of the line you changed as additional spaces will result errors in the configuration. 

After editing it will look like,

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
http-proxy-host = my.proxy.lk
http-proxy-port = 3100

Save the file and close it.

3.We need to add the same configuration into the 'servers' file in .subversion directory. However it doesn't need root access to edit this file. Therefore open the file as a normal user and add the above details. Save and close.

4. Open a new terminal tab and access subversion repository back.

A useful thread to know additional options will be, svn-over-http-proxy

Monday, September 26, 2011

Creating a patch file with Apache Subversion

Apache Subversion is an open source version control system, popular among many developers. Creating and applying patches for your source code is a significant task you might need to do at some point of coding, specially when working with large scale enterprise product source codes. This post is about how to use subversion to create a patch or apply a patch after doing some modifications into the source code.

First let's see how to see the differences made into our code. 'diff' command is used to view the all the uncommited changes done into a certain project folder.
To view these uncommited changes goto the relevant directory in the local project repository and type;

svn diff

This will list all the modifications done into the source code with the specific class names.If we want to view the changes done to a single class or limited set of classes that can be viewed by adding those file names into our command as,

svn diff File1 File2 

But note that we have to be in the correct directory where the files are located, before entering the command.

Another option is view the differences between two revisions of the project.This is done by giving the specific version numbers with the 'diff' command.

svn diff -r revision1:revision2

As an example let's say we need to view the changes between revision 112 and 113. Then use svn diff -r 112:113, this will list the changes between the two given revisions only now.

As we can see the changes now next step is creating the patch file which contains these changes. The changes can be applied to the another source code using a .diff or a  .patch file. To create a patch for the modified contents in a whole directory, following command can be used.

svn diff > bug_fix.patch 
or
svn diff > bug_fix.diff 

If the patch is for some changes in a single file this can be,

svn  diff File1 > bug_fix.patch

There may be times that a patch is needed for the changes between two revisions. If so we need to give the necessary revisions with the command.

svn diff -r revision1:revision2 > bug_fix.patch

All the changes we did are safely written into a patch file now and they can be applied to someone else's code by applying this patch in the correct way.