D5495: revset: add "branch" positional arguments to the merge revset

angel.ezquerra (Angel Ezquerra) phabricator at mercurial-scm.org
Sun Jan 6 19:03:37 UTC 2019


angel.ezquerra created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Make it possible to only include those merge revisions that are merges with one
  or more specific branches (passed as positional arguments to the merge revset
  function). All merge revisions are shown by default (i.e. if no "merge with"
  branches are specified).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5495

AFFECTED FILES
  mercurial/revset.py

CHANGE DETAILS

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1249,15 +1249,33 @@
         pass
     return baseset(datarepr=('<max %r, %r>', subset, os))
 
- at predicate('merge()', safe=True)
+ at predicate('merge(*withbranch)', safe=True)
 def merge(repo, subset, x):
-    """Changeset is a merge changeset.
+    """Changeset is a merge changeset
+
+    All merge revisions are returned by default. If one or more "withbranch"
+    names are provided only merges with those branches (i.e. whose
+    second parent belongs to one of those branches) will be returned.
     """
     # i18n: "merge" is a keyword
-    getargs(x, 0, 0, _("merge takes no arguments"))
+    args = getargsdict(x, 'merge', '*withbranch')
+    withbranches = []
+    if 'withbranch' in args:
+        for el in args['withbranch']:
+            # i18n: "withbranch" is a keyword
+            withbranches.append(getstring(el,
+                _('withbranch argument must be a string')))
     cl = repo.changelog
-    return subset.filter(lambda r: cl.parentrevs(r)[1] != -1,
-                         condrepr='<merge>')
+    if withbranches:
+        # basematch is a function that returns true when a revision
+        # is a merge and the second parent belongs to one of the
+        # selected "merge with branches"
+        matches = lambda r: (cl.parentrevs(r)[1] != -1
+                             and repo[r].p2().branch() in withbranches)
+    else:
+        # basematch is a function that returns true when a revision is a merge
+        matches = lambda r: cl.parentrevs(r)[1] != -1
+    return subset.filter(matches, condrepr='<merge>')
 
 @predicate('branchpoint()', safe=True)
 def branchpoint(repo, subset, x):



To: angel.ezquerra, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list