MercurialEclipse plugin for Eclipse

If you use Eclipse as your IDE and Mercurial as your version control system, then you might find the MercurialEclipse plugin useful. If you add, remove, rename or move source files using Eclipse, it is a pain to synchronize these changes to the underlying Mercurial repository. If you use the MercurialEclipse plugin, all can make all the changes you wish directly to the repository.

Install

Go to Help > Install New Software > Add and add http://mercurialeclipse.eclipselabs.org.codespot.com/hg.wiki/update_site/stable to Location and click OK. Pick the Stable release and proceed with the rest of the installation. Restart Eclipse after the plugin is installed.

Usage

The big problem I have with MercurialEclipse is that it will not work with existing repositories. You have to clone an existing repository using MercurialEclipse, so that it can create a project of that in your Workspace. This is the only way to begin using it. To do this, go to File > New > Project > Mercurial > Clone Existing Mercurial Repository. Provide the URL or local location and create the project.

To do any Mercurial operation, click on the relevant project, directory or source file in Project Explorer and choose Team. All the relevant Mercurial operations can be seen listed in this right-click menu.

The status of the files in the repository are indicated by icon overlays in Project Explorer. You can do almost all the Mercurial operations from inside Eclipse, including viewing the history log and graph, committing, changing branches and so on.

Tried with: MercurialEclipse 2.1.0, Eclipse 3.7.2 and Ubuntu 12.04 LTS

Advertisements

Side-by-side color diff at terminal using CDiff

20150708_cdiff

If you use Mercurial, Git or Subversion at the shell, CDiff is a useful tool to have around. By default, hg diff or git diff is displayed in the classic diff format. This shows the before-and-after changed lines one below the other. Personally, I find this very confusing. I very much prefer the side-by-side diff view used in GUI diff programs. cdiff is a great way to get this side-by-side diff view at the shell in full color!

Install

CDiff is a Python program that can be installed from PyPI using this command:

$ sudo pip install cdiff

Note: Do not confuse this package with the colordiff package that is available in Ubuntu repositories. That is something else!

Usage

  • Invoke cdiff in any subdirectory of a Mercurial, Git or Subversion repository. By default, this shows a colorful diff of the changes in all uncommitted files.

  • To get side-by-side diff view use: cdiff -s

  • CDiff assumes that your window width is 80 by default. I prefer to view side-by-side diff that uses the full width of my terminal window. This can be achieved by invoking: cdiff -s -w 0

  • To diff two files, just pass them through diff -u and pipe that to cdiff:

$ diff -u file1.cpp file2.cpp | cdiff -s

Tried with: CDiff 0.9.7, Python 2.7.6 and Ubuntu 14.04

How to install Mercurial Keyring extension on Ubuntu

The Mercurial Keyring extension eliminates the pain of having to authenticate yourself with username and password every time you need to push or pull from repositories using the HTTPS protocol. Enabling this extension on Windows is pretty easy with TortoiseHg.

To install and enable this extension on Ubuntu:

  • Newer distributions of Ubuntu have a package of this extension. You can try:
$ sudo apt-get install mercurial-keyring
  • If there is no package of this extension, then install the python-setuptools package if it is not already present. This provides the easy_install program which is needed for the next steps.

  • Install the keyring Python package using easy_install:

$ sudo easy_install keyring
  • Install the mercurial_keyring Python package:
$ sudo easy_install mercurial_keyring
  • Enable the mercurial_keyring package in Mercurial by modifying the configuration file as explained here.

Tried with: Mercurial 2.0.2 and Ubuntu 12.04.2 LTS

How to have a global hgignore for Mercurial

The hgignore file can be used to help Mercurial in deciding which files to ignore. If you find yourself repeating the same file patterns in the hgignore files of your Mercurial repositories, then you might want to create a global hgignore file.

First, create a .hgignore file in your home directory. Fill it up with patterns just like you did for your repository’s hgignore.

Next, add this entry to your global Mercurial configuration file:

[ui]
ignore = ~/.hgignore

Tried with: Mercurial 2.0.2 and Ubuntu 12.04 LTS

How to use a pager with output from Mercurial

The output of many commands in Mercurial can spill beyond the height of the terminal. An external pager can be applied to this output automatically by using the pager extension that ships with Mercurial.

In the Mercurial configuration file, first enable the plugin by using the word pager and next indicate the pager program you would like it to use. For example:

[pager]
pager = less

To use the pager only when the output is more than one page and to preserve the color output of Mercurial, so I use this:

[pager]
pager = less --quit-if-one-screen --RAW-CONTROL-CHARS --no-init

Tried with: Mercurial 2.0.2

Mercurial: Not trusting file from untrusted user or group

Mercurial gives this error for the hgrc (Mercurial configuration file) when the user running a Mercurial command is not the same as the owner of hgrc. This typically happens on servers, shares or distributed filesystems.

To fix this, add a trusted section to the configuration file to tell Mercurial to trust the user or group reported in the error.

For example, if Mercurial complains that it does not trust joe and you happen to trust him, add him to hgrc:

[trusted]
users = joe

Tried with: Mercurial 2.0.2 and Ubuntu 12.04.1 LTS

How to create aliases for Mercurial commands

Just like aliases in bash, you can create aliases for Mercurial commands. This functionality is available through the alias extension. Just create a new section in your Mercurial configuration file and add aliases.

For example, to create an alias to show log in graph format and another to show compact log:

[alias]
lg = log --graph
lc = log --style=compact

Even Mercurial commands can be replaced with an alias.

Tried with: Mercurial 2.0.2 and Ubuntu 12.04.1 LTS

How to enable color in the output of Mercurial

The output of Mercurial commands at the terminal can really use some color. The file status, log output and especially the diff can be much easier to read and process with color.

This functionality is present in the color extension that ships with Mercurial. Enable this extension by modifying your Mercurial configuration file and you are done.

Tried with: Mercurial 2.0.2 and Ubuntu 12.04.1 LTS

How to show repository log as ASCII graph in Mercurial

TortoiseHg can be used to view the graph of commits and branches of a Mercurial repository. For repositories whose history is not so complicated, it may be convenient to check its graph at the commandline. This means displaying a ASCII graph of the log.

This feature is available through the graphlog extension that ships with Mercurial. Enable this extension in your Mercurial configuration file and you can view the graph by using the command:

$ hg log --graph

Tried with: Mercurial 2.0.2 and Ubuntu 12.04.1 LTS