60
Distributed Source Control With Mercurial Or, How I Learned to Stop Worrying and Love the Merge Ted Naleid - Lead Developer at Carol.com

Dvcs With Mercurial (No Notes)

Embed Size (px)

DESCRIPTION

Distributed Version Control with Mercurial presentation (without notes, easier to see on slideshare).

Citation preview

Page 1: Dvcs With Mercurial (No Notes)

Distributed Source Control With Mercurial

Or, How I Learned to Stop Worrying and Love the Merge

Ted Naleid - Lead Developer at Carol.com

Page 2: Dvcs With Mercurial (No Notes)

Overview

• Introduction

• SVN (centralized VCS) vs DVCS

• Current Popular DVCS Alternatives

• Mercurial (hg) examples

• Hands on with hg

Page 3: Dvcs With Mercurial (No Notes)

Centralized VCS (SVN)

remote centralrepos

checkoutadd

removeupdate

logcommitmerge

...

Build Server

Page 4: Dvcs With Mercurial (No Notes)

Distributed VCS (Mercurial)

buildrepos

addremoveupdate

logcommit

diffmerge

...

Bob's repos

pushpull

pushpull

Alice'srepos

Dave'srepos

pushpull

Build Server

Page 5: Dvcs With Mercurial (No Notes)

DVCS/Mercurial Strengths

SVN Limitations

Page 6: Dvcs With Mercurial (No Notes)

Branching is easy, merging is (relatively) easy

Branching is easy, but merging is painful

Page 7: Dvcs With Mercurial (No Notes)

If your computer is on, you have access to the repository

Active net connection required to interact

Page 8: Dvcs With Mercurial (No Notes)

Sharing changes with selected people is easy

(hg serve/hg push/hg pull)

Unable to share changes with others without sharing

with everyone (including the build server)

Page 9: Dvcs With Mercurial (No Notes)

Aware of file history and can merge into renamed file

Fails to merge changes when something is renamed

Page 10: Dvcs With Mercurial (No Notes)

Single .hg directory at root of source tree

.svn files are littered throughout your source tree

Page 11: Dvcs With Mercurial (No Notes)

Fast performance; you’re working on local filesystem

Slow over-the-wire performance

Page 12: Dvcs With Mercurial (No Notes)

Cheap to create/throw away local experimental branch

Discourages experimentation

Page 13: Dvcs With Mercurial (No Notes)

DVCS/Mercurial Limitations

SVN Strengths

Page 14: Dvcs With Mercurial (No Notes)

Most developers will need to learn to think differently

Familiar to most developers

Page 15: Dvcs With Mercurial (No Notes)

Better understanding of version control concepts

required

Relatively easy to grasp

Page 16: Dvcs With Mercurial (No Notes)

Need to define and adhere to convention to know

where the trunk is

Everyone knows where the trunk is because there’s only

one server

Page 17: Dvcs With Mercurial (No Notes)

Tool support and integration isn’t quite as far along

Well established tool support and integration

Page 18: Dvcs With Mercurial (No Notes)

DVCS systems are still new and a clear winner has not

been established

There is a winner among free, centralized VCS systems: Subversion

Page 19: Dvcs With Mercurial (No Notes)

Popular 2nd Gen DVCS Systems

Git - Bazaar - Mercurial

Page 20: Dvcs With Mercurial (No Notes)

GitCreated by Linus Torvalds in 2005 after the BitKeeper “debacle”

Page 21: Dvcs With Mercurial (No Notes)

Git - Website & Hosting

• Website: http://git.or.cz/

• Hosting:

• http://github.com

• http://repo.or.cz

Page 22: Dvcs With Mercurial (No Notes)

Git - Use in the Wild

• Linux Kernel

• One Laptop Per Child (OLPC)

• Ruby on Rails

• Lots of other Ruby stuff

• Written mostly in C

Page 23: Dvcs With Mercurial (No Notes)

Git - Common Wisdom

• Fastest of the DVCS systems

• Unfriendly to non-Linux/Unix systems

• Complex, with ~150 commands added to path

• Very popular in the Linux/Ruby communities

• Probably the most “buzz” off all DVCS systems right now

Page 24: Dvcs With Mercurial (No Notes)

Bazaar (bzr)Created by Canonical, Ltd. (creators of Ubuntu) in 2005

Page 25: Dvcs With Mercurial (No Notes)

Bazaar - Website & Hosting

• Website: http://bazaar-vcs.org/

• Hosting: https://launchpad.net/

Page 26: Dvcs With Mercurial (No Notes)

Bazaar - Use in the Wild

• Ubuntu

• Drupal

• Fairly big in Python community

• it’s written mostly in Python

Page 27: Dvcs With Mercurial (No Notes)

Bazaar - Common Wisdom

• Has gone through lots of revisions/changed formats

• Slowest of the 3

• Migration of an existing SVN repository is REALLY slow

• Made to be friendly, similar to SVN

• Smallest market share

Page 28: Dvcs With Mercurial (No Notes)

Mercurial (hg)Created by Matt Mackall in 2005 after the BitKeeper “debacle”

Page 29: Dvcs With Mercurial (No Notes)

Mercurial - Website & Hosting

• Website: http://www.selenic.com/mercurial/

• Hosting:

• http://freehg.org/

• http://sharesource.org/

