20
MERCURIAL TRAINING www.lptjournal.org /4/2012 HCM city

Mercurial Training

Embed Size (px)

Citation preview

Page 1: Mercurial Training

MERCURIAL TRAINING

www.lptjournal.org

6/4/2012 HCM city

Page 2: Mercurial Training

www.lptjournal.org

Agenda

• Install the Mercurial on a SUSE machine• Behind the Mercurial• Basic commands in the Mercurial• Mq extension tool for patching• Common Issues• The Mercurial vs other SCM

Eng. TrungHuynh™

Page 3: Mercurial Training

www.lptjournal.org

INSTALL on SuSE

• Find the version of SUSE– cat /etc/SuSE-release

• Find the path of repo of the Mercurial for that SuSE version– http://mercurial.selenic.com/wiki/Download– http://download.opensuse.org/repositories/devel:/tools:/scm/

openSUSE_11.4/devel:tools:scm.repo• Use the zypper tool to add the repo’s path

zypper ar http://download.opensuse.org/repositories/devel:/tools:/scm/openSUSE_11.4/devel:tools:scm.repo

• Use the zypper/yast tool to install the Mercurialzypper install mercurialCheck the installation: hg debuginstall

Eng. TrungHuynh™

Page 4: Mercurial Training

www.lptjournal.org

Basic Concepts

• Topology– Mercurial is completely decentralized system, and thus has no concept of central

repository– In Mercurial, the user can define the topology by themselves for sharing the changes

Eng. TrungHuynh™

Page 5: Mercurial Training

www.lptjournal.org

Basic Concepts

• Repository and working directory– Mercurial repositories contain a working coupled with a store– For example: /home/repository/ directory is as below figure

• In working directory, the state of files will be refer to a specific revision of repository• In .hg/store/data/ folder, it contains in formation about changes of each file

Eng. TrungHuynh™

Main.c Main.h

.hg

Rev 0 Rev 1 Rev 2 Rev 3parent parent parentparent

Working directory

repository

Page 6: Mercurial Training

www.lptjournal.org

Basic Concepts

• Revision is local version index for the project• Changeset is unique version index for global

• In above figure, we have a repository with two heads and two branches

• Head is the revision has no child revision. And the biggest revsion head is the tip

Eng. TrungHuynh™

0 1 2 3 4

56(tip)

Working dirhead

headBranch A

Branch B

changeset: 1:d7fd576b6c9b| user: trunghuynh| date: Fri Jun 08 17:28:32 2012 +0700| files: hello1.cc

revision

Page 7: Mercurial Training

www.lptjournal.org

Common Commandshg help <command>

• Hg init -> initialize a repository, of course it is a directory• Hg add -> inform the Mercurial that you want it keep track your files • Hg clone -> clone the project from a Mercurial repository

– Especial, we can clone with the specific branch: hg clone <main-repo> <new-repo> -r <head of specific branc>

• Hg pull -> get the changes from our peers into our repository– Notice that pull command just update our backlog information of our repository

• Hg update -> will update the changes after pulling, in fact it is merging the current working revision with the change from pulling

• Hg commit -> like saving edited word file. It will create a changeset• Hg push -> pushing our changes for others pulling

– The backlog information of main repo will automatically update when the child repos push their changes

• Hg branch ->check the current branch or set branch– Notice that branch name is permanently recorded as part of the changeset’s metadata– Branch name is used as the tip revision when we want checkout a branch

• Hg log ->show the information about the repository• Hg tip ->show information of the “tip” revision. The “tip” revision is the head with

largest revision

Eng. TrungHuynh™

Page 8: Mercurial Training

www.lptjournal.org

Common Commands

• Hg merge -> merge the working directory with other revision

• Hg diff -> show what is changed since the last committing • Hg revert -> revert the specific file into the unmodified

state• Hg incoming ->see what will be updated when we do a pull

action• Hg rollback uncommit…• Hg annotate <filename>• Hg strip <revision number> ->delete a specific revision

Eng. TrungHuynh™

Page 9: Mercurial Training

www.lptjournal.org

Hg commit

Eng. TrungHuynh™

0:qe7

1:de5

2:ye23:af9

@

Alice’s Repo

main.cmodel.h

model.c

Working directory

socket.c

3:a3e

changed

When we commit a new changeset will be created

Page 10: Mercurial Training

www.lptjournal.org

hg push/pull

Eng. TrungHuynh™

Main Repos

0:qe7

1:de5

0:qe7

1:de5

2:af9

Bob’s Repo

0:qe7

1:de5

2:ye2

