My favorites | English | Sign in

Faster JavaScript with Closure Tools New!

Google Code University

Software Configuration Management

Table of Contents


Audience and Pre-Requisites

This tutorial covers a tool commonly found in industry to support the software development process. The pre-requisites are significant programming experience with a language such as C++ or Java, and familiarity with Linux or Unix.

Configuration Management

Configuration Management (CM) is a tool that is used to manage change. Let's say Bob and Susan are both tech writers and both are working on updates to a technical manual. During a meeting, their manager assigns them each a section of the same document to update.

The technical manual is stored on a computer that both Bob and Susan can access. Without any CM tool or process in place, a number of problems could arise. One possible scenario is the computer storing the document might be set up so that Bob and Susan can not both work on the manual at the same time. This would slow them down considerably.

A more dangerous situation arises when the storage computer does allow the document to be opened by both Bob and Susan at the same time. Here is what could happen:

  1. Bob opens the document on his computer and works on his section.
  2. Susan opens the document on her computer and works on her section.
  3. Bob completes his changes and saves the document on the storage computer.
  4. Susan completes her changes and saves the document on the storage computer.

This illustration shows the problem that can occur if there are no controls on the single copy of the technical manual. When Susan saves her changes, she overwrites those made by Bob.

This is exactly the type of situation that a CM system can control. With a CM system, both Bob and Susan "check out" their own copy of the technical manual and work on them. When Bob checks his changes back in, the system knows that Susan has her own copy checked out. When Susan checks in her copy, the system analyzes the changes that both Bob and Susan made and creates a new version that merges the two sets of changes together.

CM systems have a number of features beyond managing concurrent changes as described above. Many systems store archives of all versions of a document, from the first time it was created. In the case of a technical manual, this can be very helpful when a user has an old version of the manual and is asking a tech writer questions. A CM system would allow the tech writer to access the old version and be able to see what the user is seeing.

CM systems are especially useful in controlling changes made to software. Such systems are called Software Configuration Management (SCM) systems. If you consider the huge number of individual source code files in a large software engineering organization and the huge number of engineers who must make changes to them, it's clear that an SCM system is critical.

Software Configuration Management

SCM systems are based on a simple idea: the definitive copies of your files are kept in a central repository. People check out copies of files from the repository, work on those copies, and then check them back in when they are finished. SCM systems manage and track revisions by multiple people against a single master set.

All SCM systems provide the following essential features:

  • Concurrency Management
  • Versioning
  • Synchronization
Let's look at each of these features in more detail.

Concurrency Management

Concurrency refers to the simultaneous editing of a file by more than one person. With a large repository, we want people to be able to do this, but it can lead to some problems.

Consider a simple example in the engineering domain: Suppose we allow engineers to modify the same file simultaneously in a central repository of source code. Client1 and Client2 both need to make changes to a file at the same time:

  1. Client1 opens bar.cpp.
  2. Client2 opens bar.cpp.
  3. Client1 changes the file and saves it.
  4. Client2 changes the file and saves it overwriting Client1's changes.
Obviously, we don't want this to happen. Even if we controlled the situation by having the two engineers work on separate copies instead of directly on a master set (as in the illustration below), the copies must somehow be reconciled. Most SCM systems deal with this problem by allowing multiple engineers to check a file out ("sync" or "update") and make changes as needed. The SCM system then runs algorithms to merge the changes as files are checked back in ("submit" or "commit") to the repository.

These algorithms can be simple (ask the engineers to resolve conflicting changes) or not-so-simple (determine how to merge the conflicting changes intelligently and only ask an engineer if the system really gets stuck).

Versioning

Versioning refers to keeping track of file revisions which makes it possible to re-create (or roll back to) a previous version of the file. This is done either by making an archive copy of every file when it is checked into the repository, or by saving every change made to a file. At any time, we can use the archives or change information to create a previous version. Versioning systems can also create log reports of who checked in changes, when they were checked in, and what the changes were.

Synchronization

With some SCM systems, individual files are checked in and out of the repository. More powerful systems allow you to check out more than one file at a time. Engineers check out their own, complete, copy of the repository (or part thereof) and work on files as needed. They then commit their changes back to the master repository periodically, and update their own personal copies to stay up-to-date with changes other people have made. This process is called syncing or updating.

Subversion

Subversion (SVN) is an open-source version control system. It has all of the features described above.

SVN adopts a simple methodology when conflicts occur. A conflict is when two or more engineers make different changes to the same area of the code base and then both submit their changes. SVN only alerts the engineers that there is a conflict - it's up to the engineers to resolve it.

The first step is to install SVN on your system. Click here for instructions. Find your operating system and download the appropriate binary.

