SVN Usage & Best Practices


Published on

Published in: Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • SVN Usage & Best Practices

    1. 1. Source control using SVN Prepared by Ashraf Fouad
    2. 2. Agenda <ul><li>Client </li></ul><ul><li>(What / Why) source code control? </li></ul><ul><li>Known SCC software. </li></ul><ul><li>Why SVN? </li></ul><ul><li>Sites / Required software. </li></ul><ul><li>Basic terminology / actions. </li></ul><ul><li>Basic life cycle. </li></ul><ul><li>Client setup / connectivity. </li></ul><ul><li>Client usage. </li></ul><ul><li>Advanced actions. </li></ul><ul><li>Server </li></ul><ul><li>Setup. </li></ul>
    3. 3. What source code control (SCC)? <ul><li>What: </li></ul><ul><ul><li>Like shared network drive, but controlling access to files between team members. </li></ul></ul><ul><ul><li>Merging different versions of code modified by several developers on text based level difference. </li></ul></ul><ul><ul><li>Tracking changes (viewing history). </li></ul></ul><ul><ul><li>Provide backup / restore points (short/long) term undo. </li></ul></ul><ul><ul><li>Provide branching / Merging. </li></ul></ul><ul><ul><li>Provide synchronization / locks / notifications. </li></ul></ul><ul><ul><li>Provide HTTP / remote access. </li></ul></ul><ul><li>Not for teams only even a single developer benefit from SCC as it makes backup of different versions of source code. </li></ul>
    4. 4. Why source code control (SCC)? <ul><li>Why: </li></ul><ul><ul><li>Shared network is not handling several developers accessing same file. </li></ul></ul><ul><ul><li>Avoid using vague words that always change as latest, final, pre-final, v1, or dates to file that will prevent them of compiling. </li></ul></ul><ul><ul><li>Keeping several versions for code for several reasons: </li></ul></ul><ul><ul><ul><li>Product versions, its patches. </li></ul></ul></ul><ul><ul><ul><li>Maintain customization of product for several clients. </li></ul></ul></ul><ul><ul><ul><li>Allow the freedom to experiment or make Proof of concept without fear of losing control over code. </li></ul></ul></ul><ul><li>Some surveys indicate that 70% of software teams doesn't use SCC, I can't imagine how they cope ==> At the end it will be your call to decide, although I don't think you can survive ;) </li></ul>
    5. 5. Known SCC software <ul><li>CVS (Concurrent Versions System) . </li></ul><ul><li>Microsoft Visual SourceSafe . </li></ul><ul><li>SVN (Subversion) . </li></ul><ul><li>IBM Rational ClearCase . </li></ul><ul><li>Borland StarTeam . </li></ul><ul><li>This presentation is dedicated for centralized source code control, we are not discussing distributed repository architecture. </li></ul><ul><li>The naming convention is not always the same for all SCC software, the naming convention used here will be for SVN. </li></ul><ul><li>In most companies using SCC, it is not only used for code, but also, requirements, analysis, design, test scenarios, etc... </li></ul>
    6. 6. Why SVN? <ul><li>Powerful with command line interface. </li></ul><ul><li>Free / open source. </li></ul><ul><li>Availability of free client software / Plugin for most known IDEs. </li></ul><ul><li>SVN is simpler than CVS by eliminating some not commonly used functionality. </li></ul><ul><li>Faster. </li></ul><ul><li>DB based not file based. </li></ul><ul><li>Customized attributes to be attached to files. </li></ul><ul><li>Automatically handles all file types without instructions. </li></ul><ul><li>Support Folder / File rename & copies maintaining the history. </li></ul>
    7. 7. Sites / Required software <ul><li>Official site: SVN </li></ul><ul><li>Free server edition: VisualSVN Server </li></ul><ul><li>Free GUI client: </li></ul><ul><ul><li>Eclipse Plugin ( Subclipse ). </li></ul></ul><ul><ul><li>Standalone free client most famous TortoiseSVN . </li></ul></ul><ul><ul><li>Standalone free / commercial SmartSVN . </li></ul></ul><ul><li>Lots of sites offering hosting SVN ( Offering SVN ) (Free / Commercial). </li></ul>
    8. 8. Basic terminology / actions <ul><li>Server: </li></ul><ul><ul><li>Repository. </li></ul></ul><ul><ul><li>Trunk / Main. </li></ul></ul><ul><li>Client: </li></ul><ul><ul><li>Working copy. </li></ul></ul><ul><ul><li>Add / Check-out / Check-in. </li></ul></ul><ul><ul><li>Check-in message. </li></ul></ul><ul><ul><li>Revision / Head. </li></ul></ul><ul><ul><li>Change log. </li></ul></ul><ul><ul><li>Update / Synchronize. </li></ul></ul><ul><ul><li>Revert. </li></ul></ul>
    9. 9. Basic life cycle (Edit-Merge-Commit) No Rev Rev 1 Rev 1 Modified Rev 2 Repository Working folder Merged
    10. 10. Basic life cycle (Edit-Merge-Commit) (cont.) <ul><li>The following rules applies: </li></ul><ul><ul><li>Files in the working folder are all writable. </li></ul></ul><ul><ul><li>Nobody knows who is editing the files. </li></ul></ul><ul><ul><li>While developer commits, he is responsible for ensuring that his changes were made against the latest version in repository. </li></ul></ul><ul><li>This life cycle is risky in the manner that the merge step may be tedious or cause problems. However, the acceptance of this risk rewards us with a concurrent development style. </li></ul><ul><li>Merge is only required when team members are working in parallel in the same file, usually it is better to do the merge manually rather than doing automatic merge supplied by different client tools. </li></ul>
    11. 11. Merge example Rev 4 Repository Dev 2 Working folder Dev 1 Working folder Rev 5 Rev 5 Rev 5 Modified 5 by dev 1 Modified 5 by dev 2 Rev 6 Modified 5 By dev 2 merge with Rev 6 Rev 7
    12. 12. Client setup / connectivity for TortoiseSVN <ul><li>TortoiseSVN client (windows installation msi): </li></ul><ul><ul><li>Install with full integration. </li></ul></ul><ul><ul><li>You will need to restart after installation. </li></ul></ul><ul><li>In order to connect: </li></ul><ul><ul><li>Create a folder that will be your local working folder. </li></ul></ul><ul><ul><li>In windows explorer, right click, SVN checkout. </li></ul></ul><ul><ul><li>URL of repository: https://<server-name>:8443/svn/<repository-name>/ </li></ul></ul><ul><ul><li>Checkout folder: Your local working folder. </li></ul></ul><ul><ul><li>Checkout depth: Fully recursive. </li></ul></ul><ul><ul><li>Head revision. </li></ul></ul><ul><ul><li>OK. </li></ul></ul>
    13. 13. Client setup / connectivity for SmartSVN <ul><li>SmartSVN client (without jre): </li></ul><ul><ul><li>Install with full integration. </li></ul></ul><ul><ul><li>Select Foundation version. </li></ul></ul><ul><li>In order to connect you need to configure repository profile, with the following information: </li></ul><ul><ul><li>Protocol: https for Internet connection, SVN for network. </li></ul></ul><ul><ul><li>Server name: name of server IP. </li></ul></ul><ul><ul><li>Repository path: /svn/<repository_name> for https, /<repository_name> for network. </li></ul></ul><ul><ul><li>Port: non-default 8443. </li></ul></ul><ul><ul><li>Corresponding local folder. </li></ul></ul>
    14. 14. Client setup / connectivity for eclipse <ul><li>Eclipse plugin: </li></ul><ul><ul><li>Right click project -> Team -> Share project. </li></ul></ul><ul><ul><li>SVN, Next </li></ul></ul><ul><ul><li>URL: https://<server-name>:8443/svn/<repository-name>/ </li></ul></ul><ul><ul><li>Project name as folder name. </li></ul></ul><ul><ul><li>Finish. </li></ul></ul><ul><ul><li>Accept certificate permanently. </li></ul></ul><ul><ul><li>Enter username / password. </li></ul></ul><ul><ul><li>We import only source & lib usually, we don't include bin folder. </li></ul></ul>
    15. 15. Basic actions <ul><li>Based on your SVN client, you need to practice the following basic actions on the 'trunk' folder: </li></ul><ul><ul><li>Add / commit. </li></ul></ul><ul><ul><li>Update / commit. </li></ul></ul><ul><ul><li>Modify / Revert. </li></ul></ul><ul><ul><li>Modify several files / commit all with same message. </li></ul></ul><ul><ul><li>View revision graph / view log. </li></ul></ul><ul><ul><li>Compare between versions / Show differences. </li></ul></ul><ul><ul><li>Add folder recursively. </li></ul></ul><ul><ul><li>Update local copy to specific revision not just head. </li></ul></ul><ul><ul><li>Delete / commit – Delete / revert deletion. </li></ul></ul><ul><li>You need to get used for the icons on files for your favorite SVN client, you should find list in the help of the client software. </li></ul>
    16. 16. Basic actions (cont.) <ul><li>Continue to practice the following tasks: </li></ul><ul><ul><li>Lock – Modify – Unlock to prevent anyone from changing in file while you are modifying it. </li></ul></ul><ul><ul><li>Export to be used when releasing for taking version. </li></ul></ul><ul><ul><li>Try the blame feature to view changes for each line is done by whom. </li></ul></ul>
    17. 17. Advanced actions <ul><li>Branching: </li></ul><ul><li>Needed when your development team needs to work on two distinct copies of a project at the same time & keep the two lines of development distinct, example: </li></ul><ul><ul><li>Development of release 2.0 </li></ul></ul><ul><ul><li>Maintenance of release 1.0 </li></ul></ul><ul><li>Atomic transactions (Changeset). </li></ul><ul><li>Resolving conflict (Best get latest version & apply changes again). </li></ul><ul><li>Reverse Integrate (Merge branch in trunk). </li></ul><ul><li>Forward Integrate (Merge trunk in branch). </li></ul>
    18. 18. Advanced actions (cont.) <ul><li>Tag / Release: Light weight, usually used as naming a release for a folder and its sub-folders to identify meaningful release (example: </li></ul>
    19. 19. Best practice <ul><li>Take it slow. </li></ul><ul><li>Be precise and exhaustive in your commit comments, try to have a standard for your company. </li></ul><ul><li>Commit your work to the repository as often as you can without breaking the build. Always check-in a compiled version of code in order not to prevent others from continuing work if updated their working folders. Don't let your working folder become too valuable. </li></ul><ul><li>Keep in touch with the repository i.e. update your working folder as often as you can without interrupting your own work. It isn't wise to let the distance between your working folder and the repository grow too large. </li></ul><ul><li>If you used merge, merge manually & make sure you have a compiling version before commit. </li></ul>
    20. 20. Best practice (cont.) <ul><li>Small project: Don't branch or merge. </li></ul><ul><li>Don't create a branch unless you are willing to take care of it. </li></ul><ul><li>Big projects: Usually have experienced maintainers who keep track of branches or patches. </li></ul><ul><li>Make always your repository root having 3 sub-folders (trunk, branches, tags). </li></ul><ul><li>Don't make branches to keep track of specific customers, better to build customizability in your application. </li></ul><ul><li>Always group your check-in logically (Bug fix, add feature, particular task). </li></ul>
    21. 21. VisualSVN Server setup <ul><li>Run installer “VisualSVN-Server-x.x.x.msi”. </li></ul><ul><li>Next, I accept, Next. </li></ul><ul><li>Specify location for installer (Require nearly 7 MB). </li></ul><ul><li>Specify location for repository (Require large space for your files). </li></ul><ul><li>Select authentication type based (Either own subversion users, or windows users) you may need to consult your system admin before decide. </li></ul><ul><li>Next, Install. </li></ul><ul><li>Finish. </li></ul>
    22. 22. VisualSVN Server setup (cont) <ul><li>What happened after installation: </li></ul><ul><ul><li>Service created VisualSVN Server created Automatic startup. </li></ul></ul><ul><ul><li>Repository folder contains 5 files now. </li></ul></ul>
    23. 23. Repository (Server) information <ul><li>Repository = File system x time </li></ul><ul><li>Usually the repository store delta between files for each check-in (Either forward or reverse delta or sometime make some combination). </li></ul><ul><li>Backup: dump versus hotcopy. </li></ul><ul><ul><li>When you dump, it checks out every single revision in the repository. </li></ul></ul><ul><ul><li>hotcopy is a file copy of your repository database. </li></ul></ul>
    24. 24. Questions / Suggestion Thanks Ashraf Fouad
    25. 25. References <ul><li>A Visual Guide to Version Control . </li></ul><ul><li>Source control how to . </li></ul><ul><li>SVN best practice . </li></ul><ul><li>5 SVN best practices . </li></ul><ul><li>OSCON: Subversion Best Practices . </li></ul><ul><li>Version control with subversion . </li></ul>