Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 362010-03-19CSCI 5828Foundations of Software EngineeringDmitry Duplaykin | Paul MaddenGit & Mercurial: Distributed Configuration Management2OverviewWhat is configuration management?A brief history of CM systemsState of the art: SubversionIntro to distributed CMGit & Mercurial: Head-to-head comparison with SubversionTips and Summary3What is configuration management?A number of aliases:Pilone & Miles call it version control:“...a tool (usually a piece of software) that will keep track of changes to your files and help you coordinate different developers working on different parts of your system at the same time.”Also known as revision control (e.g. rcs = Revision Control System), or source code management (e.g. http://git-scm.com).4What is configuration management?Typically offers features allowing:Code check-out / check-inBranching / MergingTaggingRecovery from mistakesDisplay of specific code changesReview of historical metadataTwo architectural flavors:Centralized (CVS, Subversion)Distributed (git, Mercurial)5A brief history of CM systems1972 – Source Code Control System (sccs)The original. Proprietary Unix component.1982 – Revision Control System (rcs)SCCS alternative. Like SCCS, works on single files (not entire projects).1990 – Concurrent Versions System (cvs)Built on and extended RCS: entire project tree support, client/server network model, allowed concurrent work without sccs/rcs-style locking by supporting merging.2000 – Subversion (svn)A “better” CVS. In so many ways. Developer sought CVS pros without its cons.2005 – Git & Mercurial: Distributed CMSMany, many others, both free and proprietary6State of the art: SubversionRepository creation / maintenance with svnadmin toolEither in client/server mode, or on local file:// URIsNetwork access viadedicated serversshdApacheChoice of storage databasessvn's own fsfs (simple)Berkeley DB (more features)Offline diffsCopies (tags & branches) “are cheap”Updates stored as diffs & “skip deltas”File reconstructed by sequentially applying diffs7State of the art: SubversionClient svn utility provides functions like:checkout (co) – get files from repositorycommit (ci) – upload changes to repositorycopy (cp) – create branches / tags (among other uses)revert – undo local changes to working copystatus – show what has changed in working copy or what updates are waiting in the repositoryupdate (up) – bring working copy up-to-date with repomerge – e.g. bring branch up-to-date with trunkdiff – compare revisions to each other / working copylog – show historical log messageswrappers for system commands like ls, rm, mv, cp, etc.8An svn workflowsvnadmin create repository (only server-side action)svn import initial set of files into repository (creates r1)svn co first working copymodify existing files, create new onessvn add new files to place under revision controlsvn status to see what has changed locallysvn revert to undo changessvn ci new and changed files (creates r2)svn log to view log-message metadatasvn mv to rename, svn rm to delete filessvn ci these changes (creates r3)svn co an older (r2) working copy9An svn workflowsvn diff r1 and r2 of modified file to see changeschange file in 2nd copy of head, svn ci, look for changes in 1st copy of head, svn up.svn cp to create a tagged revisionsvn cp to create a branchsvn co branch, make two commits, svn merge onto trunk, commit10Transition to distributed CMConceptual model looks like this11More complexity with git12git backgroundDeveloped by Linus Torvalds in 2005Linux Kernel team needed a new CM solution after BitKeeper licensing changedDesign requirements:fastdistributed (no central server, every copy has complete development history in its .git directory)secure (essentially impossible to “change history”)Git differences entire project trees, not individual filesRevisions tracked with a SHA1 hash of information from the current project stateTwo storage locations:changeable indeximmutable object database13Projects using gitAmong many others:And of course, famously, the Linux kernel. Linus Torvalds developed Linux because Andrew Tannenbaum wouldn't let him use Minix. He developed git because BitKeeper revoked their free license. Lesson? Linux Torvalds will eat your lunch. AndroidDebianClojureDigg jQueryPerlSambaRuby on Rails14Mercurial backgroundStarted by Matt Mackall at the same time as git Properties:Written in Python(95% in Python, core routines in C)It's distributedFastDesign features:Uses SHA-1 hashes (like git)Uses HTTP-based protocolAll above matches “Google land religion”Will be referred to as hg, since commands start with it15Projects using MercurialThe list is quite long, the most famous ones are:The Python developers have announced that they will switch from Subversion to Mercurial when hgsubversion – an extension that allows using Mercurial as a Subversion client and that has been under development since September 2009 – is released. MozillaOpenJDKOpenSolarisOpenOffice.org Symbian OSGoGNU OctaveNetbeans16Head-to-head: Create a repository & initialize with files svnsvnadmin create /repos/demomkdir -p import/branches import/tags import/trunkcp source_files/* import/trunksvn import ./import file:///repos/demo gitcd source_filesgit initgit add .git commit # editor will open for commit messagehgcd source_fileshg inithg addhg commit -m “Initial version”17Head-to-head: Get a working copy In Subversion, we need to check out a working copy from the repository...svnsvn co file:///repos/demo/trunk wc gitWe already have a versioned working copy!hgWe have it!18Head-to-head: Edit & add files, view changes svnsvn add fruitsvn status # concise viewsvn diff # show actual deltasgitgit add fruitgit status # concise viewgit diff # show actual deltashghg add fruithg status # show changed, added, deleted fileshg diff # show actual deltas19Head-to-head: Revert changes We've changed our minds about changing numbers...svnsvn revert numbers # to checked-out revisiongitgit checkout numbers # fetches from indexgit checkout HEAD number # from databasehghg revert numbers # What if you had committed? Use this hg rollback# It will help, but only if you haven't pushed # this change to
View Full Document