Upload
if05041736
View
224
Download
0
Embed Size (px)
Citation preview
8/10/2019 Vendor Branches
1/78
Vendor Branches in Mercurial:
Elegant Management of Third-Party Code
Martin Geisler
Mercurial Geek Night IINovember 24th, 2010
8/10/2019 Vendor Branches
2/78
8/10/2019 Vendor Branches
3/78
aragost Trifork
Outline
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
3 / 3 3
8/10/2019 Vendor Branches
4/78aragost Trifork
Outline
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
4 / 3 3
8/10/2019 Vendor Branches
5/78aragost Trifork
What is Mercurial?
Main features:
fast,distributedrevision control system
robust support for branchingandmerging
very flexible and extensible
5 / 3 3
8/10/2019 Vendor Branches
6/78aragost Trifork
Who is Using it?
Mercurial is used by:
Oracle for Java, OpenSolaris, NetBeans, OpenOffice, . . .
Mozilla for Firefox, Thunderbird, . . .
many more. . .
6 / 3 3
8/10/2019 Vendor Branches
7/78aragost Trifork
Centralized Revision Control
Single repository, multiple working copies:
Repository
hello.cMakefile
Alice
goodbye.cMakefile
Bob
7 / 3 3
8/10/2019 Vendor Branches
8/78aragost Trifork
Centralized Revision Control
Single repository, multiple working copies:
Repository
hello.cMakefile
Alice
goodbye.cMakefile
Bob
Drawbacks:
network latency single point of failure
contrained workflow
7 / 3 3
8/10/2019 Vendor Branches
9/78aragost Trifork
Distributed Revision Control
Mercurial duplicates the history on many servers:
Alice Bob
hello.cMakefile
goodbye.cMakefile
8 / 3 3
8/10/2019 Vendor Branches
10/78
aragost Trifork
Distributed Revision Control
Mercurial duplicates the history on many servers:
Alice Bob
hello.cMakefile
goodbye.cMakefile
Advantages: no network latency
distributed, off-line operations no imposed workflow
Drawback(?):
must synchronize repositories
8 / 3 3
8/10/2019 Vendor Branches
11/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
I
Bob
9 / 3 3
8/10/2019 Vendor Branches
12/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
A1 I
Bob
9 / 3 3
8/10/2019 Vendor Branches
13/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
A1 A2 I
Bob
9 / 3 3
8/10/2019 Vendor Branches
14/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
A1 A2 I
Bob
B1
9 / 3 3
8/10/2019 Vendor Branches
15/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
B1
A1 A2 I
Bob
B1pull
9 / 3 3
8/10/2019 Vendor Branches
16/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
B1
A1 A2 A3 I
Bob
B1
merge
9 / 3 3
8/10/2019 Vendor Branches
17/78
aragost Trifork
Moving Changesets Around
Pull and merge:
I
Alice
B1
A1 A2 A3 I
Bob
B1
Merging: find common ancestor of A2 and B1: I
compute differences between I and B1
apply them to A2, taking renames into account
9 / 3 3
C
8/10/2019 Vendor Branches
18/78
aragost Trifork
Key Mercurial Commands
Alice
hello.cMakefile
commit
update
Local commands:
hg commit: save a snapshot into the current repository
hg update: checkout revision into working directory
hg merge: join different lines of history
10/33
K M i l C d
8/10/2019 Vendor Branches
19/78
aragost Trifork
Key Mercurial Commands
Alice
hello.cMakefile
commit
update
push
pull
Local commands:
hg commit: save a snapshot into the current repository
hg update: checkout revision into working directory
hg merge: join different lines of history
Network commands:
hg pull: retrieve changesets from another repository
hg push: send your changesets to another repository
10/33
O li
8/10/2019 Vendor Branches
20/78
aragost Trifork
Outline
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
11/33
O tli
8/10/2019 Vendor Branches
21/78
aragost Trifork
Outline
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
12/33
W kfl i T
8/10/2019 Vendor Branches
22/78
aragost Trifork
Workflow in a Team
Mercurial scales from a single team. . . :
Alice
Bob
Carla Test Prod
13/33
8/10/2019 Vendor Branches
23/78
Workflow Between Two Computers
8/10/2019 Vendor Branches
24/78
aragost Trifork
Workflow Between Two Computers
. . . to working with yourself:
AlicesDesktop
AlicesLaptop
bitbucket.org
15/33
Outline
8/10/2019 Vendor Branches
25/78
aragost Trifork
Outline
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
16/33
Release Branches
8/10/2019 Vendor Branches
26/78
aragost Trifork
Release Branches
17/33
Release Branches
8/10/2019 Vendor Branches
27/78
aragost Trifork
Release Branches
1.0
17/33
Release Branches
8/10/2019 Vendor Branches
28/78
aragost Trifork
Release Branches
1.0
17/33
Release Branches
8/10/2019 Vendor Branches
29/78
aragost Trifork
Release Branches
1.0
17/33
Release Branches
8/10/2019 Vendor Branches
30/78
aragost Trifork
Release Branches
1.0
1.0.1
17/33
Release Branches
8/10/2019 Vendor Branches
31/78
aragost Trifork
Release Branches
1.0
1.0.1
17/33
Release Branches
8/10/2019 Vendor Branches
32/78
aragost Trifork
Release Branches
1.0
1.0.1
17/33
Release Branches
8/10/2019 Vendor Branches
33/78
aragost Trifork
1.0
1.0.1 1.0.2
17/33
Release Branches
8/10/2019 Vendor Branches
34/78
aragost Trifork
1.0
1.0.1 1.0.2
17/33
Outline
8/10/2019 Vendor Branches
35/78
aragost Trifork
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
18/33
8/10/2019 Vendor Branches
36/78
The Library Maintenance Problem
8/10/2019 Vendor Branches
37/78
aragost Trifork
The situation:
your application bundles libfoo version1.0
you discover and fix a bug in libfoo later, libfoo version2.0is released
what now?
20/33
The Library Maintenance Problem
8/10/2019 Vendor Branches
38/78
aragost Trifork
The situation:
your application bundles libfoo version1.0
you discover and fix a bug in libfoo later, libfoo version2.0is released
what now?
The problem:
there might be many files in libfoo
you might have changed several of them
your changes were spread over many commits
20/33
The Library Maintenance Problem
8/10/2019 Vendor Branches
39/78
aragost Trifork
The situation:
your application bundles libfoo version1.0
you discover and fix a bug in libfoo later, libfoo version2.0is released
what now?
The problem:
there might be many files in libfoo
you might have changed several of them
your changes were spread over many commits
you might have changed libfoo when you imported it
20/33
The Library Maintenance Problem
8/10/2019 Vendor Branches
40/78
aragost Trifork
The situation:
your application bundles libfoo version1.0
you discover and fix a bug in libfoo later, libfoo version2.0is released
what now?
The problem:
there might be many files in libfoo
you might have changed several of them
your changes were spread over many commits
you might have changed libfoo when you imported it
files wererenamedin libfoo 2.0!
20/33
Handling Library Upgrades
8/10/2019 Vendor Branches
41/78
aragost Trifork
The goal:
make the same fixes to libfoo 2.0 as you did to 1.0
Vendor branches help you here: gives you clear distinction between
changes made by the vendor your own changes
21/33
Outline
8/10/2019 Vendor Branches
42/78
aragost Trifork
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
22/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
43/78
aragost Trifork
High-level view of vendor branches:
default:
23/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
44/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
23/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
45/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
23/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
46/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
23/33
8/10/2019 Vendor Branches
47/78
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
48/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
23/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
49/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
23/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
50/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
23/33
Vendor Branches in Mercurial
8/10/2019 Vendor Branches
51/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
This workflow lets you:
clearly distinguish between upstream code and your code
directly modify libraries in your codebase
23/33
Vendor Branches in Mercurial
H h l l f d b h
8/10/2019 Vendor Branches
52/78
aragost Trifork
High-level view of vendor branches:
default:
libfoo:
This workflow lets you:
clearly distinguish between upstream code and your code
directly modify libraries in your codebase Mercurial knows exactly what to merge
23/33
What Happens in a Merge?
O Wh d di ib d i i l k?
8/10/2019 Vendor Branches
53/78
aragost Trifork
Or: Why does distributed revision control work?
24/33
What Happens in a Merge?
O Wh d di t ib t d i i t l k?
8/10/2019 Vendor Branches
54/78
aragost Trifork
Or: Why does distributed revision control work?
24/33
What Happens in a Merge?
O Wh d di t ib t d i i t l k?
8/10/2019 Vendor Branches
55/78
aragost Trifork
Or: Why does distributed revision control work?
local head
24/33
What Happens in a Merge?
Or: Why does distributed revision control work?
8/10/2019 Vendor Branches
56/78
aragost Trifork
Or: Why does distributed revision control work?
local head
remote head
24/33
What Happens in a Merge?
Or: Why does distributed revision control work?
8/10/2019 Vendor Branches
57/78
aragost Trifork
Or: Why does distributed revision control work?
local head
remote head
commonancestor
24/33
What Happens in a Merge?
Or: Why does distributed revision control work?
8/10/2019 Vendor Branches
58/78
aragost Trifork
Or: Why does distributed revision control work?
local head
remote head
commonancestor
24/33
What Happens in a Merge?
Or: Why does distributed revision control work?
8/10/2019 Vendor Branches
59/78
aragost Trifork
Or: Why does distributed revision control work?
local head
remote head
commonancestor
1
2
24/33
What Happens in a Merge?
Or: Why does distributed revision control work?
8/10/2019 Vendor Branches
60/78
aragost Trifork
Or: Why does distributed revision control work?
local head
remote head
commonancestor
1
2
1 +2
24/33
Merging Vendor Branches
Upgrading from libfoo version 1 0 to version 2 0:
8/10/2019 Vendor Branches
61/78
aragost Trifork
Upgrading from libfoo version 1.0 to version 2.0:
default:
libfoo:
. . .
. . . 1.0
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
62/78
aragost Trifork
Upgrading from libfoo version 1.0 to version 2.0:
default:
libfoo:
. . .
. . . 1.0
hg update libfoo
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
63/78
aragost Trifork
Upgrading from libfoo version 1.0 to version 2.0:
default:
libfoo:
. . .
. . . 1.0
hg update libfoo
unpack and import libfoo version 2.0
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
64/78
aragost Trifork
pg g
default:
libfoo:
. . .
. . . 1.0 2.0
hg update libfoo
unpack and import libfoo version 2.0
hg commit -m Import of libfoo 2.0
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
65/78
aragost Trifork
pg g
default:
libfoo:
. . .
. . . 1.0 2.0
hg update libfoo
unpack and import libfoo version 2.0
hg commit -m Import of libfoo 2.0
hg update default
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
66/78
aragost Trifork
pg g
default:
libfoo:
. . .
. . . 1.0 2.0
local head
remote headcommonancestor
hg update libfoo
unpack and import libfoo version 2.0
hg commit -m Import of libfoo 2.0
hg update default
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
67/78
aragost Trifork
default:
libfoo:
. . .
. . . 1.0 2.0
local head
remote headcommonancestor
hg update libfoo
unpack and import libfoo version 2.0
hg commit -m Import of libfoo 2.0
hg update default
hg merge libfoo
25/33
Merging Vendor Branches
Upgrading from libfoo version 1.0 to version 2.0:
8/10/2019 Vendor Branches
68/78
aragost Trifork
default:
libfoo:
. . .
. . . 1.0 2.0
local head
remote headcommonancestor
hg update libfoo
unpack and import libfoo version 2.0
hg commit -m Import of libfoo 2.0
hg update default
hg merge libfoo
hg commit -m Merged with libfoo 2.0
25/33
Outline
8/10/2019 Vendor Branches
69/78
aragost Trifork
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
26/33
8/10/2019 Vendor Branches
70/78
Importing a Code Drop
Mercurial can help you:
8/10/2019 Vendor Branches
71/78
aragost Trifork
$ rm -r lib/libfoo
$ unzip libfoo-2.0.zip -d lib/libfoo
$ hg status
M lib/libfoo/modified.txt
! lib/libfoo/deleted.txt
? lib/libfoo/new.txt
Question: has deleted.txt been renamed to new.txt?$ hg addremove --similarity 90
removing deleted.txt
adding new.txt
recording removal of deleted.txt as rename to new.txt (94% similar)
27/33
Finding Renamed Files
Tracking renames is important:
8/10/2019 Vendor Branches
72/78
aragost Trifork
you fix a bug in X.java in version 1.0
version 2.0 now uses Y.java instead of Y.java Mercurial does the right thing with rename tracking
public class X {
static int
theAnswer = 41;
}
X.java
public class Y {
static int
theAnswer = 41;
}
Y.java
public class X {
static int
theAnswer = 42;
}
X.java
public class Y {
static int
theAnswer = 42;
}
Y.java
rename
bugfix
28/33
Outline
8/10/2019 Vendor Branches
73/78
aragost Trifork
Introduction
Using MercurialWorkflowsBranches
Vendor BranchesVendor Branches in MercurialHandling Renamed Files
Wrapping Up
29/33
8/10/2019 Vendor Branches
74/78
More Information
Mercurial homepage:htt // i l l i /
http://mercurial.selenic.com/http://mercurial.selenic.com/8/10/2019 Vendor Branches
75/78
aragost Trifork
http://mercurial.selenic.com/
Mercurial: The Definitive Guide:http://hgbook.red-bean.com/
Getting Started:http://mercurial.aragost.com/kick-start/
http://mercurial.ch/
http://hginit.com/ Some free Mercurial hosting sites:
http://bitbucket.org/
http://code.google.com/
http://sourceforge.net/
http://www.codeplex.com/
31/33
Contact
Please get in touch if you have more questions or have consideredusing Mercurial in your organization:
http://mercurial.selenic.com/http://hgbook.red-bean.com/http://mercurial.aragost.com/kick-start/http://mercurial.ch/http://hginit.com/http://bitbucket.org/http://code.google.com/http://sourceforge.net/http://www.codeplex.com/http://www.codeplex.com/http://sourceforge.net/http://code.google.com/http://bitbucket.org/http://hginit.com/http://mercurial.ch/http://mercurial.aragost.com/kick-start/http://hgbook.red-bean.com/http://mercurial.selenic.com/8/10/2019 Vendor Branches
76/78
aragost Trifork
using Mercurial in your organization:
Email: [email protected]
IRC: mgin #mercurial on irc.freenode.net
32/33
Mercurial Contributors
From http://ohloh.net/p/mercurial/map:
http://localhost/var/www/apps/conversion/tmp/scratch_6/[email protected]://localhost/var/www/apps/conversion/tmp/scratch_6/mghttp://localhost/var/www/apps/conversion/tmp/scratch_6/#mercurialhttp://localhost/var/www/apps/conversion/tmp/scratch_6/irc.freenode.nethttp://localhost/var/www/apps/conversion/tmp/scratch_6/irc.freenode.nethttp://localhost/var/www/apps/conversion/tmp/scratch_6/#mercurialhttp://localhost/var/www/apps/conversion/tmp/scratch_6/mghttp://localhost/var/www/apps/conversion/tmp/scratch_6/[email protected]://ohloh.net/p/mercurial/maphttp://ohloh.net/p/mercurial/maphttp://ohloh.net/p/mercurial/map8/10/2019 Vendor Branches
77/78
aragost Trifork 33/33
Mercurial Contributors
From http://ohloh.net/p/mercurial/map:
http://ohloh.net/p/mercurial/maphttp://ohloh.net/p/mercurial/maphttp://ohloh.net/p/mercurial/map8/10/2019 Vendor Branches
78/78
aragost Trifork
Thank you!Thank you!
33/33