mercurial/help/revsets.txt
changeset 30769 e520f0f4b1cf
parent 30768 43839a24fd59
child 30770 d0a758e7002b
equal deleted inserted replaced
30768:43839a24fd59 30769:e520f0f4b1cf
     1 Mercurial supports a functional language for selecting a set of
       
     2 revisions.
       
     3 
       
     4 The language supports a number of predicates which are joined by infix
       
     5 operators. Parenthesis can be used for grouping.
       
     6 
       
     7 Identifiers such as branch names may need quoting with single or
       
     8 double quotes if they contain characters like ``-`` or if they match
       
     9 one of the predefined predicates.
       
    10 
       
    11 Special characters can be used in quoted identifiers by escaping them,
       
    12 e.g., ``\n`` is interpreted as a newline. To prevent them from being
       
    13 interpreted, strings can be prefixed with ``r``, e.g. ``r'...'``.
       
    14 
       
    15 Operators
       
    16 =========
       
    17 
       
    18 There is a single prefix operator:
       
    19 
       
    20 ``not x``
       
    21   Changesets not in x. Short form is ``! x``.
       
    22 
       
    23 These are the supported infix operators:
       
    24 
       
    25 ``x::y``
       
    26   A DAG range, meaning all changesets that are descendants of x and
       
    27   ancestors of y, including x and y themselves. If the first endpoint
       
    28   is left out, this is equivalent to ``ancestors(y)``, if the second
       
    29   is left out it is equivalent to ``descendants(x)``.
       
    30 
       
    31   An alternative syntax is ``x..y``.
       
    32 
       
    33 ``x:y``
       
    34   All changesets with revision numbers between x and y, both
       
    35   inclusive. Either endpoint can be left out, they default to 0 and
       
    36   tip.
       
    37 
       
    38 ``x and y``
       
    39   The intersection of changesets in x and y. Short form is ``x & y``.
       
    40 
       
    41 ``x or y``
       
    42   The union of changesets in x and y. There are two alternative short
       
    43   forms: ``x | y`` and ``x + y``.
       
    44 
       
    45 ``x - y``
       
    46   Changesets in x but not in y.
       
    47 
       
    48 ``x % y``
       
    49   Changesets that are ancestors of x but not ancestors of y (i.e. ::x - ::y).
       
    50   This is shorthand notation for ``only(x, y)`` (see below). The second
       
    51   argument is optional and, if left out, is equivalent to ``only(x)``.
       
    52 
       
    53 ``x^n``
       
    54   The nth parent of x, n == 0, 1, or 2.
       
    55   For n == 0, x; for n == 1, the first parent of each changeset in x;
       
    56   for n == 2, the second parent of changeset in x.
       
    57 
       
    58 ``x~n``
       
    59   The nth first ancestor of x; ``x~0`` is x; ``x~3`` is ``x^^^``.
       
    60 
       
    61 ``x ## y``
       
    62   Concatenate strings and identifiers into one string.
       
    63 
       
    64   All other prefix, infix and postfix operators have lower priority than
       
    65   ``##``. For example, ``a1 ## a2~2`` is equivalent to ``(a1 ## a2)~2``.
       
    66 
       
    67   For example::
       
    68 
       
    69     [revsetalias]
       
    70     issue(a1) = grep(r'\bissue[ :]?' ## a1 ## r'\b|\bbug\(' ## a1 ## r'\)')
       
    71 
       
    72     ``issue(1234)`` is equivalent to
       
    73     ``grep(r'\bissue[ :]?1234\b|\bbug\(1234\)')``
       
    74     in this case. This matches against all of "issue 1234", "issue:1234",
       
    75     "issue1234" and "bug(1234)".
       
    76 
       
    77 There is a single postfix operator:
       
    78 
       
    79 ``x^``
       
    80   Equivalent to ``x^1``, the first parent of each changeset in x.
       
    81 
       
    82 Predicates
       
    83 ==========
       
    84 
       
    85 The following predicates are supported:
       
    86 
       
    87 .. predicatesmarker
       
    88 
       
    89 Aliases
       
    90 =======
       
    91 
       
    92 New predicates (known as "aliases") can be defined, using any combination of
       
    93 existing predicates or other aliases. An alias definition looks like::
       
    94 
       
    95   <alias> = <definition>
       
    96 
       
    97 in the ``revsetalias`` section of a Mercurial configuration file. Arguments
       
    98 of the form `a1`, `a2`, etc. are substituted from the alias into the
       
    99 definition.
       
   100 
       
   101 For example,
       
   102 
       
   103 ::
       
   104 
       
   105   [revsetalias]
       
   106   h = heads()
       
   107   d(s) = sort(s, date)
       
   108   rs(s, k) = reverse(sort(s, k))
       
   109 
       
   110 defines three aliases, ``h``, ``d``, and ``rs``. ``rs(0:tip, author)`` is
       
   111 exactly equivalent to ``reverse(sort(0:tip, author))``.
       
   112 
       
   113 Equivalents
       
   114 ===========
       
   115 
       
   116 Command line equivalents for :hg:`log`::
       
   117 
       
   118   -f    ->  ::.
       
   119   -d x  ->  date(x)
       
   120   -k x  ->  keyword(x)
       
   121   -m    ->  merge()
       
   122   -u x  ->  user(x)
       
   123   -b x  ->  branch(x)
       
   124   -P x  ->  !::x
       
   125   -l x  ->  limit(expr, x)
       
   126 
       
   127 Examples
       
   128 ========
       
   129 
       
   130 Some sample queries:
       
   131 
       
   132 - Changesets on the default branch::
       
   133 
       
   134     hg log -r "branch(default)"
       
   135 
       
   136 - Changesets on the default branch since tag 1.5 (excluding merges)::
       
   137 
       
   138     hg log -r "branch(default) and 1.5:: and not merge()"
       
   139 
       
   140 - Open branch heads::
       
   141 
       
   142     hg log -r "head() and not closed()"
       
   143 
       
   144 - Changesets between tags 1.3 and 1.5 mentioning "bug" that affect
       
   145   ``hgext/*``::
       
   146 
       
   147     hg log -r "1.3::1.5 and keyword(bug) and file('hgext/*')"
       
   148 
       
   149 - Changesets committed in May 2008, sorted by user::
       
   150 
       
   151     hg log -r "sort(date('May 2008'), user)"
       
   152 
       
   153 - Changesets mentioning "bug" or "issue" that are not in a tagged
       
   154   release::
       
   155 
       
   156     hg log -r "(keyword(bug) or keyword(issue)) and not ancestors(tag())"