Subversion

According to the Subversion web site, “The goal of the Subversion project is to build a version control system that is a compelling replacement for CVS in the open source community.” Enough said.

Pros

  • Newer than CVS and RCS.

  • Simpler and arguably easier to understand and use than CVS (less historical baggage).

  • Atomic commits means the commit either fails or succeeds as a whole, and makes it easy to track the state of an entire project as a single revision.

  • Easy to access remote repositories.

  • Allows easy renaming of files and directories while retaining history.

  • Easily handles binary files (no native diff support) and other objects such as symbolic links.

  • Central repository hacking is more officially supported, but less trivial.

Cons

  • Not 100 percent CVS compatible for more complicated projects (e.g., branching and tagging).

  • Can be more complicated to build or install from scratch due to many dependencies. Use the version that came with your operating system if possible.

Tip

SVN tracks revisions by repository, which means that each commit has its own internal SVN revision number. Thus consecutive commits by a single person may not have consecutive revision numbers since the global repository revision is incremented as other changes (possibly to other projects) are committed by other people.

Example

This example is not suitable for enterprise or multiuser access (see the “See Also” section for links to more information). This is just to show how easy the basics are. This example also has the EDITOR environment variable set to nano (export EDITOR='nano --smooth --const --nowrap --suspend'), which some people find more user-friendly than the default vi.

The svn help and svn help help commands are very useful.

Create a new repository for personal use in a home directory:

/home/jp$ svnadmin --fs-type=fsfs create /home/jp/svnroot

Create a new project and import it:

/home/jp$ cd /tmp

/tmp$ mkdir -p -m 0700 scripts/trunk scripts/tags scripts/branches

/tmp$ cd scripts/trunk

/tmp/scripts/trunk$ cat << EOF > hello
> #!/bin/sh
> echo 'Hello World!'
> EOF

/tmp/scripts/trunk$ cd ..

/tmp/scripts$ svn import /tmp/scripts file:///home/jp/svnroot/scripts

  GNU nano 1.2.4                   File: svn-commit.tmp

Initial import of shell scripts
--This line, and those below, will be ignored--

A   .
                                       [ Wrote 4 lines ]

Adding         /tmp/scripts/trunk
Adding         /tmp/scripts/trunk/hello
Adding         /tmp/scripts/branches
Adding         /tmp/scripts/tags

Committed revision 1.

Check out the project and update it:

/tmp/scripts$ cd

/home/jp$ svn checkout file:///home/jp/svnroot/scripts
A  scripts/trunk
A  scripts/trunk/hello
A  scripts/branches
A  scripts/tags
Checked out revision 1.

/home/jp$ cd scripts

/home/jp/scripts$ ls -l
total 12K
drwxr-xr-x  3 jp jp 4.0K Jul 20 01:12 branches/
drwxr-xr-x  3 jp jp 4.0K Jul 20 01:12 tags/
drwxr-xr-x  3 jp jp 4.0K Jul 20 01:12 trunk/

/home/jp/scripts$ cd trunk/

/home/jp/scripts/trunk$ ls -l
total 4.0K
-rw-r--r--  1 jp jp 30 Jul 20 01:12 hello

/home/jp/scripts/trunk$ echo "Hi Mom..." >> hello

Check the status of your sandbox. Note how the svn status command is similar to our cvs -qn update hack in the “CVS” section earlier in this appendix:

/home/jp/scripts/trunk$ svn info
Path: .
URL: file:///home/jp/svnroot/scripts/trunk
Repository UUID: 29eeb329-fc18-0410-967e-b075d748cc20
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: jp
Last Changed Rev: 1
Last Changed Date: 2006-07-20 01:04:56 -0400 (Thu, 20 Jul 2006)

/home/jp/scripts/trunk$ svn status -v
                1        1 jp           .
M               1        1 jp           hello

/home/jp/scripts/trunk$ svn status
M      hello

/home/jp/scripts/trunk$ svn update
At revision 1.

