25
1. History 2. Structure 3. Git Comparison 4. File Storage 5. File Tracking 6. Staging 7. Queues (MQ) 8. Merge Tools 9. Interfaces Hg 2013.05.02 Mercurial - Ben Pitts 1

History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

  • Upload
    xenia

  • View
    40

  • Download
    0

Embed Size (px)

DESCRIPTION

Hg. History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools Interfaces. Mercurial / Git History. Bitmover's BitKeeper Proprietary distributed revision control system Used by Linux Kernel project for three years until… - PowerPoint PPT Presentation

Citation preview

Page 1: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

1

1. History2. Structure3. Git Comparison4. File Storage5. File Tracking6. Staging7. Queues (MQ)8. Merge Tools9. Interfaces

Hg

2013.05.02

Page 2: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

2

Mercurial / Git History• Bitmover's BitKeeper

▫ Proprietary distributed revision control system▫ Used by Linux Kernel project for three years until…▫ April 2005 Bitmover CEO Larry McVoy pulls the free

version of BitKeeper completely.

• Linus Torvalds▫ Leaves kernel project to create the next kernel RVS▫ Two months later Git is born and hosts the kernel

project• Matt Mackall simultaneously creates Mercurial

"Mercurial is very good, but Git is better.“Linus Torvalds

“It largely comes down to taste. I guess some people just have no taste, but if Git makes them happy, I won't try to stop them.”

Matt Mackall

2013.05.02

Page 3: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

3

Mercurial▫ Project named Mercurial▫ Application named Hg (Mercury)▫ Open Source (GPL2)

http://mercurial.selenic.com/

• Mercurial is written in Python• Some machine language components

• Notable users:▫ Mozilla, Python, NetBeans, OpenOffice, OpenJDK, rpm

• Free hosting: bitbucket.org, code.google.com, sourceforge.net

2013.05.02

Page 4: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

4

Mercurial Structure - Filesystem

.hgignore and .hgtags kept in the working directory for version control.• A tag will always point to a revision older than the one that

committed the tag.• Cloning from a tag will retrieve a repository that doesn't have

the tag you cloned from.

2013.05.02

/.hg//.hgignore/.hgtags/.hg/

• Repository store• File snapshots• Manifest of files • Changesets of file deltas• Logs of all revisions

/• Working directory• Represents one revision• Refreshed by 'hg

update'

/.hgignoreList of ignored files

/.hgtagsTags are global pointers to changesets, like Git

Repository folder

Page 5: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

5

Mercurial Structure – Repository

•Revisions form a directed acyclic graph•Revisions stored as keyframed deltas•A revision is a snapshot of a commit.•The last revision in the chain is a head

▫There can be any number of heads▫Heads can be merged two at a time into new

revisions.

2013.05.02

v1 v2 v3 v4

b1 b2 branch

main

Page 6: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

6

Mercurial vs. Git• Largely equivalent to Git

▫Most functionality identical between systems▫Differences in implementation and approach▫Discrepancies resolved by extensions

• hg-git▫Mercurial plugin two-way bridge between

Mercurial and Git▫Allows Mercurial repository to push/pull with Git

repositories http://hg-git.github.io/

• Full command comparison at ▫http://mercurial.selenic.com/wiki/GitConcepts

2013.05.02

Page 7: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

7

Mercurial vs. Git Extensions

Extensions provide feature parity between Git and Hg

•Git Stash / Mercurial Attic or Shelve▫Set aside working environment for later

Side commit of working directory Git Index / Mercurial Queue[s]

2013.05.02

Page 8: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

8

Mercurial vs. Git Staging

• Git explicitly identifies what files to commit through an Index, or staging area

• Mercurial treats the working directory as a snapshot of the commit, automatically managing which files are modified and need to be included.

• Mercurial Queues extension can be used for more atomic control over commits, as well as the ability to push and pop patches in a system similar to Quilt.

2013.05.02

Git Repo

