SlideShare a Scribd company logo
1 of 30
Subversion Introduction & Best Practices


Martin Bergljung


On site | Monday 11 April 2011
Contents


Contents
• What’s subversion?
• Subversion architecture
• Subversion concepts
• Subversion usage
• Subversion best practices




                              2
What’s Subversion?

 • Apache Subversion is a software versioning and a revision control system founded
   and sponsored in 2000 by CollabNet Inc
     • Replaces CVS and improves on its faults
 • Developers use Subversion to maintain current and historical versions of files such as
   source code, web pages, and documentation
 • It is often abbreviated SVN, after the command name svn




                                                                                        3
Subversion Architecture
                            TortoiseSVN
                            IntelliJ SVN client
                            Eclipse SVN client
C:work> svn import ...




                                                  4
Subversion Concepts – the repository

 • Subversion is a centralized system for sharing information
 • At its core is a repository, which is a central store of data
 • The repository stores information in the form of a file system tree
      • a typical hierarchy of files and directories
 • Any number of clients connect to the repository, and then read or write to these files


                                  • Sounds like a file server, what’s the difference?
                                        •   It remembers every change ever written to it —
                                            every change to every file, and even changes to
                                            the directory tree itself, such as the addition,
                                            deletion, and rearrangement of files and
                                            directories.




                                                                                               5
Subversion Concepts – versioning models

 • The Problem with File Sharing:




                                          6
Subversion Concepts –
versioning models continued
 • The Lock-Modify-Unlock Solution:

                                      • This solution is used by many
                                        version control systems
                                      • The problem with it is:
                                          •   Locking may cause administrative
                                              problems
                                          •   Locking may cause unnecessary
                                              serialization
                                          •   Locking may create a false sense
                                              of security




                                                                            7
Subversion Concepts –
versioning models continued
                                      This solution is used by Subversion
 • The Copy-Modify-Merge Solution:




                                     But what if changes overlap?           8
Subversion Concepts – Repository URLs

 • Subversion uses URLs to identify versioned files and directories in Subversion
   repositories:
     • $ svn checkout http://svn.example.com:9834/repos
 • The schema part of the URL has the following meaning:




                                                                                    9
Subversion Concepts –
Repository URLs
 • Project specific URL:
     •   $ svn checkout    https://yourproject.svn.cvsdude.com/alfresco




                                                                          10
Subversion Concepts – Working Copies

 • A Subversion working copy is an ordinary directory tree on your local system,
   containing a collection of files
 • Your working copy is your own private work area
 • Each directory in your working copy contains a subdirectory named .svn

 • The following                     • To get a working copy of one of the example
   example shows                       projects you must checkout as follows:
   a repository
                                       $ svn checkout http://svn.example.com/repos/calc
   with two
   projects:




                                                                                          11
Subversion Concepts – Revisions

 • An svn commit operation publishes changes to any number of files and
   directories as a single atomic transaction
 • In your working copy, you can change files' contents; create, delete, rename, and
   copy files and directories; and then commit a complete set of changes as an atomic
   transaction
 • Each time the repository accepts a commit, this creates a new state of the file
   system tree, called a revision:




                                                                                        12
Subversion Concepts – trunk, branch, tag

 • When laying out the repository for a project there are a couple of concepts that we will
   come in contact with: trunk, branches, and tags – so what do they mean?
 • trunk - main development area
     • This is where your next major release of the code lives
     • Generally has all the newest features
 • branch – a copy of code derived from a certain point in trunk
     • when a new version is released from trunk it is often custom to create a branch for
       maintenance purposes
     • This allows you to do bug fixes and make a new release without having to release the
       newest - possibly unfinished or untested - features
     • If the bug fixes work according to plan, they are usually merged back into the trunk
 • tag - a point in time on the trunk or a branch that you wish to preserve
     • Such as a major release of the software, whether alpha, beta, RC or GA


                                                                                              13
