Inhaltsverzeichnis

Mercurial Tips

Install from Source

(As an alternative if the package of the distro is outdated)

  1. Remove the original package from the system (removepkg mercurial…)
  2. Download and unpack the newest source tarball
  3. Cd into unpacked dir and type make to get help
  4. Type make install
  5. Create the file /etc/profile.d/mercurial.sh with this content:
    export PYTHONPATH="/usr/local/lib/python2.5/site-package"

Step 4 installs the following content to usr/local/:

lib/python2.5/site-packages/hgext/
lib/python2.5/site-packages/mercurial/
lib/python2.5/site-packages/mercurial-1.8.4-py2.5.egg-info
bin/hg
share/man/man1/hg.1        # not with 1.8 ?
share/man/man5/hgrc.5      # not with 1.8 ?
share/man/man5/hgignore.5  # not with 1.8 ?

See also

Configuration

Configuration of mercurial is done in $HOME/.hgrc. See http://www.selenic.com/mercurial/hgrc.5.html

Config example

; ~/.hgrc
 
[extensions]
hgext.graphlog =
hgext.extdiff =
 
[extdiff]
cmd.kdiff = kompare
 
[paths]
someShortcut = ssh://someUrl/somePath/someProject

Enable graphical log

Add this to the file $HOME/.hgrc:

[extensions]
hgext.graphlog =

Usage: hg glog [OPTIONS] - More

More user friendly diff

Sources: TipsAndTricks Extdiff extension HGBook

Command Line Diff

Download and install colordiff from www.slackbuilds.org. Then add the following to $HOME/.hgrc:

[extensions]
hgext.extdiff =
 
[extdiff]
cmd.cdiff = colordiff
opts.cdiff = -uprN

Usage: hg cdiff [...] [| less -R]

Graphical Diff

Add the following to $HOME/.hgrc:

[extensions]
hgext.extdiff =
 
[extdiff]
cmd.kdiff = kompare

Changing the username

Edit ~/.hgrc (More):

[ui]
username = New Username <new@address>

Remote Repositories

Bookmarks for often accessed remote repositories can be set in .hgrc. Example:

alias

http://www.selenic.com/mercurial/hg.1.html#urls

Changing default push/pull Path

Just edit .hg/hgrc in your local repo. More

Usage

Initial import

Cd into the root directory of your project and type hg init. This merely creates the subdir .hg which is the repository.:?: The current dir becomes the working dir of the project.

Add all files to the project by hg add and hg commit

Source

Templates and Styles

Log-like commands can be formatted with froatting strings, wich ar called templates. A style is simply a precanned template. Command to list all installed styles:

hg log --template list

Command to incluce phase info into the log:

hg glog --template phases
hg glog -T phases

Converting Repo from CVS

This is a no-brainer ;-) See ConvertExtension. Note that the conversion worked witout the cvsps tool mentioned there (On Slack 12.2 with Mercurial 1.4.1)

hg convert <pathToCheckedOutCvsModule>

Branching

Remommendation: Use internal branches, i.e. hg branch and add a bookmark to each branch. Don't use hg clone or named branches for branching.

See alo http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

Merging

Pulling from another repository usually creates a 2nd head (= 2nd branch) in your repo.

Merging means: Apply the changes between the last common changeset of your branch and the head of the pulled branch into the working directory.

Handling Variants

This section describes how to create e.g. client-specific variants of the same main project eg. for special needs of customers.

FIXME Use wiki/RebaseExtension and fix rest of this section.

"Separate what changes" Solution

Using the example of css-skins:

Project structure:

