Nearest Extension

This extension is not distributed with Mercurial.

Author: Gilles Moris (morisgi)

Download site: http://freehg.org/u/morisgi/nearest/

Overview

The goal of the nearest mercurial extension is to find the nearest tag(s) from a given changeset, either backward or forward in the changesets history tree.

By default, tags are searched backward in history, but using the --contains option will make it search forward. It answers the following questions:BR

The tags are searched by date, so that the nearest tag in time will be reported. However, the --all option will make the extension search the first tag on all possible branches.

Configuration

Enable the extension by adding following lines to your configuration file (~/.hgrc):

[extensions]
nearest=/path/to/nearest.py

Usage

hg nearest [--contains] [--all] [--match pattern] [--format outputspec] [--tagsep char] REV ...

If no argument is provided, it returns the nearest tag on which the working directory is based on:

$ hg nearest
1.1+55

Which versions will include revision 5500:

$ hg nearest --contains --all 5500
1.0-727
1.0.1-633
1.1-1361

Note that even though there are more commits to 1.0, it is reported first due to its older date.

The --match option can be used to filter the tags. For instance to find a 0.9.x tag:

# The "*" replace any sequence of character
# The "?" replaces a single character
# To match characters "a", "b" or "c", use [abc]
$ hg nearest --match "0.9.*"

Output customization

The default output format is "tag+dist", and "tag-dist" with the --contains option, where "dist" is the longest path to the tag.

The format output can be customized using the --format option with the following rules:

You can use \n or \t to include special characters.

You can use the following section in the configuration file to save the format:

[nearest]
format = this is the generic format for backward and forward if they are not set below\n
# do not forget to double % chars in hgrc file, like %%r
format.forward = format specialized for --contains
format.backward = format specialized without --contains
format.exact = format in case of exact match
tagsep = string that separates tags for the %T format


CategoryExtension