git commitIndex Working

Directorygit add

Hg Repo

hg commit Working Directory

Page 9: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

9

Mercurial File StorageFile Storage• Stores a snapshot (instance) of the current heads• Stores changesets containing commit deltas• Conflates deltas into keyframes

▫ Compress deltas▫ Increase random access performance

Compression• Files stored via compress (zip)

▫ Algorithm balances compression with performance• Files stored raw if already compressed

▫ Hg always does ‘the right thing’ when storing files.• HTTP transfers use bzip2• SSH connections use SSH built in stream compression

2013.05.02

Page 10: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

10

Mercurial File TrackingTrack files not folders• Empty folders not allowed• Only files are tracked• File path is created with the file and torn down after if empty

Tracking Files• ‘hg add’ – Add file[s] to the repository, and to the next commit• ‘hg addremove’ – Add all new files, removes missing files• ‘hg remove’ – Stop tracking history, file is deleted from

working directory.• The complete history of the file is still stored, forever.

▫ No garbage collection• Mercurial will track a new file with the same name as a

separate entity.

2013.05.02

Page 11: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

11

Mercurial History•What is past stays in the past, history

moves forward.•Mercurial an append-only philosophy and

makes it difficult to alter the history of commits

•Avoids pitfalls of allowing history rewriting

•Trades off flexibility•Guaranteed atomicity of transactions•Repository unlocked for reading at all

times

2013.05.02

Page 12: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

12

Mercurial vs. Git Rebasing• Git is designed to allow the graph to be modified freely.• Mercurial is designed to keep the graph moving forward.• Rewriting the commit graph is not allowed in Mercurial.• Mercurial Rebase Extension

▫ Allows rebasing uncommitted changes ‘hg pull’ a new head. ‘hg rebase’ your changes onto the head.

▫ Fails if conflicts detected▫ Can also be done as part of a pull

‘hg pull –rebase’• Hg's Rebase will not allow

▫ rebasing to your own ancestor▫ rebasing to merge revision with external parents.

2013.05.02

Page 13: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

13

Mercurial Queues (MQ)• To use a Git Index style layer, create a single patch

▫ 'hg qnew patchname‘ – Create a single patch▫ ‘hg qrefresh’ – Record changes into the patch▫ 'hg qfinish‘ – Finalize the patch

• The Queue can contain multiple patches• More flexible than Git's single Index

• Git is capable of handling patches too:▫ StGIT

http://www.procode.org/stgit/▫ Guilt

http://repo.or.cz/w/guilt.git• These are scripts layered over Git• MQ is an integral extension to Hg

2013.05.02

Page 14: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

14

Mercurial Queues - Patches

• ‘hg qpop’ and ‘hg qpush’ - Navigate up and down the patch chain

• ‘hg refresh’ – Save changes into current patch• Changes in the commit can be separated by

feature or section and tracked individually.

• MQ also supports multiple parallel queues.▫ 'hg qqueue -c [queue name]' creates a queue.▫ 'hg qqueue [queue name]' switches between active queues

2013.05.02

Commit

Patch 1‘UI Tweak’

Patch 1‘Bugfix’

Working Directory

Page 15: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

15

Mercurial Queues – Versioning Patches

• Patches are kept in plaintext in the repository▫Single queue patches stored in:

/.hg/patches/[patchname]/▫Multiqueue patches stored in:

/.hg/patches-[queuename]/[patchname]/• Creating a Mercurial repository inside these

folders expands this intermediate area into a versioned repository.▫Share queues with other people to allow others to

look at your patch in progress before it is committed.▫Collaborate on components of the code at a more

local level before finalizing the overall commit.

2013.05.02

Page 16: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

16

Mercurial Branching

• Git creates branches by attaching labels to commits and growing the tree.

• In Mercurial branching can be done internally, but cloning a repository is always preferred.

• Cloning is safer, more modular, easy to discard.• If cloning locally, Mercurial uses hardlinks to files

