Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges...

39
1 Comparing Apples to Oranges – Subversion, Git, and Mercurial - - © elego Software Solutions GmbH Comparing Apples to Oranges Subversion, Git, and Mercurial SubConf 2009 Stefan Sperling <[email protected]> Stephen Butler <[email protected]>

Transcript of Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges...

Page 1: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

1Comparing Apples to Oranges – Subversion, Git, and Mercurial - - © elego Software Solutions GmbH

Comparing Apples to Oranges

Subversion, Git, and Mercurial

SubConf 2009

Stefan Sperling <[email protected]>

Stephen Butler <[email protected]>

Page 2: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

2

Is there SCM tool convergence?

Page 3: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

3

Real-life situations

1. Reserving a file for editing

– Centralized vs distributed

2. Merging a text edit to a renamed file

– How is tree history modeled?

3. Merging a file move

– Distinguishing file move from directory rename

4. Cherry-picking a revision

– Fine-grained merge tracking

Page 4: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

4

Real-life situations

1. Reserving a file for editing

– Centralised vs distributed

Page 5: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

5

Centralised design

Page 6: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

6

Distributed design

Page 7: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

7

Distributed design with a central server

Page 8: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

8

Real-life situations

1. Reserving a file for editing

– Centralised vs distributed

2. Merging a text edit to a renamed file

– How is tree history modeled?

Page 9: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

9

Merging a text edit to a renamed file

� Edit the text of file foo.c in branch A:

--- foo.c+++ foo.c@@ -1,4 +1,4 @@#include <stdio.h>void main() {- printf("Hello world!\n");+ printf("Goodbye world!\n");}

� Rename file foo.c to bar.c in branch B

� Merge the text change from branch A to branch B

Page 10: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

10

Merging a text edit to a renamed file

� Subversion:

$ svn merge ^/A

--- Merging r3 through r5 into '.':

C foo.c

Summary of conflicts:

Tree conflicts: 1

$ svn status

M .

! C foo.c

> local missing, incoming edit upon merge

$ svn merge ^/A/foo.c@2 ^/A/foo.c@5 bar.c

--- Merging r3 through r5 into 'bar.c':

U bar.c

$ cat bar.c

#include <stdio.h>

int main() {

printf("Goodbye world!\n");

}

$ svn resolved foo.c

Page 11: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

11

Subversion 3D tree

Page 12: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

12

Subversion 3D tree

Page 13: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

13

Subversion 3D tree

Page 14: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

14Comparing Apples to Oranges – Subversion, Git, and Mercurial - - © elego Software Solutions GmbH

Merging a text edit to a renamed file

� Mercurial:

$ hg pull ../A

pulling from ../A

searching for changes

adding changesets

adding manifests

adding file changes

added 1 changesets with 1 changes to 1 files (+1 heads)

(run 'hg heads' to see heads, 'hg merge' to merge)

$ hg merge

merging bar.c and foo.c to bar.c

0 files updated, 1 files merged, 0 files removed, 0 files unresolved

(branch merge, don't forget to commit)

$ cat bar.c

#include <stdio.h>

void main() {

printf("Goodbye world!\n");

}

$

Page 15: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

15

Mercurial: Revlog data structure

Page 16: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

16

Mercurial: Filelog

Page 17: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

17

Mercurial: Filelog

Page 18: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

18

Mercurial: Changeset calculation

Page 19: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

19

Mercurial: Manifest & changelog

Page 20: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

20

Merging a text edit to a renamed file

� Git:

$ git pull ../A master

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From ../A

* branch master -> FETCH_HEAD

Merge made by recursive.

bar.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)

$ cat bar.c

#include <stdio.h>

void main() {

printf("Goodbye world!\n");

}

$

Page 21: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

21

Git: Blob object stores file content

Page 22: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

22

Git: Every revision of a file creates a new blob

Page 23: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

23

Git: All file blobs are stored together

Page 24: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

24

Git: Tree objects represent directories

Page 25: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

25

Git: Tree objects form a hierarchy

