Benutzer-Werkzeuge

Webseiten-Werkzeuge


becki:linux:mercurial_tips

Dies ist eine alte Version des Dokuments!


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

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

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

See hg clone

(Note that there exists also a possibility for internal branches and merges.)

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.

See also Handling Variants for the solution in SVN.

FIXME Verify

1st Idea

Exclude client-specific code from the repo:

  • Keep variable code in a separate subdir of the repo.
  • Exclude this subdir in .hgignore.
  • Optionally create a sub-repo in the subdir to track local changes of the variant.

Sub-repo can always pull from the sub-repo of the trunk. Everything in the main repo can pushed and pulled in every direction.

2nd Idea

All variants are part of the whole project:

  • Keep variants in separate subdirs of the repo. One subdir per variant.
  • Make a symlink to the currently used variant and refer to the variant only via the symlink from the other code
  • Exclude the symlink in .hgignore.

Advantages: Every variant is accessible in every repo. Everything can pushed and pulled in every direction.
Disadvantage: Symlink must be created or a fallback mechanism to a default-variant must be implemented.

3rd Idea

  • Clone the „trunk“-repo for each variant
  • Change whatever you want in the variant repo
  • Edit generic code only in the trunk
  • Pull changes of the trunk into the variants, but never the other way around!

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 more commits than the latest

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.

Publishing with Webserver

Source

mkdir /etc/mercurial

Create /etc/mercurial/hgrc:

[web]
allow_archive = gz, bz2

Create /etc/mercurial/hgwebrc

[collections]
/home/share/hgroot = /home/share/hgroot

Copy hgweb.cgi from root dir of mercurial tarball to /var/www/cgi-bin, optionally rename it to hgweb and make the following edits:

@@ -4,10 +4,13 @@
 # See also http://mercurial.selenic.com/wiki/PublishingRepositories
 
 # Path to repo or hgweb config to serve (see 'hg help hgweb')
-config = "/path/to/repo/or/config"
+config = "/etc/mercurial/hgwebrc"
 
 # Uncomment and adjust if Mercurial is not installed system-wide:
-#import sys; sys.path.insert(0, "/path/to/python/lib")
+import sys; sys.path.insert(0, "/usr/local/lib/python2.5/site-packages")
+
+import os
+os.environ["HGENCODING"] = "UTF-8"
 
 # Uncomment to send python tracebacks to the browser if an error occurs:
 #import cgitb; cgitb.enable()

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

Todo

Cookies helfen bei der Bereitstellung von Inhalten. Diese Website verwendet Cookies. Mit der Nutzung der Website erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Computer gespeichert werden. Außerdem bestätigen Sie, dass Sie unsere Datenschutzerklärung gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website. Weitere Information
becki/linux/mercurial_tips.1309533219.txt.gz · Zuletzt geändert: 2011-07-01 15:13 von becki

Impressum - Datenschutzerklärung