Add a new script to revision control:

/home/jp/scripts/trunk$ cat << EOF > mcd
> #!/bin/sh
> mkdir -p "$1"
> cd "$1"
> EOF

/home/jp/scripts/trunk$ svn st
?      mcd
M      hello
/home/jp/scripts/trunk$ svn add mcd
A         mcd

Commit changes:

/home/jp/scripts/trunk$ svn ci

  GNU nano 1.2.4                  File: svn-commit.tmp

* Tweaked hello
* Added mcd
--This line, and those below, will be ignored--

M    trunk/hello

A    trunk/mcd

                                       [ Wrote 6 lines ]

Sending        trunk/hello
Adding         trunk/mcd
Transmitting file data ..
Committed revision 2.

Update the sandbox, make another change, then check the difference:

/home/jp/scripts/trunk$ svn up
At revision 2.

/home/jp/scripts/trunk$ vi hello

/home/jp/scripts/trunk$ svn diff hello
Index: hello
===================================================================
--- hello        (revision 2)
+++ hello        (working copy)
@@ -1,3 +1,3 @@
 #!/bin/sh
 echo 'Hello World!'
-Hi Mom...
+echo 'Hi Mom...'

Commit the change, avoiding the editor by putting the log entry on the command line:

/home/jp/scripts/trunk$ svn -m '* Fixed syntax error' commit
Sending        trunk/hello
Transmitting file data .
Committed revision 3.

See the history of the file:

/home/jp/scripts/trunk$ svn log hello
------------------------------------------------------------------------
r3 | jp | 2006-07-20 01:23:35 -0400 (Thu, 20 Jul 2006) | 1 line

* Fixed syntax error
------------------------------------------------------------------------
r2 | jp | 2006-07-20 01:20:09 -0400 (Thu, 20 Jul 2006) | 3 lines
* Tweaked hello
* Added mcd

------------------------------------------------------------------------
r1 | jp | 2006-07-20 01:04:56 -0400 (Thu, 20 Jul 2006) | 2 lines

Initial import of shell scripts

------------------------------------------------------------------------

Add some revision metadata, and tell the system to expand it. Commit it and examine the change:

/home/jp/scripts/trunk$ vi hello

/home/jp/scripts/trunk$ cat hello
#!/bin/sh
# $Id$
echo 'Hello World!'
echo 'Hi Mom...'

home/jp/scripts/trunk$ svn propset svn:keywords "Id" hello
property 'svn:keywords' set on 'hello'

/home/jp/scripts/trunk$ svn ci -m'* Added ID keyword' hello
Sending        hello

Committed revision 4.

/home/jp/scripts/trunk$ cat hello
#!/bin/sh
# $Id: hello 5 2006-07-21 09:09:34Z jp $
echo 'Hello World!'
echo 'Hi Mom...'

Compare the current revision to r2, revert to that older (broken) revision, realize we goofed and get the most recent revision back:

/home/jp/scripts/trunk$ svn diff -r2 hello
Index: hello
===================================================================
--- hello       (revision 2)
+++ hello       (working copy)
@@ -1,3 +1,4 @@
 #!/bin/sh
+# $Id$
echo 'Hello World!'
-Hi Mom...
+echo 'Hi Mom...'

Property changes on: hello
______________________________________________________________ _ _ _ _ _

Name: svn:keywords
  + Id

/home/jp/scripts/trunk$ svn update -r2 hello
UU hello
Updated to revision 2.

/home/jp/scripts/trunk$ cat hello
#!/bin/sh
echo 'Hello World!'
Hi Mom...

/home/jp/scripts/trunk$ svn update -rHEAD hello
UU hello
Updated to revision 4.

/home/jp/scripts/trunk$ cat hello
#!/bin/sh
# $Id: hello 5 2006-07-21 09:09:34Z jp $
echo 'Hello World!'
echo 'Hi Mom...'

See Also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.205.223