HOWTOlabs Subversion
Sever Setup and Usage Tips

Elsewhere

Subversion is considered by many to be the successor to CVS for affordable electronic file version control.  Many Operating System distributions come with svn already installed.  For example Apple's OS X 10.5.X now includes svn 1.4.X, where previous releases required special installers.

Installing under Linux ...
# yum list \*subversion\*

  ...
  Available Packages
  subversion.i386         1.4.2-4.el5     base
  subversion-devel.i386   1.4.2-4.el5     base
  subversion-javahl.i386  1.4.2-4.el5     base
  subversion-perl.i386    1.4.2-4.el5     base
  subversion-ruby.i386    1.4.2-4.el5     base

# yum install subversion

  ...
  Installed: subversion.i386 0:1.4.2-4.el5
  Dependency Installed: apr.i386 0:1.2.7-11
  apr-util.i386 0:1.2.7-7.el5_3.1 neon.i386 0:0.25.5-10.el5
  perl-URI.noarch 0:1.35-3 postgresql-libs.i386 0:8.1.11-1.el5_1.1
  Complete!

# yum list \*inet\*

  ...
  Available Packages
  perl-IO-Socket-INET6.noarch                 2.51-2.fc6                      base
  xinetd.i386                                 2:2.3.14-10.el5                 base

# yum install xinetd 

  ...
  Installed: xinetd.i386 2:2.3.14-10.el5
  Complete! 
Create group (is this necessary?), create public/svn, create repository ...
$ ls -lhd /public/svn

  drwxrwsr-x 7 rickatech subvsn 4.0K Jul  5 20:40 /public/svn

$ svnadmin create /public/svn 
Import a simple project (using direct file mode) ...
$ ls -R um

  um: notes.txt

$ svn import um file:///public/svn/um -m "fp"

  Adding um/notes.txt
  Committed revision 1. 
Checkout project (using direct file mode) ...
$ svn co file:///public/svn/um

  A um/notes.txt
  Checked out revision 1.

$ ls -Ra

  .:         .  ..  um
  ./um:      .  ..  notes.txt  .svn
  ./um/.svn: .  ..  entries  format  prop-base  props  text-base  tmp
  ...

$ svn info um

  Path: um
  URL: file:///public/svn/um
  Repository Root: file:///public/svn
  Repository UUID: 2a33dff9-0b7b-49a1-a411-a1b6993661c1
  Revision: 2
  Node Kind: directory
  Schedule: normal
  Last Changed Author: rickatech
  Last Changed Rev: 2
  Last Changed Date: 2009-07-05 20:52:13 -0700 (Sun, 05 Jul 2009) 
Checkout project remotely ...
$ svn co file:///public/svn/um

$ svn co svn://192.168.2.24/um

  A um/notes.txt
  Checked out revision 1.

$ svn co svn://localhost/um

  ...  requires authentication, creates ~/.subversion user settings  ...

$ svn co svn co file:///public/svn/um

  ...  bypasses authentication, creates ~/.subversion user settings  ... 
Enable very simple user password authentication ...
# cd /public/svn

# ls -al

  conf
  dav
  db
  format
  hooks
  locks
  README.txt

# cd /public/svn/conf

# rcsdiff *

  diff -r1.1 passwd
  8a9,10
  > rickatech = 1234

  diff -r1.1 svnserve.conf
  11a12
  > anon-access = none
  18c19
  < # password-db = passwd
  ---
  > password-db = passwd

# service xinetd restart

  Stopping xinetd:  [  OK  ]
  Starting xinetd:  [  OK  ] 

Common commands ...

$ svn status

  M notes.txt

$ svn diff

  Index: notes.txt
  ================
  --- notes.txt	(revision 1)
  +++ notes.txt	(working copy)
  @@ -1 +1,3 @@
   This is a test!
  +
  +First change 

$ svn status -u

  *        public_htdocs/swfupload/swfupload.swf
  *        public_htdocs/swfupload
  *        public_htdocs/js/component_new.php
  *        public_htdocs/js/swfupload.queue.js
  *  223   public_htdocs/js/component_new.js
  *        public_htdocs/js/handlers.js
  *        public_htdocs/js/fileprogress.js
  *        public_htdocs/js/swfupload.js
  *        public_htdocs/js/swfupload_alt.js
  *  223   public_htdocs/js
  *        public_htdocs/XPButtonUploadText_61x22.png
  *  223   public_htdocs
  *  223   classes/ComponentNew.php
  Status against revision:    225

