SVN

From Triangle Wiki

Jump to: navigation, search

Contents

Introduction

Subversion (SVN) is a version control system initiated in 2000 by CollabNet Inc. It is used to maintain current and historical versions of files such as source code, web pages, and documentation.

This document will give information on Subversion, such as install and usage for an Ubuntu server.

Installation

We use Apache with SVN for the following reasons:

  • Ability to use https protocol; so secure passwords.
  • Fine-grained access controls. Apache auth to limit permissions by directory. This means you can grant read access to everything, but commit access only to trunk for instance, while have another group with commit access to tags or branches.
  • Install SVN: apt-get install subversion
  • Install Apache: apt-get install apache2

Create Directory

  • Make a subversion root directory: mkdir -p /var/lib/svn

Add Apache Modules

  • dav_module
  • dav_fs_module
  • dav_svn_module
  • authz_svn_module

Setup SSL Access

  • Enables use of Apache's AuthType Basic, so securing passwords.
  • Generate the certificate by following the steps outlined in /etc/httpd/conf/mod_ssl.txt. Be sure to change your directory to /etc/httpd/conf before following the directions.

Create /var/lib/svn/.svn-policy-file

  1. [/]
  2. * = r
  3.  
  4. [triangle:/]
  5. username = rw

The * in the / section is matched to anonymous users. Any access above and beyond read only will be prompted for a user/pass by apache AuthType Basic. The triangle section inherits permissions from those above, so anonymous users have read only permission to it. I granted myself read/write permissions to the repo.

Create /var/lib/svn/.svn-auth-file htpasswd -cs /home/svn/.svn-auth-file cactus

The above creates the file (-c) and uses sha1 for storing the password (-s). The user cactus is created. To add additional users, leave off the (-c) flag.

htpasswd -s /home/svn/.svn-auth-file userX

Create a Repository svnadmin create /home/svn/repositories/test

Set Permissions The Apache user needs permissions over the new repository. chown -R nobody.nobody /home/svn/repositories/test

Create a Directory structure for project, Create the following directory structure on your development machine. branches tags trunk

You can create them like this. cd /path/to/directoryofchoice mkdir branches tags trunk

Populate Directory

Put your source files into the created trunk directory.

cp -R /home/cactus/project/test/code/* trunk

[edit] Import the Project

svn import -m "Initial import" https://yourdomain.net/svn/test/

[edit] Test SVN Checkout

cd /path/to/directory_of_choice cd .. rm -rf /path/to/directory_of_choice svn co https://yourdomain.net/svn/test/

Subversion Commands

SVNAdmin To view a list of the available commands via the SVNAdmin type svnadmin --help into the terminal window.

SVN To view a list of the available commands via the SVN type svn --help into the terminal window.

Server Configuration

When using SVNServe the following ports must be open to allow connections to the SVNService.

  • svn 3690/tcp
  • svn 3690/udp

Setting Up A Repository

The common way to set up an SVN repository is as follows:

  • /var/lib/svn/triangle
  • /var/lib/svn/triangle/trunk
  • /var/lib/svn/triangle/branches
  • /var/lib/svn/triangle/tags

Best practices dictate that commits should happen often and logically; i.e. when a certain bug has been completed, new feature added etc.

  • Create a root folder for all your repositories using svnadmin create --fs-type fsfs under /var/lib/svn (Linux) C:\SVN (Windows). This utilises the newer File System repository type as opposed to the BerkleyDB format.
  • Inside this folder, create a folder for your new repository e.g. "/svn/projectName"
  • Right-click that folder and choose "Create repository here..."
  • A menu pops up, select "Native FileSystem"
  • To restrict access to your repository using passwd authentication, do the following:
    • Open the "conf" folder e.g. "c:\svn\project\conf"
    • Create or edit the file "svnserve.conf" and enter the following:
[general]
anon-access = none
auth-access = write
password-db = ../../passwd
realm = Admin
[miscellany]
enable-auto-props = yes
  • Save the file
  • Create a global "passwd" file e.g. "C:\svn\passwd"
  • Enter the names and passwords of each user using this repository, make sure the realm is the same in each repository:
[users]
user1 = password1
user2 = password2

Diffs and Patches

SVN Repository Patches

Updating a subversion repository with your changes isn't the only way to share your work. You may want to create a patch file based on a diff (a comparison between two files or folders), which can then be applied to someone else's working copy.

To do this we use the tortoiseSVN client on windows, but it can be done with any svn client, including the command-line clients on any supporting OS. Once you have checked out the latest revision of the file(s) you want to change, and have made your changes in your working copy, you select the file(s), then select the subversion sub-menu "Make Patch". A file browsing dialog will then appear, asking you where you want to save your file, and suggesting a .patch or a .diff extension. SVN doesn't care which extension you use, but it will generate a GNU/diffutils compatible patch file. The extension is important if you plan to use diffutils to apply the patch.

The person receiving the patch need to have the same revisions as the ones you originally modified. They just select the folder in which the patch is to be applied, select the tortoisesvn context menu "Apply Patch" and select the .diff or .patch file. The files will be automatically modified with the same modifications.

One great advantage of this method is that the patch files are very small, containing only the information necessary to change the file to a new state.

Winmerge and diffutils

Alternatively, you may want to create a patch for a file which is not under version control. GNU/diffutils is the tool most commonly used for creating and applying patches, but I prefer using WinMerge, a windows visual diff/merge tool, to create the patch files. See the external links section for download URLs.

Open WinMerge, then select Tools -> Generate Patch.

Enter the original file or folder location in the first box, then the file or folder to be compared in the second box. Then enter the name of the patch file to create (.diff), and select whether you want to append it to an existing file. There are a number of other options which I haven't tried yet, but you're welcome to play around with them and edit this article with your findings.

Then click OK and your file is generated. WinMerge cannot apply patches, you need to use either svn or diffutils, or another program that can perform this operation.

There is a version of diffutils for windows platforms, as part of a large package called GnuWin32, available on sourceforge. The URL is in the External Links section.

Tools

Remove all SVN folders

  • find . -name ".svn" -type d -exec rm -rf {} \;

External Links

Personal tools