2013.05.02

Page 17: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

17

Mercurial Branching

Mercurial supports named branching▫Named branches exist in a global namespace.▫Useful for team and project organization

Keep a gold, beta, and alpha head.As QA tests, the heads are moved up the chain.

Mercurial still doesn’t let you change history, so…

▫You can never delete or rename a named branch.(Of course you can, but it's not recommended.)

2013.05.02

Page 18: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

18

Mercurial BranchingMercurial Bookmarks Extension•Comes in the box•Allows commits to be named less permenantly

•Bookmarks are pointers into the commit graph▫Can be renamed, nested and deleted at will

•Bookmarks may be pushed and pulled between repositories▫Global namespace still applies.

2013.05.02

Page 19: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

19

Mercurial Merge Tools - Internal• internal:merge

▫ Traditional merge with conflict markers baked into the file▫ ‘hg resolve’ needed before ‘hg commit’ is allowed

• internal:dump▫ Creates three versions of the files to be merged manually: local, other

and base▫ For the file a.txt, the conflict files will named "a.txt.local",

"a.txt.other" and "a.txt.base“• internal:fail

▫ Marks unmerged files as unresolved, ‘hg resolve’ needed• internal:local

▫ Uses the local version of files as the merged version• internal:other

▫ Uses the other version of files as the merged version• internal:prompt

▫ Asks the user to keep local or other as the merged version

2013.05.02

Page 20: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

20

Mercurial Merge Tools - External•Merge tools are selected in /.hg/hgrc

[merge-tools]mymergetool.priority = 100mymergetool.premerge = Falsemymergetool.args = $local $other $base -o $outputmyimgmerge =

[merge-patterns]**.jpg = myimgmerge**.exe = internal:fail

2013.05.02

Page 21: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

21

Mercurial Merge Tools - External• Tool Arguments

▫ $output – Where the merge will end up▫ $local - Unmerged local changes▫ $base - Revision from the merge ancestor▫ $other - Second parent revision

• Tool Options▫ .args - The arguments to pass the merge tool▫ .premerge=False – Don’t first attempt internal merge (defaults

to True)▫ .executable – Path of merge tool▫ .binary – Does the merge tool support binary files?▫ .symlinks – Does the merge tool support symlinks?▫ .gui – Requires a GUI, interactive merge▫ .priority - Priority of this merge tool (0-100)

2013.05.02

Page 22: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

22

Mercurial Merge Tools - ExternalInteractive merging tools are plentiful

• KDiff3▫ Merge GUI▫ Packaged with Hg

• Meld▫ Merge GUI▫ Linux/Mac/Win

meldmerge.org

• Diffuse▫ Text based interactive merge tool▫ Python

diffuse.sourceforge.net

2013.05.02

Page 23: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

23

Mercurial Interfaces• SourceTree

▫ Free Git/Hg GUI for Win/Mac sourcetreeapp.com

• MacHg▫ Free Hg GUI for Mac

jasonfharris.com/machg

• TortoiseHg▫ Free file browser integration, Windows and Gnome/Nautilus

tortoisehg.bitbucket.org

• EasyHg▫ Simple free Hg GUI for Linux/Mac/Win

easyhg.org

2013.05.02

Page 24: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

24

Mercurial Integration• Eclipse

▫Mercurial Eclipse plugin bitbucket.org/mercurialeclipse/main

• NetBeans▫Supported out of the box

• Visual Studio▫HgSccPackage extension

https://bitbucket.org/zzsergant/hgsccpackage/overview• Ant

▫ANT4HG http://ant4hg.free.fr/

• Maven▫Integrated via scm:hg namespace

2013.05.02

Page 25: History Structure Git Comparison File Storage File Tracking Staging Queues (MQ) Merge Tools

Mercurial - Ben Pitts

25

Hg

2013.05.02

http://mercurial.selenic.com/

Benjamin PittsComputer Science M.S. Student

Old Dominion University