$ svn update

  A    public_htdocs/XPButtonUploadText_61x22.png
  A    public_htdocs/swfupload
  A    public_htdocs/swfupload/swfupload.swf
  D    public_htdocs/js/component_new.js
  A    public_htdocs/js/fileprogress.js
  A    public_htdocs/js/swfupload.js
  A    public_htdocs/js/swfupload_alt.js
  A    public_htdocs/js/component_new.php
  A    public_htdocs/js/swfupload.queue.js
  A    public_htdocs/js/handlers.js
  U    classes/ComponentNew.php
  Updated to revision 225.

$ svn delete foobar

  ... stay tuned ...

$ svn commit -m "some text description"

  ... stay tuned ... 
$ svn diff -r 1799:1800 email_tracker.php 

  [ show difference between past file versions ]

$ svn diff classes/Company.php -rBASE:HEAD 

  ... show diff of changes in head vs current local file? 

$ svn log summit-reg-barcode.php 

  ------------------------------------------------------------------------
  r2077 | ricks | 2009-10-01 10:42:53 -0700 (Thu, 01 Oct 2009) | 1 line

  size ...
  ------------------------------------------------------------------------
  r2075 | tobin | 2009-09-29 15:14:39 -0700 (Tue, 29 Sep 2009) | 1 line

  Updated ...
  ------------------------------------------------------------------------
  r2074 | ricks | 2009-09-25 14:34:55 -0700 (Fri, 25 Sep 2009) | 1 line

  as per ...
  ------------------------------------------------------------------------