.
|-- .hgignore
|-- index.html
|-- skin.css -> skins_user/franz.css
|-- skins_dist
|   |-- default.css
|   |-- helmut.css
|   `-- otto.css
`-- skins_user
    `-- franz.css

.hgignore:

syntax: glob

skin.css
skins_user

Advantages: Every distributed skin is accessible in every repo. Everything can pushed and pulled in every direction.
Disadvantage: Symlink must be created after cloning a repo

"Patch" Solution

Suitable for projects which are not under your control, i.e. where you just use the code and don't contribute back.

Undoing Changes

Undoing lokal Changes

hg revert <file1> [<file2>]

Restores the files in the working directory to the state when they had been last commited. Much more options are posssible, see hg help revert Hgbook Wiki

Undo latest commit

Do hg rollback (and afterwards hg revert)

Undo an older commit

Use hg backout REV. The old commit is not deleted from history, but reverted as new commit

Undo more commits than the latest

hg strip (can also be used to remove an older head)

Or:

Use clone -r <revnumber> <old> <new> to create a repo which contains only the changesets until <revnumber>. Than throw away the original repo and use the cloned repo.

History editing

hg histedit e.g. for merging serveral changesets into one. See Wiki

Wrong histeds may be reverted by hg unbundle .hg/strip-backup/<backupfile>. This works for wrong hg rebases as well.

'cherry-picking

Copy changes from other branches onto the current branch: See hg/help/graft

Queues

Source: MqTutorial

hg init --mq             # Start / -c for version control / qinit is deprecated
hg qnew -m 'message' name_of_patch    # Create new patch
hg qrefresh              # Update the patch with the new changes
hg qapplied              # Show currently pushed patches
hg qfinish name_of_patch # Make the patch a permanent commit
 
# Pull changes from upstream:
hg qpop -a               # remove all patches from repo
hg pull -u
hg qpush -a              # apply all patches to repo
 
# Push changes to upstream:???
hg qpop -a               # remove all patches from repo
hg push
hg qpush -a              # apply all patches to repo

Collaboration models

Basically there is Pull-only versus shared-push collaboration. See also wiki/WorkingPractices

Publishing with Webserver

Uncomment or add the following line to /etc/httpd/httpd.conf:

LoadModule cgi_module lib/httpd/modules/mod_cgi.so

Source

Create file /etc/mercurial/webrc1):

[collections]
/home/share/hgroot = /home/share/hgroot
 
[web]
allow_archive = gz, zip, bz2
encoding = UTF-8

Copy hgweb.cgi from root dir of the mercurial source2) tarball to /var/www/cgi-bin/hgweb and correct the path to the webrc config file:

7c7
< config = "/path/to/repo/or/config"
---
> config = "/etc/mercurial/webrc"

Clone some repositories into /home/share/hgroot and point browser to http://localhost/cgi-bin/hgweb/

Working with Git Repositories

With the HgGit extension you can push/pull to/from a remote (or local) Git repo while doing all the work in a local Hg repo. A nice way to get around Git commands :-)

See http://hg-git.github.io/ for more info.

Install

HgGit needs dulwich. Both is available on www.slackbuilds.org

Working with HgGit

Local repo (L) is hg, remote repo (R) is git.
We want to push/pull to/from branch master on R

FIXME Verify:

  1. L needs a (manually created) bookmark master which tells HgGit to push to / pull from which branch on R. Checkout if that bookmark must point to tip in order to get pushed all commits! Checkout if the bookmark must be active on L!
  2. The tag default/master is autmatically created and moved on L on every push to / pull from R
  3. In order to push from L to R, R must not be on the branch to which to L wants to push (see push)

See https://www.mercurial-scm.org/wiki/HgGit

Access Github

To push an existing Mercurial repository to Github:

  1. Import your public SSH key to Github
  2. Create an empty repo, e.g. foo on Github
  3. Cd into your local Hg repo and do
    hg bookmark -r default master # make a bookmark of master for default, so a ref gets created
    hg push git+ssh://git@github.com/becki/foo.git
1)
name is arbitrary, but it must be mentioned in web.cgi below and it must not be hgrc, because this is the global config file of mercurial
2)
For Slack, you need to download the source, cause the cgi is missing in default install