Subversion Usage – Initial Checkout

 • Most of the time, you will start using a Subversion repository by doing a checkout of
   your project
 • Checking out a repository creates a working copy of it on your local machine
 • This copy contains the HEAD (latest revision) of the Subversion repository that you
   specify on the command line:

     • $ svn checkout http://svn.example.com/repos/calc



                              While your working copy is “just like any other collection of files and
                              directories on your system,” you can edit files at will, but you must
                              tell Subversion about everything else that you do. For example, if
                              you want to copy or move an item in a working copy, you should use
                              svn copy or svn move instead of the copy and move
                              commands provided by your operating system

                                                                                                 14
Subversion Usage – Initial Checkout

 • For example if the main project is called alfresco you can check it out with the following
   command:
      •   $ svn checkout https://yourproject.svn.cvsdude.com/alfresco/_training

 • From TortoiseSVN you would do it like this:
     Right-click in the folder
                                    Then select                   Then enter URL
     where you want to
                                    SVN Checkout...               here
     check-out source code




                                                                                          15
Subversion Usage – Day-to-Day

• At the start of the day you would typically update your working copy:
         • $ svn update
•   Then you would go ahead and make changes, updating files, adding files:
         • $ svn add foo.txt
• Deleting files:
         • $ svn delete bar.txt
• Making new directories:
         • $ svn mkdir test
• And finally you would commit your changes:
         • $ svn commit -m "JIRA-101 - Corrected number of cheese
           slices."




                                                                              16
Subversion Usage – Day-to-Day – Update

 • At the start of the day you would typically update your working copy
 • Right click on the top directory (i.e. ‘alfresco’ in this case)
 • Then Select SVN Update




                                                                          17
Subversion Usage – Day-to-Day – Add

 • Right click on the file you want to add
 • Then Select TortoiseSVN
 • And then select Add...




 • The file will now be displayed as follows:



                                                18
Subversion Usage – Day-to-Day – Delete

 • Right click on the file you want to delete
 • Then Select TortoiseSVN
 • And then select Delete




                                                19
Subversion Usage – Day-to-Day – Making a new
directory
 • Same as adding
 • Just create the directory and then follow same procedure as for adding file




                                                                                 20
Subversion Usage – Day-to-Day – Committing
changes
 • When you are done with adding files and directories, updating files, and deleting
   files and directories, then you need to commit to persist these updates in the
   repository
 • Right click on the top folder under which all changes have been done
 • Then Select SVN Commit..., in the next dialog specify log message, commit by
   pressing OK button




                                                                                       21
Best Practices (1) –
Use a sane repository layout
 • There are many ways to lay out your repository
 • The Subversion project officially recommends the idea of a "project root", which
   represents an anchoring point for a project
 • A "project root" contains exactly three subdirectories:
      • /branches
      • /tags
      • /trunk
 • A repository may contain only one project root, or it may contain a number of them
 • Example:
      • /alfresco
           • /share-customizations-phase1
                 • /branches
                 • /tags
                 • /trunk


                                                                                        22
Best Practices (2) –
Commit logical change sets
 • When you commit a change to the repository, make sure your change reflects a
   single purpose:
     • the fixing of a specific bug,
     • the addition of a new feature,
     • or some particular task
 • Your commit will create a new revision number which can forever be used as a
   "name" for the change.
 • You can mention this revision number in bug databases, or use it as an argument
   to svn merge should you want to undo the change or port it to another branch




                                                                                     23
Best Practices (3) –
Use the issue-tracker wisely
 • Try to create as many two-way links between Subversion change sets and your
   issue-tracking database as possible:
     • If possible, refer to a specific issue ID in every commit log message
     • When appending information to an issue (to describe progress, or to close the issue)
       name the revision number(s) responsible for the change




                                                                                              24
Best Practices (4) – Track merges manually

 • When committing the result of a merge, be sure to write a descriptive log message
   that explains what was merged, something like:
     • Merged revisions 3490:4120 of /branches/1.1-maintenance to /trunk.
 • The above example log message tells us that all changes in revision 3490 to
   revision 4120 in the 1.1-maintenance branch were merged over to trunk




                                                                                       25