$ svn diff -r2074:2075 summit-reg-barcode.php --diff-cmd diff -x -b

  23,24c23,24
  < $code->setScale(2); // Resolution
  < $code->setThickness(26); // Thickness
  ---
  > $code->setScale(4); // Resolution
  > $code->setThickness(30); // Thickness

  [ you can't do a diff between file versions in a
    tag/branch that doesn't contain both versions? ]

Review existing tags and branches.  Create a tag, delete a tag.

$ svn list https://svn.motmd.com/svn/foobar

  branches/
  tags/
  trunk/

$ svn list https://svn.motmd.com/svn/foobar/tags

  1.0.0/
  ...
  1.0rc3/

$ svn copy -m "Rick's patches" https://svn.motmd.com/svn/foobar/trunk https://svn.motmd.com/svn/foobar/tags/1.0.5

  ...

$ svn delete -m "poof" https://svn.motmd.com/svn/foobar/1.0.5

  ... 

Switch working files from trunk to branch.  This is a handy non-invasive way to see what files have changed since a branch was made.  Reverse the parameters to switch from branch back to trunk.

$ svn status

$ svn info | grep URL

  URL: .../svn/nimbus/trunk

$ svn switch .../svn/nimbus/tags/1.0.4

  D  public_htdocs/XPButtonUploadText_61x22.png
  D  public_htdocs/swfupload
  A  public_htdocs/flash
  A  public_htdocs/flash/swfupload_f9.swf
       ...
  U  nimbus.tmproj
  U  classes/ComponentNew.php

$ svn info | grep URL

  URL: .../nimbus/tags/1.0.4 

svnlook is a non-invasive command that works directly on the file system to get status and other state information.  It can not be used with a repository URL (red-bean.com).

$ svnlook diff -r 6185  /disk1/svn_repos/nor1upgrades

  Modified: trunk/include/classes/UtilsNor1.php
  ===================================================================
  --- trunk/include/classes/UtilsNor1.php	2010-08-10 16:41:21 UTC (rev 6184)
  +++ trunk/include/classes/UtilsNor1.php	2010-08-10 19:07:50 UTC (rev 6185)
  @@ -720,11 +720,20 @@
        $emailQueue->_type = EmailQueue::$_TYPE_EXTROOMCD;
        $emailQueue->_status = EmailQueue::$_STATUS_WAIT;
        if (self::hasValidObjStatus($property) && self::hasValidObjStatus($chain)) {
  -         $emailQueue->save();
  -         $emailQueue->_body = "Please add the room code '$code' into iProp (test system)\r\n"
  -                             ."Property: ".$property->_name." (".$chain->_name.")";
  -         $emailQueue->save();
  -     } else {
  +		$emailQueue->save();  /*  Note: email body is written to .../emails/[year]/[month]/...  */
  +		$emailQueue->_body  = "<!--\r\n<TEXT>\r\n";
  +		$emailQueue->_body .= "Please add the room code '$code' into iProp (test system)\r\n";
  +		$emailQueue->_body .= "Property: ".$property->_name." (".$chain->_name.")\r\n";
  +		$emailQueue->_body .= "\r\nURI:\r\n".$_SERVER['REQUEST_URI'].")\r\n";
  +		$emailQueue->_body .= "</TEXT>  -->\r\n";
  +		$emailQueue->_body .= "<HTML>";
  +		$emailQueue->_body .= "\n<p>Please add the room code '$code' into iProp (test system)";
  +		$emailQueue->_body .= "\n<br>Property: ".$property->_name." (".$chain->_name.")";
  +		$emailQueue->_body .= "\n\n<p>URI:\r\n".$_SERVER['REQUEST_URI'].")</p>";
  +		$emailQueue->_body .= "\n</HTML>\n";
  +		$emailQueue->save();
  +      }
  +	 else {
            return Errors::addDebug(__METHOD__, "No email, because property or chain is not active yet");
        }

$ svnlook log -r 6185  /disk1/svn_repos/nor1upgrades

  RESOLVED - bug 2214:  Include DLMI request URL in error email 
  https://bugs.nor1solutions.com/show_bug.cgi?id=2214 

$ svnlook info -r 6185  /disk1/svn_repos/nor1upgrades

  rarmstrong
  2010-08-10 19:07:50 +0000 (Tue, 10 Aug 2010)
  116
  RESOLVED - bug 2214:  Include DLMI request URL in error email 
  https://bugs.nor1solutions.com/show_bug.cgi?id=2214 
Handy Commands and Queries [edit]

Elsewhere

External command line diff

$svn diff -x -b --diff-cmd /usr/bin/diff 

Merging branch back into trunk

$ cd /var/www/proj1/

$ svn switch svn+ssh://qa.yours.com/svn_repos/proj1/branches/cp_addon_rick

$ svn info

  ...
  URL: svn+ssh://qa.yours.com/svn_repos/proj1/branches/cp_addon_rick
  Last Changed Rev: 776

$ svn log --verbose --stop-on-copy

  ------------------------------------------------------------------------
  r753 | rarmstrong | 2010-11-04 10:44:59 -0700 (Thu, 04 Nov 2010) | 1 line
  Changed paths:
     A /branches/cp_addon_rick (from /trunk:752)

  branch of trunk for control addon development
  ------------------------------------------------------------------------

So base revision when branch was made is 753, the latest branch revision is 776.

$ svn switch svn+ssh://qa.yours.com/svn_repos/proj1/trunk

$ svn merge -r 753:HEAD svn+ssh://qa.yours.com/svn_repos/proj1/branches/cp_addon_rick

  U ...

$ svn status

  M ...

Now preform diff's, check what will be committed.

$ svn commit -m "Merged branches/cp_addon_rick changes r341:405 into the trunk."

  Sending
  Committed revision 

Eventually after performing many merges strange double MM file modified and C file conflicts will occur.  The MM are harmless and can be ignored - they occur usually becuase checkout and commit are not taking place from the same directory.  Conflicts must be dealt with. Best to type p and then review the left and right merge files that will be created.  Often the conflict file must be removed and replaced with a clean merged file for the C to change to a M so that commit command will execute.

What about conflicts?

$ svn merge -r817:HEAD svn+ssh://qa.yours.com/svn_repos/proj1/branches/cp_addon_rick

  --- Merging r818 through r826 into '.':
  U    selfcontrolpanel/views/helpers/wizard.php
  U    selfcontrolpanel/views/dashboards/summary_form.ctp
  Conflict discovered in 'selfcontrolpanel/views/elements/menu.ctp'.
  Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p

$ svn status

  M       selfcontrolpanel/views/helpers/wizard.php
  M       selfcontrolpanel/views/dashboards/summary_form.ctp
  ?       selfcontrolpanel/views/elements/menu.ctp.merge-left.r817
  ?       selfcontrolpanel/views/elements/menu.ctp.merge-right.r826
  ?       selfcontrolpanel/views/elements/menu.ctp.working
  C       selfcontrolpanel/views/elements/menu.ctp 

Now you can review the conflict files, make changes accordingly, and perform final commit to trunk.  You may need to rename the confict file, pull down current file, then copy resolved conflicts back to the file.  The 'C' should now be a 'M' and commit can proceed.