Vous êtes sur la page 1sur 20

MERCURIAL TRAINING

www.lptjournal.org

6/4/2012 HCM city

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

www.lptjournal.org

Eng. TrungHuynh

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 repos 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 Mercurial


zypper install mercurial Check the installation: hg debuginstall
www.lptjournal.org Eng. TrungHuynh

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

www.lptjournal.org

Eng. TrungHuynh

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

Working directory Main.c Main.h

.hg
Rev 0 parent Rev 1 parent Rev 2

repository
parent Rev 3

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
www.lptjournal.org Eng. TrungHuynh

Basic Concepts
Revision is local version index for the project Changeset is unique version index for global
changeset: 1:d7fd576b6c9b | user: trunghuynh | date: Fri Jun 08 17:28:32 2012 +0700 | files: hello1.cc

Branch A

3 5

head 6(tip)

revision

head

Working dir

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
www.lptjournal.org Eng. TrungHuynh

Common Commands
hg 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 changesets 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
www.lptjournal.org Eng. TrungHuynh

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
www.lptjournal.org Eng. TrungHuynh

Hg commit
Alices Repo model.c main.c model.h socket.c @
2:ye2 3:af9

Working directory

3:a3e

changed

1:de5

When we commit a new changeset will be created

0:qe7

www.lptjournal.org

Eng. TrungHuynh

hgMain Repos push/pull


@
2:af9
Mark parent revision of working directory

1:de5

A revision of repo

0:qe7

Bobs Repo

Alices Repo

2:af9

2:ye2

2:af9

1:de5

hg pull <Bobs repo>

1:de5

0:qe7

0:qe7

www.lptjournal.org

Eng. TrungHuynh

hg merge/update
Alices Repo 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

2:ye2

3:af9

1:de5

0:qe7

www.lptjournal.org

Eng. TrungHuynh

Advance Using Mercurial


Merge conflict:
The conflict happens when two changesets have modified the same files section with different way. In this case, the Mercurial need a help from user. Changeset 4 Changeset 7

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

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

www.lptjournal.org

Eng. TrungHuynh

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.

www.lptjournal.org

Eng. TrungHuynh

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
www.lptjournal.org Eng. TrungHuynh

MQ tool
MQ is the extension tool of Mercurial that manages your patches
Modify the .hgrc to enable MQ
[extensions] hgext.mq =

www.lptjournal.org

Eng. TrungHuynh

MQ tool what is patch file?


diff --git a/opensaf.spec.in b/opensaf.spec.in Diff header --- 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)

Hunk

+%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

www.lptjournal.org

Eng. TrungHuynh

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
www.lptjournal.org Eng. TrungHuynh

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 patch Note: hg revert will let you come back the last refresh state.

www.lptjournal.org

Eng. TrungHuynh

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 ??
www.lptjournal.org Eng. TrungHuynh

Mercurial vs Others

From www.infoQ.com

www.lptjournal.org

Eng. TrungHuynh

Vous aimerez peut-être aussi