Lecture Notes on Subversion (COMP 303)

Subversion is a free/open-source version control system

History of Subversion

Basics: the Repository

  • The repository is a central store of data;
  • storing information in a file system tree.
  • Any number of clients can connect to the repository and then read or write files in the repository.
  • By writing files the client is making files available to others.
  • By reading files the client is receiving info from others.
[clientserver]

Basics: the Repository (2)

  • The repository remembers every change to every file and even additions and deletions in the directory tree.
  • When a client reads from the repository, normally it only sees the latest version of the filesytem;
  • but client can also view previous states of the filesystem.
    • What did this directory contain last Wednesday?
    • Who was the last person to change this file?
    • What changes did Laurie make to this file?
    • Give me the version of my code that worked yesterday.
[clientserver]

Versioning Models -Problem to avoid

[ProblemToAvoid]

Lock-Modify-Unlock Solution

[LockModifyUnlock]
But, may cause admin problems, unnecessary serialization and a false sense of security.

The Copy-Modify-Merge Solution

[CopyModifyMerge1]

The Copy-Modify-Merge Solution (2)

[CopyModifyMerge2]

Working Copies

  • working copy is an ordinary directory on your local system
  • you edit these files, test
  • when you are ready you publish your changes by writing to the repository
  • if someone else has already changed a file or files, you will have to merge the newer one with yours before being allowed to write
  • working copy has extra files in .svn directory known as the working copy administrative directory
  • a typical Subversion repository contains files for several projects, a working copy for a specific project will only have the relevant subtree.
[filesystem]

Working Copies (2)

  • To get an initial working copy you must check out some subtree of the repository.
  • To get a working copy of the calc project:
    $ svn checkout http://svn.example.com/repos/calc
    A  calc
    A  calc/Makefile
    A  calc/integer.c
    A  calc/button.c
    
    $ ls -A calc
    Makefile  integer.c  button.c  .svn/
    
  • There are several ways of accessing a repository, the two you might use are:
    • file:/// (direct access on a local disk)
    • svn+ssh:// (using custom protocol of svnserve via an SSH tunnel)
    • Once you checkout a project, subsequent accesses do not need the full specifier, the information needed is in the local working copy.
[filesystem]

Making a change

  • Suppose you want to change button.c .
  • You edit the file as normal.
  • The new modification time and date will be more recent than the time and date of the file in the repository.
  • You publish your change by committing your file to the repository:
    $ svn commit button.c
    Sending        button.c
    Transmitting file data .
    Committed revision 57.
    
[filesystem]

What if someone else had a working copy?

  • Suppose Sally was also working on the project.
  • Now her copy of the button.c file will be out of date.
  • Sally can ask to bring her working copy up to date by:
    $ pwd
    /home/sally/calc
    $ ls -A 
    .svn/ Makefile integer.c button.c
    $ svn update
    U button.c 
    
  • Subversion only updates those files that have been changed.
  • Update often if working on a group project!
[filesystem]

Revisions

Revisions (2)

[revisions]

The states of files in your working directory

Subversion Architecture

[architecture]

Creating your repository on the teaching labs at McGill

Creating your working copy

After you have your working directory, some useful commands are:


Some more tips