CS11 Advanced C++ Spring 2012-2013 Lecture 4Source Code Management n You are working on a large software project… n Problem 1: You break the code q Need to roll back to a previous version that works n Problem 2: Other people also working on project q …perhaps on the exact same source files n Problem 3: Centralized source of project info? q Maybe a website that shows current test pass-rate, most recent API docs, etc. n A source code management system can solve all of these problems, and many moreManaging the Source Code n Basic idea: q Store all project files in a repository q Repository keeps track of all changes to any file q Copies of the project are “checked out” from the repository q Developers are isolated from others’ changes q Changes to project files are “checked in” or “committed” back to the repository, when ready. q Multiple changes to the same file are merged n Automatically, if possible; otherwise, manually!Distributed Version Control n A new trend in version control systems: q Don’t use a central repository server! n Distributed version control systems q Each user has a local repository q Users work against their own local repository n Check out a working copy, make edits, then check in q Users can synchronize with other repositories very easily n Great for widely distributed software development q Open-source software, for example n Used less often in commercial development teams q Software companies prefer to have a single central server q Can still use DVCS in a centralized manner, thoughVersion Control Systems n Commercial centralized version control systems: q Perforce, Visual SourceSafe, BitKeeper, … n Open-source centralized version control systems: q Subversion – written as a replacement for CVS n Open-source distributed version control systems: q Git – written by Linus Torvalds n Used for Linux kernel development, Eclipse, PostgreSQL, … q Mercurial (hg) – distributed VCS written in Python n Used by Python project, vim, OpenOffice, GNU Octave, … q Bazaar – also written in Python n Used by Ubuntu project, GNU Emacs, MySQL, …Using Subversion n Two main commands in Subversion: q svn n Program used by developers to access the repository n Can check out files, check in, move, delete, etc. q svnadmin n The repository administration tool n Used rarely, by repository administrator n Both programs take commands q Example: svn checkout ... q Both have a help command: n svn help or svn help commandSetting Up a Repository n Start by creating a repository q Repository contains all the config and data files q Command: svnadmin create /path/to/repository q Can be an absolute or relative path n Can create your repository on the CS cluster svnadmin create ~/cs11/advcpp/svnrepo n Subversion can use different storage layers q Filesystem storage, or BerkeleyDB q Default is filesystem – use that!Accessing the Repository n Subversion uses URLs to refer to repositories q Supports access via HTTP, if needed n For local access, use a file:// URL q On CS cluster: file:///home/user/cs11/advcpp/svnrepo n Subversion also supports remote access q svn://… URL for use of Subversion’s server q Or, svn+ssh://… URL for accessing over SSH n For accessing CS cluster repository remotely: svn+ssh://[email protected]/home/user/cs11/advcpp/svnrepoImporting Source Code n Need to import initial project source into repository q svn import does this q Recursively adds a whole directory tree to repository n Lay out your repository in a reasonable way q Each project (or subproject) should have its own directory q Example ray tracer directories: n raytracer n raytracer/docs n raytracer/tests n raytracer/scenes n etc. n Subversion lets you move files/directories later, tooImporting Source Code (2) n Go to directory with your source files q Clean up .o files, etc. – don’t want to import those n Import the directory tree into the repository q Usually want to specify a subproject to use svn import \ file:///home/user/cs11/advcpp/svnrepo/raytracer q Subversion will add all files in the local directory (and subdirectories) into a raytracer subdirectory of your repository q Can also specify a path to directory to importWorking On Your Project n Now, repository is the central store of all versions of all files q Can check out any version of any file q Usually want the most recent version to work with n Retrieve a “working copy” of your project q A local copy of a particular version of the files q You can make changes in isolation q Can periodically sync up with other changes that have occurred q Once your local copy works properly, check it in!Checking Out Files n To check out files: q svn checkout url (or, svn co url) q URL specifies both repository location, and directory within repository n For example, to get raytracer project from your repository: svn checkout \ file:///home/user/cs11/advcpp/svnrepo/raytracer q Will create a local directory named raytracer, with project files in it n To update local working copy: svn update (or, svn up) q If performed within working copy, no URL needed!Working with Local Files n Can add new files using add command q From within working copy: svn add path1 path2 ... q Can add whole directories n Subversion will recurse through directory contents n Can delete files using delete command q Again, within working copy: svn delete path1 path2 ... n Can move files using move command svn move frompath topathCommitting Changes n Changes to working copy must be committed before they are visible to anyone else q Includes add/delete/move operations n Subversion makes sure your local working copy is up to date first q Can’t commit until you have latest version incorporated n Issue commit command svn commit q Can specify files to commit, if desired q By
View Full Document