Page 30: Dvcs With Mercurial (No Notes)

Mercurial - Use in the Wild

• OpenJDK (Java)

• OpenSolaris

• Mozilla

• NetBeans

• Many others (largely Java/Python related)

• Like Bazaar, it’s mostly written in Python

Page 31: Dvcs With Mercurial (No Notes)

Mercurial - Common Wisdom• Similar syntax to SVN

• Slightly slower than Git, but faster than Bazaar

• Good cross-platform support

• Getting good support from large Java projects (OpenJDK, NetBeans, etc)

• Lower maintenance and easier learning curve than Git

Page 32: Dvcs With Mercurial (No Notes)

Why did I choose Mercurial over Git/Bazaar?

Page 33: Dvcs With Mercurial (No Notes)

Similar commands to SVN

• hg add

• hg remove

• hg update

• hg log

• hg status

• It’s like SVN but with the ability to “push” and “pull”

Page 34: Dvcs With Mercurial (No Notes)

Better cross platform support and growing tool integration

Page 35: Dvcs With Mercurial (No Notes)

No “packing” of the repository is necessary

Page 36: Dvcs With Mercurial (No Notes)

Local revision numbers are “friendly”

Page 37: Dvcs With Mercurial (No Notes)

It’s used by a number of big Java projects

Page 38: Dvcs With Mercurial (No Notes)

It’s the first one I tried :)

Page 39: Dvcs With Mercurial (No Notes)

All 3 of these tools look fantastic.

Page 40: Dvcs With Mercurial (No Notes)

Mercurial Usage ExamplesHow do I do X?

Page 41: Dvcs With Mercurial (No Notes)

Create a new repository

localrepos

portal/.hg

localfile

system

portal/**

hg init

hg addremove

hg commit

Page 42: Dvcs With Mercurial (No Notes)

“Checkout” an Existing Repository

remoterepos

http://hg01/repos/portal

hg clone

hg clone http://hg01/repos/portal

localrepos

portal/.hg

creates tip fileson filesystem

localfile

system

portal/**

Page 43: Dvcs With Mercurial (No Notes)

Pull down the latest changes(no conflicts with local changes)

localrepos

portal/.hg

localfile

system

portal/**

hg pull

hg update

remoterepos

http://hg01/repos/portal

"hg pull -u" will do this in one command

Page 44: Dvcs With Mercurial (No Notes)

Pull down the latest changes(conflicts detected with local changes)

localrepos

portal/.hg

localfile

system

hg pullremoterepos

http://hg01/repos/portal

local file changes

hg merge

hg commit

hg updateconflict!

files unchanged!

"hg fetch" will pull->update->merge->commit in one command

hg commit

Page 45: Dvcs With Mercurial (No Notes)

Push changes to another repository(by default, push will refuse to run if it would require a merge)

localrepos

portal/.hg

hg push

remoterepos

http://hg01/repos/portal

localfile

system

local file changes

hg commit

hg addhg remove

hg addremove

Page 46: Dvcs With Mercurial (No Notes)

Do a push/pull dry run

localrepos

portal/.hg

hg incoming remoterepos

http://hg01/repos/portal

hg outgoing

Page 47: Dvcs With Mercurial (No Notes)

Create a new “branch”(experimenting is cheap and easy)

localrepos

portal/.hg

localrepos

portal-clone/.hg

creates tip fileson filesystem

localfile

system

portal-clone/**

Branching is done by simply cloning a repository hg clone

hg clone portal portal-clone

Page 48: Dvcs With Mercurial (No Notes)

Compare file system with repository

localrepos

portal/.hg

localfile

system

local file changes

hg diffhg statushg identify

Page 49: Dvcs With Mercurial (No Notes)

Query repository for info

localrepos

portal/.hg

hg loghg annotate

hg cathg grephg serve

Page 50: Dvcs With Mercurial (No Notes)

Hands on with Hg

Page 51: Dvcs With Mercurial (No Notes)

Creating new repository

Page 52: Dvcs With Mercurial (No Notes)

Cloning repository/branching

Page 53: Dvcs With Mercurial (No Notes)

Pushing changes to another repository

Page 54: Dvcs With Mercurial (No Notes)

Merging conflicting changes

Page 55: Dvcs With Mercurial (No Notes)

Creating a tag

Page 56: Dvcs With Mercurial (No Notes)

Searching through history

Page 57: Dvcs With Mercurial (No Notes)

Viewing repository through a web browser

Page 58: Dvcs With Mercurial (No Notes)

A quick way to stick your toes in and try Mercurial out:

use it as a “Super Client” for SVN

Page 59: Dvcs With Mercurial (No Notes)

Web Resources• Choosing a distributed version control system

http://www.dribin.org/dave/blog/archives/2007/12/28/dvcs/

• Understanding Mercurialhttp://www.selenic.com/mercurial/wiki/index.cgi/UnderstandingMercurial

• Version Control and the “80%” (DVCS counterpoint)http://blog.red-bean.com/sussman/?p=79

• Mercurial Bookhttp://hgbook.red-bean.com/hgbook.html

• Video of Bryan O’Sullivan (creator of the Mercurial Book)http://video.google.com/videoplay?docid=-7724296011317502612

Page 60: Dvcs With Mercurial (No Notes)

Questions?