[PATCH 3 of 3] revset: two new revsets, copies and renames

Jordi GutiƩrrez Hermoso jordigh at octave.org
Fri Apr 5 14:42:39 EDT 2019


# HG changeset patch
# User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
# Date 1554489566 14400
#      Fri Apr 05 14:39:26 2019 -0400
# Node ID cf6a3da4082569df7b5dd83ab61fcbedc70839f1
# Parent  4baa10f1f44a8e427f49fa4f4d8d29552c2a1a65
revset: two new revsets, copies and renames

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -757,6 +757,21 @@ def converted(repo, subset, x):
     return subset.filter(lambda r: _matchvalue(r),
                          condrepr=('<converted %r>', rev))
 
+ at predicate('copies(pattern)', safe=True, weight=30)
+def copies(repo, subset, x):
+    """Changesets which added files matching pattern via copying. This
+    excludes renames, which are copies where the original file was
+    removed.
+
+    The pattern without explicit kind like ``glob:`` is expected to be
+    relative to the current directory and match against a file or a
+    directory.
+
+    """
+    # i18n: "removes" is a keyword
+    pat = getstring(x, _("copies requires a pattern"))
+    return checkstatus(repo, subset, pat, 3)
+
 @predicate('date(interval)', safe=True, weight=10)
 def date(repo, subset, x):
     """Changesets within the interval, see :hg:`help dates`.
@@ -1802,6 +1817,18 @@ def public(repo, subset, x):
     getargs(x, 0, 0, _("public takes no arguments"))
     return _phase(repo, subset, phases.public)
 
+ at predicate('renames(pattern)', safe=True, weight=30)
+def renames(repo, subset, x):
+    """Changesets which added files matching pattern via a rename.
+
+    The pattern without explicit kind like ``glob:`` is expected to be
+    relative to the current directory and match against a file or a
+    directory.
+    """
+    # i18n: "removes" is a keyword
+    pat = getstring(x, _("renames requires a pattern"))
+    return checkstatus(repo, subset, pat, 4)
+
 @predicate('remote([id [,path]])', safe=False)
 def remote(repo, subset, x):
     """Local revision that corresponds to the given identifier in a
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -3038,3 +3038,15 @@ abort if the revset doesn't expect given
   $ log 'expectsize(0:2, :2)'
   abort: revset size mismatch. expected between 0 and 2, got 3!
   [255]
+
+test copies and renames
+
+  $ hg cp b c
+  $ hg ci -m copy
+  $ hg mv c d
+  $ hg ci -m rename
+  $ hg log -r 'copies("**")' -T '{rev}:{desc}\n'
+  10:copy
+  $ hg log -r 'renames("**")' -T '{rev}:{desc}\n'
+  11:rename
+


More information about the Mercurial-devel mailing list