Some SVN Terminology

  • Revision: A change in a file or set of files. A revision is one "snapshot" in a constantly changing project.
  • Repository: The master copy where SVN stores a project's full revision history. Each project has one repository.
  • Working Copy: The copy in which an engineer make changes to a project. There can be many working copies of a given project each owned by an individual engineer.
  • Check Out: To request a working copy from the repository. A working copy equals the state of the project when it was checked out.
  • Commit: To send changes from your working copy into the central repository. Also known as check-in or submit.
  • Update: To bring others' changes from the repository into your working copy, or to indicate if your working copy has any uncommitted changes. This is the same as a sync, as described above. So, update/sync brings your working copy up-to-date with the repository copy.
  • Conflict: The situation when two engineers try to commit changes to the same area of a file. SVN indicates conflicts, but the engineers must resolve them.
  • Log message: A comment you attach to a revision when you commit it, which describes your changes. The log provides a summary of what's been going on in a project.

Getting Started with SVN

Now that you have SVN installed, we'll run through some basic commands. The first thing to do is set up a repository in a specified directory. Here are the commands:

$ svnadmin create /usr/local/svn/newrepos
$ svn import mytree file:///usr/local/svn/newrepos/project -m "Initial import"
Adding         mytree/foo.c
Adding         mytree/bar.c
Adding         mytree/subdir
Adding         mytree/subdir/foobar.h

Committed revision 1.

The import command copies the contents of directory mytree into the directory project in the repository. We can take a look at the directory in the repository with the list command

$ svn list file:///usr/local/svn/newrepos/project
bar.c
foo.c
subdir/

The import does not create a working copy. To do this, you need to use the svn checkout command. This creates a working copy of the directory tree. Let's do that now:

$ svn checkout file:///usr/local/svn/newrepos/project
A    foo.c
A    bar.c
A    subdir
A    subdir/foobar.h
.
Checked out revision 215.

Now that you have a working copy, you can make changes to the files and directories there. Your working copy is just like any other collection of files and directories - you can add new ones or edit them, move them around, you can even delete the entire working copy. Note that if you copy and move files in your working copy, it is important to use svn copy and svn move instead of your operating system commands. To add a new file, use svn add and to delete a file use svn delete. If all you want to do is edit, just open the file with your editor and edit away!

There are some standard directory names often used with Subversion. The "trunk" directory holds the main line of development for your project. A "branches" directory holds any branch version you might be working on.

$ svn list file:///usr/local/svn/repos
/trunk
/branches

So, let's say you have made all the required changes to your working copy and you want to sync it with the repository. If a lot of other engineers are working in this area of the repository, it's important to keep your working copy up-to-date. You can use the svn status command to view the changes that you have made.

A       subdir/new.h      # file is scheduled for addition
D       subdir/old.c        # file is scheduled for deletion
M       bar.c                  # the content in bar.c has local modifications
 

Note that there are lots of flags on the status command to control this output. If you'd like to view the specific changes in a modified file, use svn diff.

$ svn diff bar.c
Index: bar.c
===================================================================
--- bar.c	(revision 5)
+++ bar.c	(working copy)
@@ -1,18 +1,19 @@
+#include 
+#include 

 int main(void) {
-  int temp_var;
+ int new_var;
...

Finally, to update your working copy from the repository, use the svn update command.

$ svn update
U  foo.c
U  bar.c
G  subdir/foobar.h
C  subdir/new.h
Updated to revision 2.

This is one place where a conflict might occur. In the output above, the "U" indicates no changes were made to the repository versions of these files and an update was done. The "G" means a merge occurred. The repository version had been changed, but the changes did not conflict with yours. The "C" indicates a conflict. This means that the changes from the repository overlapped with yours, and now you have to choose between them.

For every file that has a conflict, Subversion puts three files in your working copy:

  • file.mine: This is your file as it existed in your working copy before you updated your working copy.
  • file.rOLDREV: This is the file you checked out of the repository prior to making your changes.
  • file.rNEWREV: This file is the current version in the repository.

You can do one of three things to resolve the conflict:

  • Go through the files and do the merge manually.
  • Copy one of the temporary files created by SVN over your working copy version.
  • Run svn revert to throw away all of your changes.

Once you've resolved the conflict, you let SVN know by running svn resolved. This removes the three temporary files and SVN no longer views the file in a conflict state.

The last thing to do is to commit your final version to the repository. This is done with the svn commit command. When you commit a change, you need to provide a log message, which describes your changes. This log message is attached to the revision you create.

svn commit -m "Update files to include new headers."

There is so much more to learn about SVN, and how it can support large software engineering projects. There are extensive resources available on the web - just do a Google search on Subversion.

References

Online Subversion Book

Wikipedia article on SVN

Subversion website