2. 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.phuongdo.vn Eng. TrungHuynh™
3. 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 Mercurial
zypper install mercurial
Check the installation: hg debuginstall
www.phuongdo.vn
Eng. TrungHuynh™
4. 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.phuongdo.vn
Eng. TrungHuynh™
5. 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
www.phuongdo.vn Eng. TrungHuynh™
Main.c Main.h
.hg
Rev 0 Rev 1 Rev 2 Rev 3parent parent parent
Working directory
repository
6. 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
www.phuongdo.vn Eng. TrungHuynh™
0 1 2 3 4
5
6(tip)
Working
dirhead
head
Branch Achangeset: 1:d7fd576b6c9b
| user: trunghuynh
| date: Fri Jun 08 17:28:32
2012 +0700
| files: hello1.cc
revision
7. 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 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 www.phuongdo.vn
Eng. TrungHuynh™
8. 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.phuongdo.vn
Eng. TrungHuynh™
10. hg push/pull
www.phuongdo.vn 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>
@
@
@
@ Mark parent revision
of working directory
A revision of repo
11. hg merge/update
www.phuongdo.vn Eng. TrungHuynh™
Alice’s Repo
0:qe7
1:de5
2:ye2
3: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
12. 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.
www.phuongdo.vn 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
13. 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.phuongdo.vn Eng. TrungHuynh™
14. 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.phuongdo.vn Eng. TrungHuynh™
15. MQ tool
• MQ is the extension tool of Mercurial that
manages your patches
– Modify the .hgrc to enable MQ
[extensions]
hgext.mq =
www.phuongdo.vn Eng. TrungHuynh™
17. 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.phuongdo.vn Eng. TrungHuynh™
18. 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.phuongdo.vn Eng. TrungHuynh™
19. 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.phuongdo.vn Eng. TrungHuynh™
pathsAssigns symbolic names to repositories. The left side is the symbolic name, and the right gives the directory or URL that is the location of the repository. Default paths can be declared by setting the following entries.defaultDirectory or URL to use when pulling if no source is specified. Default is set to repository from which the current repository was cloned.default-pushOptional. Directory or URL to use when pushing if no destination is specified.
Mercurial store the differences between the successive versions and periodic complete version of a file. Both of them are compressed before storingNodeId is simplify a SHA1 hash of the current file concatenated with the nodeids of one or both parents of the current revision.What will happens when we change the name of file ?
Reverts changes in your working directory back to that version, but keeps the current parents for the next checkin. This command exists for undoing changes in current versions, not for working on old versions.hg status reports when file contents or flags have changed relative to either parent. hg diff only reports changed contents relative to the first parent. You can see flag information with the --git option tohg diff and deltas relative to the other parent with -r. I want a clean, empty working directoryThe easiest thing to do is run hg clone -U which will create a fresh clone without checking out a working copy.If the repository already has a working copy, you can remove it running hg update null.If you've just committed it, and you haven't done any other commits or pulls since, you may be able to use rollback (see Rollback) to undo the last commit transactionHow can I do a "hg log" of a remote repository?The correct way to do this is cloning the remote repository to your computer and then doing a hg log locally.
Mercurial will push/pull all branches by default, while git will push/pull only the current branch.If you want to push/pull only a single branch with Mercurial you can use the --rev option (-r for short) and specify the tip revision of the branch
What Mercurial can’t do:Can not check out only on directory of a repository$ hg archive -t zip ../hg1.zip what do you when you want to send the source to some where?$ hg export -o ../hg1-rev28.diff 28 export the change in the revision 28 vs $ hg import ../hg1-rev28.diff (hg1-rev28.diff ~hg1-rev28.patch)When we use “hg merge” command. If there have some conflicts whe has to decide what thing we should keep.That means we has to open the conflict file, then we edit and save. The last thing is “hg resolve <option here> “ command.
What Mercurial can’t do:Can not check out only on directory of a repository$ hg archive -t zip ../hg1.zip what do you when you want to send the source to some where?$ hg export -o ../hg1-rev28.diff 28 export the change in the revision 28 vs $ hg import ../hg1-rev28.diff (hg1-rev28.diff ~hg1-rev28.patch)When we use “hg merge” command. If there have some conflicts whe has to decide what thing we should keep.That means we has to open the conflict file, then we edit and save. The last thing is “hg resolve <option here> “ command.
Obviously, by using patching technique we can separate the changes with base code. If there is unnecessary the changes, we can easy move the changes away. Hgqrefresh can runned any time and the topmost applied patch will be updated.Ancestor of Mq is quilt tool
@@ -14,6 +14,7 @@Begin with number line is 14 original with 6 line after but after modified the number of line is 7Is mean removed line+ is mean added line
the best performance of it. No commentsFirst of all, try to “batch” operations together. Every time you run qpush or qpop, these commands scan the working directory once to make sure you haven't made some changes and then forgotten to run qrefresh. On a small tree, the time that this scan takes is unnoticeable. However, on a medium-sized tree (containing tens of thousands of files), it can take a second or more. No comments
You should notice that Mercurial doubles the number of files in your repository (the historic is kept per file in .hg/store/data). It doesn't seem to be a good choice for Windows system running on NTFS. It's also interesting to see that git takes a big advantage of the system when executing command. While Hg and Bzr do not spend a big proportion of time in system, Git can take up to 10-40% cpu time within system call, which raises the question as to how it will perform on Windows system where the git-developers won't have access to all the system performance trick they are used to with Linux. Single Merges and Merge Queues should be tested, this is a tiedous part to benchmark.http://www.infoq.com/articles/dvcs-guidehttp://betterexplained.com/articles/intro-to-distributed-version-control-illustrated/