Best Practices (5) –
Understand mixed-revision working copies
 • Your working copy's directories and files can be at different "working" revisions
 • This is a deliberate feature which allows you to mix and match older versions of
   things with newer ones. But there are few facts you must be aware of:
      1. After every svn commit, your working copy has mixed revisions
           •   The things you just committed are now at the HEAD revision, and everything else is at an
               older revision.
      2. Certain commits are disallowed:
           •   You cannot commit the deletion of a file or directory which doesn't have a working revision
               of HEAD.
           •   You cannot commit a property change to a directory which doesn't have a working revision
               of HEAD.
      3. svn update will bring your entire working copy to one working revision, and is the
         typical solution to the problems mentioned in point #2.




                                                                                                             26
Best Practices (6a) –
Know when to create branches
 • The Never-Branch system (policy 1)
      • (Often used by nascent projects that don't yet have runnable code.)
 • Users commit their day-to-day work on /trunk
 • Occasionally /trunk "breaks" (doesn't compile, or fails functional tests) when a user
   begins to commit a series of complicated changes
      • Pros: Very easy policy to follow. New developers have low barrier to entry. Nobody
        needs to learn how to branch or merge.
      • Cons: Chaotic development, code could be unstable at any time




                                                                                             27
Best Practices (6b) –
Know when to create branches
 • The Always-Branch system (policy 2)
     • (Often used by projects that favour heavy management and supervision.)
 • Each user creates/works on a private branch for every coding task
 • When coding is complete, someone (original coder, peer, or manager) reviews all
   private branch changes and merges them to /trunk
     • Pros: /trunk is guaranteed to be extremely stable at all times
     • Cons: Coders are artificially isolated from each other, possibly creating more merge
       conflicts than necessary. Requires users to do lots of extra merging




                                                                                              28
Best Practices (6c) –
Know when to create branches
 • The Branch-When-Needed system (policy 3)
     • (This is the system used by the Subversion project)
 • Users commit their day-to-day work on /trunk
          • Rule #1: /trunk must compile and pass regression tests at all times. Committers who violate
            this rule are publically humiliated
          • Rule #2: a single commit (change set) must not be so large so as to discourage peer-review
          • Rule #3: if rules #1 and #2 come into conflict (i.e. it's impossible to make a series of small
            commits without disrupting the trunk), then the user should create a branch and commit a
            series of smaller change sets there. This allows peer-review without disrupting the stability of
            /trunk.
     • Pros: /trunk is guaranteed to be stable at all times. The hassle of branching/merging is
       somewhat rare.
     • Cons: Adds a bit of burden to users' daily work: they must compile and test before
       every commit.



                                                                                                               29
Best Practices (7) –
Trunk, branching, and tagging during release




                                               30

More Related Content

What's hot

Totalsvn Usage And Administration By Gopi
Totalsvn Usage And Administration By GopiTotalsvn Usage And Administration By Gopi
Totalsvn Usage And Administration By Gopigopinathkarangula
 
Linux Performance Analysis and Tools
Linux Performance Analysis and ToolsLinux Performance Analysis and Tools
Linux Performance Analysis and ToolsBrendan Gregg
 
The dream is alive! Running Linux containers on an illumos kernel
The dream is alive! Running Linux containers on an illumos kernelThe dream is alive! Running Linux containers on an illumos kernel
The dream is alive! Running Linux containers on an illumos kernelbcantrill
 
LinuxTag13: 10 years of Xen and beyond
LinuxTag13: 10 years of Xen and beyondLinuxTag13: 10 years of Xen and beyond
LinuxTag13: 10 years of Xen and beyondThe Linux Foundation
 
IBM Domino / IBM Notes Performance Tuning
IBM Domino / IBM Notes Performance Tuning IBM Domino / IBM Notes Performance Tuning
IBM Domino / IBM Notes Performance Tuning Vladislav Tatarincev
 
Dueling duplications RMAN vs Delphix
Dueling duplications RMAN vs DelphixDueling duplications RMAN vs Delphix
Dueling duplications RMAN vs DelphixKyle Hailey
 
Xen Project Update LinuxCon Brazil
Xen Project Update LinuxCon BrazilXen Project Update LinuxCon Brazil
Xen Project Update LinuxCon BrazilThe Linux Foundation
 
Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?
Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?
Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?panagenda
 
What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...
What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...
What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...Novell
 
XCP: The Art of Open Virtualization for the Enterprise and the Cloud
XCP: The Art of Open Virtualization for the Enterprise and the CloudXCP: The Art of Open Virtualization for the Enterprise and the Cloud
XCP: The Art of Open Virtualization for the Enterprise and the CloudThe Linux Foundation
 
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, VerseNext Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, VerseVladislav Tatarincev
 
Engage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance BoostEngage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance BoostChristoph Adler
 
Experiences porting KVM to SmartOS
Experiences porting KVM to SmartOSExperiences porting KVM to SmartOS
Experiences porting KVM to SmartOSbcantrill
 
You don't want to do it like that
You don't want to do it like thatYou don't want to do it like that
You don't want to do it like thatSharon James
 
Understanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksUnderstanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksJignesh Shah
 
S4 xen hypervisor_20080622
S4 xen hypervisor_20080622S4 xen hypervisor_20080622
S4 xen hypervisor_20080622Todd Deshane
 
Connections install in 45 mins
Connections install in 45 minsConnections install in 45 mins
Connections install in 45 minsSharon James
 
Ceph, Xen, and CloudStack: Semper Melior-XPUS13 McGarry
Ceph, Xen, and CloudStack: Semper Melior-XPUS13 McGarryCeph, Xen, and CloudStack: Semper Melior-XPUS13 McGarry
Ceph, Xen, and CloudStack: Semper Melior-XPUS13 McGarryThe Linux Foundation
 
Xen: Hypervisor for the Cloud - CCC13
Xen: Hypervisor for the Cloud - CCC13Xen: Hypervisor for the Cloud - CCC13
Xen: Hypervisor for the Cloud - CCC13The Linux Foundation
 

What's hot (20)

Totalsvn Usage And Administration By Gopi
Totalsvn Usage And Administration By GopiTotalsvn Usage And Administration By Gopi
Totalsvn Usage And Administration By Gopi
 
Linux Performance Analysis and Tools
Linux Performance Analysis and ToolsLinux Performance Analysis and Tools
Linux Performance Analysis and Tools
 
The dream is alive! Running Linux containers on an illumos kernel
The dream is alive! Running Linux containers on an illumos kernelThe dream is alive! Running Linux containers on an illumos kernel
The dream is alive! Running Linux containers on an illumos kernel
 
LinuxTag13: 10 years of Xen and beyond
LinuxTag13: 10 years of Xen and beyondLinuxTag13: 10 years of Xen and beyond
LinuxTag13: 10 years of Xen and beyond
 
IBM Domino / IBM Notes Performance Tuning
IBM Domino / IBM Notes Performance Tuning IBM Domino / IBM Notes Performance Tuning
IBM Domino / IBM Notes Performance Tuning
 
Drop the Pressure on your Production Server
Drop the Pressure on your Production ServerDrop the Pressure on your Production Server
Drop the Pressure on your Production Server
 
Dueling duplications RMAN vs Delphix
Dueling duplications RMAN vs DelphixDueling duplications RMAN vs Delphix
Dueling duplications RMAN vs Delphix
 
Xen Project Update LinuxCon Brazil
Xen Project Update LinuxCon BrazilXen Project Update LinuxCon Brazil
Xen Project Update LinuxCon Brazil
 
Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?
Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?
Engage 2020 - Kubernetes for HCL Connections Component Pack - Build or Buy?
 
What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...
What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...
What's LUM Got To Do with It: Deployment Considerations for Linux User Manage...
 
XCP: The Art of Open Virtualization for the Enterprise and the Cloud
XCP: The Art of Open Virtualization for the Enterprise and the CloudXCP: The Art of Open Virtualization for the Enterprise and the Cloud
XCP: The Art of Open Virtualization for the Enterprise and the Cloud
 
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, VerseNext Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
Next Generation Monitoring for IBM Domino, Traveler, IMSMO, Verse
 
Engage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance BoostEngage 2020 - HCL Notes V11 Performance Boost
Engage 2020 - HCL Notes V11 Performance Boost
 
Experiences porting KVM to SmartOS
Experiences porting KVM to SmartOSExperiences porting KVM to SmartOS
Experiences porting KVM to SmartOS
 
You don't want to do it like that
You don't want to do it like thatYou don't want to do it like that
You don't want to do it like that
 
Understanding PostgreSQL LW Locks
Understanding PostgreSQL LW LocksUnderstanding PostgreSQL LW Locks
Understanding PostgreSQL LW Locks
 
S4 xen hypervisor_20080622
S4 xen hypervisor_20080622S4 xen hypervisor_20080622
S4 xen hypervisor_20080622
 
Connections install in 45 mins
Connections install in 45 minsConnections install in 45 mins
Connections install in 45 mins
 
Ceph, Xen, and CloudStack: Semper Melior-XPUS13 McGarry
Ceph, Xen, and CloudStack: Semper Melior-XPUS13 McGarryCeph, Xen, and CloudStack: Semper Melior-XPUS13 McGarry
Ceph, Xen, and CloudStack: Semper Melior-XPUS13 McGarry
 
Xen: Hypervisor for the Cloud - CCC13
Xen: Hypervisor for the Cloud - CCC13Xen: Hypervisor for the Cloud - CCC13
Xen: Hypervisor for the Cloud - CCC13
 

Viewers also liked

Annual Powerpoint
Annual PowerpointAnnual Powerpoint
Annual Powerpointsgast32
 
Connected Educator
Connected Educator Connected Educator
Connected Educator Kim Sivick
 
E retail marketing october 2012
E retail marketing october 2012E retail marketing october 2012
E retail marketing october 2012Nikos Varvadoukas
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting PersonalKirsty Hulse
 

Viewers also liked (6)

Windows 8
Windows 8Windows 8
Windows 8
 
Annual Powerpoint
Annual PowerpointAnnual Powerpoint
Annual Powerpoint
 
Connected Educator
Connected Educator Connected Educator
Connected Educator
 
Wine mnfng
Wine mnfngWine mnfng
Wine mnfng
 
E retail marketing october 2012
E retail marketing october 2012E retail marketing october 2012
E retail marketing october 2012
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 

Similar to Random House

Version Control With Subversion
Version Control With SubversionVersion Control With Subversion
Version Control With SubversionSamnang Chhun
 
Slide set 7 (Source Code Management History Overview) - Copy.pptx
Slide set 7 (Source Code Management History  Overview) - Copy.pptxSlide set 7 (Source Code Management History  Overview) - Copy.pptx
Slide set 7 (Source Code Management History Overview) - Copy.pptxUTKARSHBHARDWAJ71
 
SVN Tool Information : Best Practices
SVN Tool Information  : Best PracticesSVN Tool Information  : Best Practices
SVN Tool Information : Best PracticesMaidul Islam
 
Source version control using subversion
Source version control using subversionSource version control using subversion
Source version control using subversionMangesh Bhujbal
 
Version Control and Continuous Integration
Version Control and Continuous IntegrationVersion Control and Continuous Integration
Version Control and Continuous IntegrationGeff Henderson Chang
 
Drupal Version Control & File System Basics
Drupal Version Control & File System BasicsDrupal Version Control & File System Basics
Drupal Version Control & File System BasicsJulia Kulla-Mader
 
Grasp(eo) versioning system Final presentation
Grasp(eo) versioning system Final presentationGrasp(eo) versioning system Final presentation
Grasp(eo) versioning system Final presentationNikita Grishin
 
version controlling in software development
version controlling in software developmentversion controlling in software development
version controlling in software developmentAnushka Perera
 
Linux13 concurrent versions system
Linux13 concurrent versions systemLinux13 concurrent versions system
Linux13 concurrent versions systemJainul Musani
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Paradigma Digital
 
Dita Release Management
Dita Release ManagementDita Release Management
Dita Release Managementjlborie
 
Productivity 101: Making a Easily Re-deployable Dev Environment with Subversion
Productivity 101: Making a Easily Re-deployable Dev Environment with SubversionProductivity 101: Making a Easily Re-deployable Dev Environment with Subversion
Productivity 101: Making a Easily Re-deployable Dev Environment with Subversionryanduff
 
Source Code Management Slides
Source Code Management SlidesSource Code Management Slides
Source Code Management Slidesdaschuck
 

Similar to Random House (20)

SVN
SVNSVN
SVN
 
Version Control With Subversion
Version Control With SubversionVersion Control With Subversion
Version Control With Subversion
 
Slide set 7 (Source Code Management History Overview) - Copy.pptx
Slide set 7 (Source Code Management History  Overview) - Copy.pptxSlide set 7 (Source Code Management History  Overview) - Copy.pptx
Slide set 7 (Source Code Management History Overview) - Copy.pptx
 
Subversion last minute survival crash course
Subversion  last minute survival crash courseSubversion  last minute survival crash course
Subversion last minute survival crash course
 
SVN Information
SVN Information  SVN Information
SVN Information
 
SVN Tool Information : Best Practices
SVN Tool Information  : Best PracticesSVN Tool Information  : Best Practices
SVN Tool Information : Best Practices
 
Source version control using subversion
Source version control using subversionSource version control using subversion
Source version control using subversion
 
Version Control and Continuous Integration
Version Control and Continuous IntegrationVersion Control and Continuous Integration
Version Control and Continuous Integration
 
Svn workflow
Svn workflowSvn workflow
Svn workflow
 
Versioning for Developers
Versioning for DevelopersVersioning for Developers
Versioning for Developers
 
Drupal Version Control & File System Basics
Drupal Version Control & File System BasicsDrupal Version Control & File System Basics
Drupal Version Control & File System Basics
 
Subversion
SubversionSubversion
Subversion
 
Grasp(eo) versioning system Final presentation
Grasp(eo) versioning system Final presentationGrasp(eo) versioning system Final presentation
Grasp(eo) versioning system Final presentation
 
version controlling in software development
version controlling in software developmentversion controlling in software development
version controlling in software development
 
Linux13 concurrent versions system
Linux13 concurrent versions systemLinux13 concurrent versions system
Linux13 concurrent versions system
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?
 
Dita Release Management
Dita Release ManagementDita Release Management
Dita Release Management
 
Productivity 101: Making a Easily Re-deployable Dev Environment with Subversion
Productivity 101: Making a Easily Re-deployable Dev Environment with SubversionProductivity 101: Making a Easily Re-deployable Dev Environment with Subversion
Productivity 101: Making a Easily Re-deployable Dev Environment with Subversion
 
Source control
Source controlSource control
Source control
 
Source Code Management Slides
Source Code Management SlidesSource Code Management Slides
Source Code Management Slides
 

Random House

  • 1. Subversion Introduction & Best Practices Martin Bergljung On site | Monday 11 April 2011
  • 2. Contents Contents • What’s subversion? • Subversion architecture • Subversion concepts • Subversion usage • Subversion best practices 2
  • 3. What’s Subversion? • Apache Subversion is a software versioning and a revision control system founded and sponsored in 2000 by CollabNet Inc • Replaces CVS and improves on its faults • Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation • It is often abbreviated SVN, after the command name svn 3
  • 4. Subversion Architecture TortoiseSVN IntelliJ SVN client Eclipse SVN client C:work> svn import ... 4
  • 5. Subversion Concepts – the repository • Subversion is a centralized system for sharing information • At its core is a repository, which is a central store of data • The repository stores information in the form of a file system tree • a typical hierarchy of files and directories • Any number of clients connect to the repository, and then read or write to these files • Sounds like a file server, what’s the difference? • It remembers every change ever written to it — every change to every file, and even changes to the directory tree itself, such as the addition, deletion, and rearrangement of files and directories. 5
  • 6. Subversion Concepts – versioning models • The Problem with File Sharing: 6
  • 7. Subversion Concepts – versioning models continued • The Lock-Modify-Unlock Solution: • This solution is used by many version control systems • The problem with it is: • Locking may cause administrative problems • Locking may cause unnecessary serialization • Locking may create a false sense of security 7
  • 8. Subversion Concepts – versioning models continued This solution is used by Subversion • The Copy-Modify-Merge Solution: But what if changes overlap? 8
  • 9. Subversion Concepts – Repository URLs • Subversion uses URLs to identify versioned files and directories in Subversion repositories: • $ svn checkout http://svn.example.com:9834/repos • The schema part of the URL has the following meaning: 9
  • 10. Subversion Concepts – Repository URLs • Project specific URL: • $ svn checkout https://yourproject.svn.cvsdude.com/alfresco 10
  • 11. Subversion Concepts – Working Copies • A Subversion working copy is an ordinary directory tree on your local system, containing a collection of files • Your working copy is your own private work area • Each directory in your working copy contains a subdirectory named .svn • The following • To get a working copy of one of the example example shows projects you must checkout as follows: a repository $ svn checkout http://svn.example.com/repos/calc with two projects: 11
  • 12. Subversion Concepts – Revisions • An svn commit operation publishes changes to any number of files and directories as a single atomic transaction • In your working copy, you can change files' contents; create, delete, rename, and copy files and directories; and then commit a complete set of changes as an atomic transaction • Each time the repository accepts a commit, this creates a new state of the file system tree, called a revision: 12
  • 13. Subversion Concepts – trunk, branch, tag • When laying out the repository for a project there are a couple of concepts that we will come in contact with: trunk, branches, and tags – so what do they mean? • trunk - main development area • This is where your next major release of the code lives • Generally has all the newest features • branch – a copy of code derived from a certain point in trunk • when a new version is released from trunk it is often custom to create a branch for maintenance purposes • This allows you to do bug fixes and make a new release without having to release the newest - possibly unfinished or untested - features • If the bug fixes work according to plan, they are usually merged back into the trunk • tag - a point in time on the trunk or a branch that you wish to preserve • Such as a major release of the software, whether alpha, beta, RC or GA 13
  • 14. Subversion Usage – Initial Checkout • Most of the time, you will start using a Subversion repository by doing a checkout of your project • Checking out a repository creates a working copy of it on your local machine • This copy contains the HEAD (latest revision) of the Subversion repository that you specify on the command line: • $ svn checkout http://svn.example.com/repos/calc While your working copy is “just like any other collection of files and directories on your system,” you can edit files at will, but you must tell Subversion about everything else that you do. For example, if you want to copy or move an item in a working copy, you should use svn copy or svn move instead of the copy and move commands provided by your operating system 14
  • 15. Subversion Usage – Initial Checkout • For example if the main project is called alfresco you can check it out with the following command: • $ svn checkout https://yourproject.svn.cvsdude.com/alfresco/_training • From TortoiseSVN you would do it like this: Right-click in the folder Then select Then enter URL where you want to SVN Checkout... here check-out source code 15
  • 16. Subversion Usage – Day-to-Day • At the start of the day you would typically update your working copy: • $ svn update • Then you would go ahead and make changes, updating files, adding files: • $ svn add foo.txt • Deleting files: • $ svn delete bar.txt • Making new directories: • $ svn mkdir test • And finally you would commit your changes: • $ svn commit -m "JIRA-101 - Corrected number of cheese slices." 16
  • 17. Subversion Usage – Day-to-Day – Update • At the start of the day you would typically update your working copy • Right click on the top directory (i.e. ‘alfresco’ in this case) • Then Select SVN Update 17
  • 18. Subversion Usage – Day-to-Day – Add • Right click on the file you want to add • Then Select TortoiseSVN • And then select Add... • The file will now be displayed as follows: 18
  • 19. Subversion Usage – Day-to-Day – Delete • Right click on the file you want to delete • Then Select TortoiseSVN • And then select Delete 19
  • 20. Subversion Usage – Day-to-Day – Making a new directory • Same as adding • Just create the directory and then follow same procedure as for adding file 20
  • 21. Subversion Usage – Day-to-Day – Committing changes • When you are done with adding files and directories, updating files, and deleting files and directories, then you need to commit to persist these updates in the repository • Right click on the top folder under which all changes have been done • Then Select SVN Commit..., in the next dialog specify log message, commit by pressing OK button 21
  • 22. Best Practices (1) – Use a sane repository layout • There are many ways to lay out your repository • The Subversion project officially recommends the idea of a "project root", which represents an anchoring point for a project • A "project root" contains exactly three subdirectories: • /branches • /tags • /trunk • A repository may contain only one project root, or it may contain a number of them • Example: • /alfresco • /share-customizations-phase1 • /branches • /tags • /trunk 22
  • 23. Best Practices (2) – Commit logical change sets • When you commit a change to the repository, make sure your change reflects a single purpose: • the fixing of a specific bug, • the addition of a new feature, • or some particular task • Your commit will create a new revision number which can forever be used as a "name" for the change. • You can mention this revision number in bug databases, or use it as an argument to svn merge should you want to undo the change or port it to another branch 23
  • 24. Best Practices (3) – Use the issue-tracker wisely • Try to create as many two-way links between Subversion change sets and your issue-tracking database as possible: • If possible, refer to a specific issue ID in every commit log message • When appending information to an issue (to describe progress, or to close the issue) name the revision number(s) responsible for the change 24
  • 25. Best Practices (4) – Track merges manually • When committing the result of a merge, be sure to write a descriptive log message that explains what was merged, something like: • Merged revisions 3490:4120 of /branches/1.1-maintenance to /trunk. • The above example log message tells us that all changes in revision 3490 to revision 4120 in the 1.1-maintenance branch were merged over to trunk 25
  • 26. Best Practices (5) – Understand mixed-revision working copies • Your working copy's directories and files can be at different "working" revisions • This is a deliberate feature which allows you to mix and match older versions of things with newer ones. But there are few facts you must be aware of: 1. After every svn commit, your working copy has mixed revisions • The things you just committed are now at the HEAD revision, and everything else is at an older revision. 2. Certain commits are disallowed: • You cannot commit the deletion of a file or directory which doesn't have a working revision of HEAD. • You cannot commit a property change to a directory which doesn't have a working revision of HEAD. 3. svn update will bring your entire working copy to one working revision, and is the typical solution to the problems mentioned in point #2. 26
  • 27. Best Practices (6a) – Know when to create branches • The Never-Branch system (policy 1) • (Often used by nascent projects that don't yet have runnable code.) • Users commit their day-to-day work on /trunk • Occasionally /trunk "breaks" (doesn't compile, or fails functional tests) when a user begins to commit a series of complicated changes • Pros: Very easy policy to follow. New developers have low barrier to entry. Nobody needs to learn how to branch or merge. • Cons: Chaotic development, code could be unstable at any time 27
  • 28. Best Practices (6b) – Know when to create branches • The Always-Branch system (policy 2) • (Often used by projects that favour heavy management and supervision.) • Each user creates/works on a private branch for every coding task • When coding is complete, someone (original coder, peer, or manager) reviews all private branch changes and merges them to /trunk • Pros: /trunk is guaranteed to be extremely stable at all times • Cons: Coders are artificially isolated from each other, possibly creating more merge conflicts than necessary. Requires users to do lots of extra merging 28
  • 29. Best Practices (6c) – Know when to create branches • The Branch-When-Needed system (policy 3) • (This is the system used by the Subversion project) • Users commit their day-to-day work on /trunk • Rule #1: /trunk must compile and pass regression tests at all times. Committers who violate this rule are publically humiliated • Rule #2: a single commit (change set) must not be so large so as to discourage peer-review • Rule #3: if rules #1 and #2 come into conflict (i.e. it's impossible to make a series of small commits without disrupting the trunk), then the user should create a branch and commit a series of smaller change sets there. This allows peer-review without disrupting the stability of /trunk. • Pros: /trunk is guaranteed to be stable at all times. The hassle of branching/merging is somewhat rare. • Cons: Adds a bit of burden to users' daily work: they must compile and test before every commit. 29
  • 30. Best Practices (7) – Trunk, branching, and tagging during release 30