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=('', subset, os)) -@predicate('merge()', safe=True) +@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='') + 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='') @predicate('branchpoint()', safe=True) def branchpoint(repo, subset, x):