Alice’s Repo

2:af9

2:af9

hg pull <Bob’s repo>

hg push <Main’s repo>

@

@

@

@ Mark parent revision of working directory

A revision of repo

Page 11: Mercurial Training

www.lptjournal.org

hg merge/update

Eng. TrungHuynh™

Alice’s Repo

0:qe7

1:de5

2:ye23:af9

@

The “hg update” command will change our current working revision that we are working on.

The “hg merge” command will merge a specific revision to the current working revision. In this case, the change from af9 changeset will merge into the revsion 2.After successful merging, we has to commit to create a new changeset/revision which contains both change from revision 3 and 2

4:kq6

Page 12: Mercurial Training

www.lptjournal.org

Advance Using Mercurial

• Merge conflict:– The conflict happens when two changesets have modified the same file’s section

with different way. In this case, the Mercurial need a help from user.

Eng. TrungHuynh™

Main(){printf(“hello Mercurial world”);printf(“Merge is fun and easy”);}

Main(){printf(“hello Mercurial world”);printf(“Merge is difficult”);}

Changeset 4 Changeset 7

Page 13: Mercurial Training

www.lptjournal.org

Common Issues

• To resolve that conflicts we need to open that file and edit to what we want. After that we use “hg resolve <filename> to correct the confliction.

• To support merging, we can use a graphical tool such as kdiff3 as the best tool.

Eng. TrungHuynh™

Page 14: Mercurial Training

www.lptjournal.org

Common Issues

• abort: outstanding uncommitted changes– The cause is merging with uncommitted changes. – There open happens when we pull while there are some uncommitted change– Have two solutions are:

• Always commit changes before pulling• Extract the uncommit changes into the file and pulling. After that imports the

uncommit change file

• abort: push creates new remote heads on branch 'default'!– When we push some things that will create new heads in remote repo.

Mercurial thinks that is an impolite action. The best way is when pulling and merge before pushing

• “abort: crosses branches (use 'hg merge' or 'hg update -C')”– Update the working revision in the different branch

Eng. TrungHuynh™

Page 15: Mercurial Training

www.lptjournal.org

MQ tool

• MQ is the extension tool of Mercurial that manages your patches – Modify the .hgrc to enable MQ

[extensions]hgext.mq =

Eng. TrungHuynh™

Page 16: Mercurial Training

www.lptjournal.org

MQ toolwhat is patch file?

diff --git a/opensaf.spec.in b/opensaf.spec.in--- a/opensaf.spec.in+++ b/opensaf.spec.in@@ -14,6 +14,7 @@ %define is_ais_msg %(test "@AIS_MSG_ENABLED@" = "yes" && echo 1 || echo 0) %define is_ais_smf %(test "@AIS_SMF_ENABLED@" = "yes" && echo 1 || echo 0) %define is_tipc_trans %(test "@TIPC_TRANSPORT_ENABLED@" = "yes" && echo 1 || echo 0)

+%define is_ais_pm %(test "@AIS_PM_ENABLED@" = "yes" && echo 1 || echo 0)

%define _pkglibdir %{_libdir}/%{name} %define _pkgsysconfdir %{_sysconfdir}/%{name}

@@ -541,6 +542,46 @@ %endif

+%if %is_ais_pm

Eng. TrungHuynh™

Diff header

Hunk

Page 17: Mercurial Training

www.lptjournal.org

MQ tool

• Create a patch repository– Hg qinit

• This command will create a “patches” directory in “.hg” directory and also create a patch queue

• In patches folder contains our patches and more two files that are a series file and a status file

• The series file contains all of patches name that MQ knows• The status file contains status of all patches that are applied currently

• Hg qseries command lists every patch that MQ knows about in a repository

• Hg qapplied command lists every patch that MQ has applied in a repository

Eng. TrungHuynh™

Page 18: Mercurial Training

www.lptjournal.org

MQ tool

• Hg qnew –m “message for patch” <patch name>– Create a new patch with a patch name

• Hg qrefresh – Save new change to the top applied patchNote: hg revert will let you come back the last refresh state.

Eng. TrungHuynh™

Page 19: Mercurial Training

www.lptjournal.org

MQ tool

• Hg qpop – Pop out the top patch from the queue

• Hg qpush– Push a patch into the queue

• Hg qdelete <patch.name>– Delete a patch from a queue. The file is still preserve

in patch repository• Hg qfinish ??

Eng. TrungHuynh™

Page 20: Mercurial Training

www.lptjournal.org

Mercurial vs Others

Eng. TrungHuynh™

From www.infoQ.com