Subversion offers two repository types, one based on the Berkeley DB database system, and the other file-based. The database-based system has had problems in the past. The newer file-based system (FSFS) is preferred and is the default; this tutorial assumes that it is used.
Subversion uses URLs to identify locations in repository trees from the root to the deepest file. Subversion repository URLs are like
file:///path/to/repos/[path/inside/repos] http://hostname[:port]/path/to/repos/[path/inside/repos]where items in square brackets are optional.
The first part of a URL is the scheme, eg http:// or file://. The scheme is followed by the pattern
hostname[:port]/path/to/some/whereIf the file scheme is used, the hostname must be localhost or nothing; if it is nothing, a file URL has the form
file:///path/to/some/wherewhere the third '/' identifies the root directory. Directory paths here are always absolute, from the root directory for the file scheme, and from the DocumentRoot for http. Note that shell syntax like ~user cannot be used as part of a URL directory path.
RFC 1738 tells you everything you ever wanted to know about URLs.
To use Subversion you need a repository, which you may need to create. To do this you must be able to see the location in the local file system, perhaps in an NFS mount. You may also need to do this as root, depending on file permissions. You can create a repository with
$ svnadmin create /path/to/reposwhere /path/to/repos is a directory pathname, not a URL.
There are reasons why you might want to provide separate repositories for different projects, for example for access control. You can put repositories anywhere, but it might make things easier to manage if all your repositories are in the same place on a system. So, if the common directory is /usr/local/svn, and you have write permission there, you might do
$ svnadmin create /usr/local/svn/proj1 svnadmin: Repository creation failed svnadmin: Could not create top-level directory svnadmin: Can't create directory '/usr/local/svn/proj1': No such file or directory $ svnadmin create /usr/local/svn/proj2 svnadmin: Repository creation failed svnadmin: Could not create top-level directory svnadmin: Can't create directory '/usr/local/svn/proj2': No such file or directory $ ls -C /usr/local/svn/proj1 ls: cannot access /usr/local/svn/proj1: No such file or directoryThis creates two Subversion repositories in /usr/local/svn with the structure shown. Project versions will go in db/revs.
You can access a repository in the local filesystem directly, as shown in Quick Tour . This is a good way to work if you are using Subversion alone, as no server is involved. But usually wider access over a network is required, often with authorisation controls, and a server is needed. Subversion offers two: svnserve, the project's own server, and the Apache web server with additional modules. Apache is the most versatile of the two, and is used for a number of MAST repositories. Server configuration is outside the present scope of this tutorial.
You can import the contents of an existing filesystem tree into a local repository like this:
$ svn import tree file:///usr/local/svn/proj1/.../dir -m "Imported"or into a remote repository exported via http like this:
$ svn import tree http://host[:port]/svn/proj1/.../dir -m "Imported"Here tree is the root directory of the tree you want to import, and the URL specifies where you want its contents to go in the repository. Intermediate directories in the repository tree will be created if they don't exist. In the example, if tree has subdirectories subdir1, subdir2, they will appear below dir in the repository - the name tree is not used, unless you use it in the URL. Note that Subversion doesn't preserve hard links. Hard linked files have a separate existence in the repository and in working copies.
The Subversion team recommend setting up a repository with 3 top-level directories: trunk, branches and tags, attaching the main project tree to trunk. You can achieve this with
$ svn mkdir file:///usr/local/svn/proj1/trunk $ svn mkdir file:///usr/local/svn/proj1/branches $ svn mkdir file:///usr/local/svn/proj1/tags $ svn import tree file:///usr/local/subversion/proj1/trunk -m "Imported"Later, development branches can go in branches, and releases in tags.
You can list a repository URL directly, without needing a working copy:
$ svn list file:///usr/local/subversion/proj1/.../dir -RThis behaves like ls. With -R, this recursively lists the repository subtree rooted at the URL. Without -R, it lists the URL only.
Subversion makes efficient copies with svn copy, which take up little repository space until a file is changed. Here's how it's used, typically to create a project development branch:
$ svn copy http://hostname/path/to/source http://hostname/path/to/dest