Page 26: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

26

Git: Commit object refers to a tree root

Page 27: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

27

Real-life situations

1. Reserving a file for editing

– Centralised vs distributed

2. Merging a text edit to a renamed file

– How is tree history modeled?

3. Merging a file move

– Distinguishing a file move from a directory rename

Page 28: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

28

Merging a file move

� Developers! Developers! Developers!

� They like to refactor their code

– Renaming files

– Renaming directories

nach Software Configuration Management Patterns Berczuk/Appelton

Page 29: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

29

Merging a file move

� A project starts out as:

fruit/Color.java

fruit/Taste.java

fruit/citrus/Apple.java

� On branch A, add a file to the "citrus" package:

fruit/Color.java

fruit/Taste.java

fruit/citrus/Apple.java

fruit/citrus/Orange.java

� On branch B, move Apple.java to the "pome" package:

fruit/Color.java

fruit/Taste.java

fruit/citrus/

fruit/pome/Apple.java

� Merge the change from branch A to branch B

Page 30: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

30

Merging a file move

� Subversion:

$ svn merge ^/A

--- Merging r3 through r5 into '.':

A fruit/citrus/Orange.java

$ svn status

M .

A + fruit/citrus/Orange.java

$ ls fruit/ fruit/citrus/ fruit/pome/

Color.java Taste.java citrus/ pome/

fruit/citrus:

Orange.java

fruit/pome:

Apple.java

Page 31: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

31

Subversion records the source of a copy

Page 32: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

32

Subversion records the source of a copy

Page 33: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

33

Merging a file move

� Mercurial:

$ hg pull ../A

pulling from ../A

searching for changes

adding changesets

adding manifests

adding file changes

added 1 changesets with 1 changes to 1 files (+1 heads)

(run 'hg heads' to see heads, 'hg merge' to merge)

$ hg merge

1 files updated, 0 files merged, 0 files removed, 0 files unresolved

(branch merge, don't forget to commit)

$ ls -R fruit/

Color.java Taste.java pome/

fruit/pome:

Apple.java Orange.java

Page 34: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

34Comparing Apples to Oranges – Subversion, Git, and Mercurial - - © elego Software Solutions GmbH

Merging a file move

� Git:

$ git pull ../A master

remote: Counting objects: 8, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 5 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (5/5), done.

From ../A

* branch master -> FETCH_HEAD

Merge made by recursive.

fruit/citrus/Orange.java | 20 ++++++++++++++++++++

1 files changed, 20 insertions(+), 0 deletions(-)

create mode 100644 fruit/citrus/Orange.java

$ ls -R fruit/

Color.java Taste.java citrus/ pome/

fruit/citrus:

Orange.java

fruit/pome:

Apple.java

$

Page 35: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

35

Real-life situations

1. Reserving a file for editing

– Centralised vs distributed

2. Merging a text edit to a renamed file

– How is tree history modeled?

3. Merging a file move

– Distinguishing file move from directory rename

4. Cherry-picking a revision

– Fine-grained merge tracking

Page 36: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

36

Cherry-picking a revision

� Pick a revision from a branch's history and merge it to the HEADof another branch.

L. Wingard 2005 - Flow of Change

Page 37: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

37

Cherry-picking a revision

� Release branches need to receive bug fixes

� Two approaches:

– Make fix in main line, then merge into release branch

– Make fix in release branch, then merge into main line

� Ideally, the merge should be tracked

� Which approach works best for

– Subversion?

– Mercurial?

– Git?

Page 38: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

38

Why should I care about the design of my SCM tool?

� Design defines constraints

� Your development process must adapt to constraints

� Fixing bugs is easy, fixing design is hard

Page 39: Comparing Apples to Oranges Subversion, Git, and Mercurial · Comparing Apples to Oranges –Subversion, Git, and Mercurial - - ©elego Software Solutions GmbH1 Comparing Apples to

39Comparing Apples to Oranges – Subversion, Git, and Mercurial - - © elego Software Solutions GmbH

Thank you!

Questions?