Articles index » General » Subversion: Advanced

Subversion: Advanced

The more advanced features of SVN.

Submitted by eviL<3 on 28 Mar 2008, 15:31

This article builds upon the Subversion: Introduction one, so please read that one first. It will try to explain more advanced aspects of the SVN version control system.

Table of contents
Trunk, Tags, Branches
Diff
Export
Properties
Configuration

Trunk, Tags, Branches #
You may have seen these before, for example looking at the phpBB SVN root. Many repositories are structured in this way, they have /branches, /tags and /trunk in their repository root. What the hell is this?

Let’s begin with the trunk. A trunk can refer to the long nose of an elephant, the back storage area of a car, or in SVN’s case: the current version. The trunk contains the latest development version and is mostly unstable. So if you want the very latest version, you get the trunk. For phpBB, the trunk contains phpBB 3.1. More about that in the branches section.

What are branches? Well, let’s say you have a project that has more than one main version (branch), phpBB for example has the 2.0.x branch and the 3.0.x branch. phpBB 2.0 is still supported, well so how do we maintain this? We don’t want to have to put all of these into the trunk, so we use /branches. Branches are used if you need a separate trunk for (usually old) other versions. Branches are not used very often for little projects.

And the tags? Pretty simple, a tag identifies a release. When the phpBB group releases phpBB 3.0.1, they create a new tag for that release. They basicly just copy the current trunk into /tags/release-3_0_1. If they want to check later on how it was in 3.0.0, they can just have a look at release-3_0_0.

So now you know what those three things are, how are they used though? In SVN the tags and branches are file based. This means that to start a new tag/branch, you copy the contents from the trunk, and you just have another set of files in there then. SVN offers commands to copy whole file structures, but TortoiseSVN even offers a way to do it automatically.

Go into your trunk and right-click on the window, then select TortieSVN » Branch/Tag. Now you get a window where you can do the tagging/branching directly on the server. You just enter http://path/to/repository/tags/tagname.

How to set it up? Just make three folders in your repository root called branches, tags and trunk. Move all the current files into /trunk/. That’s all. .

Diff #
In case you don’t know what diff is, it’s an application used to see the difference between two files and automise the process of applying these edits. MODs are more or less a more userfriendly variant of it, they are also less automised though. There is a great tool to view these differences in a better way, which is called WinMerge. I suggest you get it right away, as TortoiseSVN even integrates with it. Let’s say you changed a file in your repository and want to view the changes you made, you can now simply right click on the modified file, chose TortoiseSVN » Diff. In case WinMerge is installed, it should now start and show you your changes. You can also export the changes as “patch”, which is the automised diff format. This can be very useful sometimes.

Export #
When you check out an SVN working copy, it creates a “.svn” folder in every folder of the working copy, which is invisible. If you want to package up your files to a zip (for a release) it’s a pain if you have to remove all these .svn folders manually. SVN offers this great function called “export”. It allows you to get the files without having a working copy. So you go to the working copy and right click on the root. Then choose TortoiseSVN » Export. Now export the files to a location of your choice, so you can zip them up.

Properties #
Properties are another part of SVN’s extended functionality. There are quite a few official properties, but I will only explain the most important ones. Properties can be set on a file or a folder and they have a name and a value.

svn:keywords, this is the one I personally use the most. SVN has a few keywords, including “Date”, “Rev”, “Author”. My favourite one is “Id”. These keywords can be included in a file like this: $Keyword$. So you can have $Id$. I bet you’ve seen that somewhere in a phpBB file before. Now, when checking out, SVN will add some data to this keyword, if it’s set correctly. Here is an example of how it could look for Id: $Id: index.php 504 2008-01-30 22:14:38Z evil3 $. What I like about this is that it includes the filename, revision, date and author.

svn:externals, probably the most special one. If you have an application that depends on an external library and the external library is hosted on an SVN server you can make SVN automatically check out an additional working copy from another repository using this property. It’s usually set on the root. The format is “foldername<space>repository url”. It’s checked out into foldername, which is not allowed to exist yet.

svn:mime-type, is also often used. This allows you to set a mime type on your files, for example for images. Some SVN viewers can display it better like that, but it’s not required at all.

How are properties set? This is also done via TortoiseSVN. You right click on the folder/file and choose TortoiseSVN » Properties. Then you can click “Add” and select “svn:keywords” as property name. “Id” as property value. These properties also have to be committed to be added to the repository.

Configuration #
Yes, SVN has something like a “global configuration”. It’s just a little hidden, that’s all. It’s an ini file (although it has no file extension). You can find it at: C:\Documents and Settings\<username>\Application Data\Subversion\config (config is the filename). On linux that would be ~/.subversion/config. Open this file in your text editor, preferably not notepad :P.

It should begin with:
Code: Select all
### This file configures various client-side behaviors.

The first interesting setting is at the end of the [miscellany] section: enable-auto-props. This setting allows you to automatically set properties on newly added files. Note that existing files are not affected, but any file you add to any repository will have those properties set. We will define the properties in a second. Find the following line and remove the #:
Code: Select all
# enable-auto-props = yes


Now let’s set them, in the [auto-props] section. There are some commented out examples at the beginning, I’ve added these for my personal use.
Code: Select all
*.php = svn:keywords=Id
*.html = svn:keywords=Id
*.xml = svn:keywords=Id
*.sql = svn:keywords=Id
*.css = svn:keywords=Id
*.js = svn:keywords=Id
*.txt = svn:keywords=Id
*.png = svn:mime-type=image/png
*.jpg = svn:mime-type=image/jpeg
*.gif = svn:mime-type=image/gif

You can add whatever you like, you can also separate properties using “;”, in case you want to add more than one.

That’s it, I hope you learnt (yes, that is correct English ;P) something!
 

License:

All articles in the knowledge base are licensed under the phpbbmodders beerware-nc license.

Back to category


Articles index » General » Subversion: Advanced