Source Code Control with Subversion CPS 5401 19
Source Code Control with Subversion CPS 5401 19 Sep 2013 Umayanganie Munipala
What is Version Control Good For? If you work in a team, it is the best way to synchronize your work with your colleagues. It is also a way to document what changes were made, by whom, and why. Roll back a defective code to a version that worked. CPS 5401 19 September 2013 2
What is Version Control Good For? • Maintain project/file history Branches allow you to have customizations that need to be kept out of the main development line. If you are working in a team, a branch is a way to develop a major feature, stay up to date with changes your colleagues make, and only add your feature to the main development • Managing releases - so you know what files are in what version CPS 5401 19 September 2013 3
What is Version Control Good For? Even If you work alone, it is an easy way to synchronize between more than one machine. (You could even imagine traveling without all your files, and installing them from the repository onto a borrowed machine as the need arises. ) Having a source code repository is one way to backup your work. CPS 5401 19 September 2013 4
Concepts: Repository copy and Working copy CPS 5401 19 September 2013 5
Version Control Systems • Version control system keeps track of all work and all changes in a set of files, typically the implementation of a software project, and allows several (potentially widelyseparated) developers to collaborate. • Classification and examples: • Distributed model - each developer works directly with their own local repositories repository, and changes are shared between as a separate step • Open-source: GNU arch, Bazaar • Proprietary: Bit. Keeper, Code co-op, Team. Ware • Client-server model - developers use a shared single repository • Local only: Revision Control System (RCS) • Open-source: CVS, CVSNT, Open. CVS, Subversion, Vesta • Proprietary: a lot CPS 5401 19 September 2013 6
Subversion (SVN) • • • Directory versioning Atomic commits File and directory metadata Faster network access Requires less network access Branching and tagging are cheap CPS 5401 19 September 2013 7
Fundamental Concepts and How it Works • Subversion is a centralized system for sharing information • At its core is a repository, which is a central store of data • Can be accessed via a HTTP or HTTPS connection • Repository 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. CPS 5401 19 September 2013 8
Fundamental Concepts – Working Copy & Remote copy A Subversion working copy is an ordinary directory tree on local system, containing a collection of files • Subversion provides commands to commit your changes and merge other people changes into your working copy • Each working directory has a. svn directory (administrative directory) • • Repository password are stored in each. svn folder • Stores a original copy of each file in directory CPS 5401 19 September 2013 9
Basic Subversion Work Flow • • Get a working copy Make changes in your copy Test them locally Integrate them with any changes made to the Repository Commit them back to the Repository Repeat these steps until a release is ready Tag the release Start making changes again for next CPS 5401 19 September 2013 10 release
How to start • Subversion client is distributed as command-line tool and can be downloaded at: http: //subversion. tigris. org • Tortoise SVN, a Subversion client, implemented as a windows shell extension: http: //tortoisesvn. tigris. org/ • For development more convenient is to use Subclipse plugin for Eclipse/Netbeans. Subclipse can be installed and updated from within : http: //subclipse. tigris. org/install. html CPS 5401 19 September 2013 11
Netbeans SVN URL of server that hosts svn Your username and Password on that server CPS 5401 19 September 2013 12
Netbeans SVN Directory on server Side to check out (blank for whole Repository) Directory to place The files on your host CPS 5401 19 September 2013 13
Eclipse: Create repository location In Eclipse switch to “SVN Repository Exploring” perspective and create new Repository Location: Type repository URL, e. g. http: //java-eim. googlecode. com/svn/trunk/ CPS 5401 19 September 2013 14
Check-out the project A check-out creates a local working copy from the repository. 1. Right-click on a module for check-out, choose “Checkout…” option 2. 3. Choose to check-out using e. g. New Project Wizard Check-out e. g. as General Project CPS 5401 19 September 2013 15
Make changes and commit A commit (check-in) occurs when a copy of the changes made to the working copy is written or merged into the repository. 1. 2. 3. Switch to another perspective, for example, “Java” View and modify files in your working copy When finished and ready to commit certainly(!!!) synchronize with repository, to avoid conflicting changes (probably somebody already modified the same files)!!! Right click Team… Synchronize with Repository 4. To compare local and remote files double click on file CPS 5401 19 September 2013 16
Resolving Conflicts Once in a while, you will get a conflict when you update your files from the repository • Subversion places conflict markers—special strings of text which delimit the “sides” of the conflict - into the file to demonstrate the overlapping areas • For every conflicted file Subversion places three additional files in directory: • <<<<<<< filename your changes ======= code merged from repository >>>>>>> revision • • filename. ext. mine - your file as it existed in your working copy before you updated your working copy - without conflict markers. This file has your latest changes in it. • filename. ext. r. OLDREV - the file that was the BASE revision before you updated your working copy. It is the file that you checked out before you made your latest edits. • filename. ext. r. NEWREV - the file that your Subversion client just received from the server when you updated your working copy. This file corresponds to the HEAD revision of the repository. Manually resolve a conflict, execute resolved command, commit CPS 5401 19 September 2013 17
More Concepts and Features • • Revisions Tagging and branching Metadata (properties) Locking • Lock is a piece of metadata which grants exclusive access to one user to change a file • • History of changes [Team Show History] Compare different revisions • Select two versions from history Compare • • • Directories are versioned items Deletes and moves are recorded Copy sources are remembered CPS 5401 19 September 2013 18
Revisions • Each time the repository accepts a commit, this creates a new state of the file system tree, called a revision. • Revision numbers are global, rather than per-file • Allows to talk about “revision 2524” • Unique identifier for a state of project • Simple way to tag (next slide) • Each revision corresponds to a single commit • Contains author, log message, and date CPS 5401 19 September 2013 19
Branches and Tags • Branch - a line of development that exists independently of another line, yet still shares a common history if you look far enough back in time. • Subversion implements “cheap copies” – branches are simply copies of the main trunk Tag is just a “snapshot” of a project in time. • Tags are copies which are never changed • • Might not even be necessary if you simply record the global revision number that built your product CPS 5401 19 September 2013 20
Metadata Any file or directory can store properties • Properties are name/value pairs • Some standard properties exist • • svn: ignore • svn: mime-type • svn: eol-style • etc. User-defined properties are allowed • Property values can be text or binary • CPS 5401 19 September 2013 21
Subversion Hosting • When you decided to use Subversion in your project, then you will need a server where to place your code Our research group server is here: • http: //repository. cs. utep. edu/svn/hpcs • • List of sites that offer Subversion hosting: http: //subversion. tigris. org/links. html#hosting CPS 5401 19 September 2013 22
Clients for other OS users Rapid. SVN is a tortoisesvn like client program that is available in Ubuntu Software Center Mac : svnx Centos/ Redhat (griffin) : collab. net client ◦ $ yum install subversion ◦ $ yum install mod_dav_svn CPS 5401 19 September 2013 23
References • Subversion home • http: //svn. subversion. com/ • Book “Version Control with Subversion” http: //svnbook. red-bean. com/ • Svn location for class • http: //repository. cs. utep. edu/svn/cps 5401/ Username : cps 5401 group. X • Password : cps 5401 g. X • CPS 5401 19 September 2013 24
Exercises svn info ◦ URL of the repository and the revision number ◦ Make sure it’s the working directory svn co svn add svn status svn commit –m “xxx” svn update CPS 5401 19 September 2013 25
Exercises (conflicts) how do deal with conflicting edits by two users of the same repository. ? %% emacs firstfile # make some change %% svn commit -m "another edit to the first file" Sending firstfile svn: Commit failed (details follow): svn: Out of date: ’firstfile’ in transaction ’ 5 -1’ CPS 5401 19 September 2013 26
Exercises (conflicts) The solution is to get the other edit, and commit again. After the update, svn reports that it has resolved a conflict successfully. ◦ ◦ ◦ ◦ %% svn update G firstfile Updated to revision 5. %% svn commit -m "another edit to the first file" Sending firstfile Transmitting file data. Committed revision 6. G at the start of the line indicates that svn has resolved a conflicting edit. CPS 5401 19 September 2013 27
Exercises (conflicts) If both students make edits on the same part of the file, svn can no longer resolve the conflicts. ◦ %% svn commit -m "another edit to the first file" ◦ svn: Commit failed (details follow): type e to open the file in an editor Or type p for ‘postpone’ and edit it later. After editing and resolving conflict commit the file ◦ %% svn resolved firstfile ◦ Resolved conflicted state of ’firstfile’ ◦ %% svn commit -m "another edit to the first file" CPS 5401 19 September 2013 28
Conflict Options (e) edit - change merged file in an editor (df) diff-full - show all changes made to merged file (r) resolved (dc) display-conflict - show all conflicts (ignoring merged version) (mc) mine-conflict (tc) theirs-conflict - accept their version for all conflicts (same) (mf) mine-full (tf) theirs-full (p) postpone (l) launch (s) show all - accept merged version of file - accept my version for all conflicts (same) - accept my version of entire file (even non-conflicts) - accept their version of entire file (same) - mark the conflict to be resolved later - launch external tool to resolve conflict - show this list CPS 5401 19 September 2013 29
History: How to get information about the repository. svn info svn log 2: 5 svn diff ◦ To see differences in various revisions of individual files ◦ First Update the svn ◦ svn diff firstfile CPS 5401 19 September 2013 30
Exercises (Shuffling files around) svn mkdir trunk See the output ◦ Create a file somefile and commit it to the repository. Then do rm somefile ◦ svn status svn revert ◦ deleted : brought back from repositary ◦ undo any local edits svn --force rm yourfile. CPS 5401 19 September 2013 31
Exercises(Branching and merging) svn copy <the URL of your repository>/trunk <the URL of your repository>/onebranch -m "create a branch“ This is not visible in the trunk. Checkout and see. Edits are also not visible svn co <the URL of your repository>/onebranch projectbranch edits in the main trunk can be pulled into this branch: ◦ svn merge ˆ/trunk --- Merging r 13 thro r 15 CPS 5401 19 September 2013 32 into ’. ’:
Exercises(Branching and merging) When you are done editing, the branch edits can be added back to the trunk. svn co file: //‘pwd‘/repository/trunk mycleanproject ◦ A # all the current files and then do a special merge: cd mycleanproject svn merge --reintegrate ˆ/branch CPS 5401 19 September 2013 33
- Slides: 33