From patchwork Sun Jun 11 05:36:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6, of, 6] revset: fix order of first/last members in compound expression (BC) From: Yuya Nishihara X-Patchwork-Id: 21329 Message-Id: <0fcda861cf6a78f36ffa.1497159376@mimosa> To: mercurial-devel@mercurial-scm.org Date: Sun, 11 Jun 2017 14:36:16 +0900 # HG changeset patch # User Yuya Nishihara # Date 1497091728 -32400 # Sat Jun 10 19:48:48 2017 +0900 # Node ID 0fcda861cf6a78f36ffae19bbda0e8150d43ae22 # Parent 24b03ed1d589fac6ebbcd6eea00bf6f749a5cd72 revset: fix order of first/last members in compound expression (BC) Suppose len(subset) >> len(ls) in common cases, 'subset & ls' should be avoided whenever possible. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -884,11 +884,11 @@ def filelog(repo, subset, x): return subset & s -@predicate('first(set, [n])', safe=True) -def first(repo, subset, x): +@predicate('first(set, [n])', safe=True, takeorder=True) +def first(repo, subset, x, order): """An alias for limit(). """ - return limit(repo, subset, x) + return limit(repo, subset, x, order) def _follow(repo, subset, x, name, followfirst=False): l = getargs(x, 0, 2, _("%s takes no arguments or a pattern " @@ -1152,8 +1152,8 @@ def keyword(repo, subset, x): return subset.filter(matches, condrepr=('', kw)) -@predicate('limit(set[, n[, offset]])', safe=True) -def limit(repo, subset, x): +@predicate('limit(set[, n[, offset]])', safe=True, takeorder=True) +def limit(repo, subset, x, order): """First n members of set, defaulting to 1, starting from offset. """ args = getargsdict(x, 'limit', 'set n offset') @@ -1181,10 +1181,12 @@ def limit(repo, subset, x): break result.append(y) ls = baseset(result, datarepr=('', lim, ofs, os)) + if order == followorder and lim > 1: + return subset & ls return ls & subset -@predicate('last(set, [n])', safe=True) -def last(repo, subset, x): +@predicate('last(set, [n])', safe=True, takeorder=True) +def last(repo, subset, x, order): """Last n members of set, defaulting to 1. """ # i18n: "last" is a keyword @@ -1205,6 +1207,8 @@ def last(repo, subset, x): break result.append(y) ls = baseset(result, datarepr=('', lim, os)) + if order == followorder and lim > 1: + return subset & ls ls.reverse() return ls & subset diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -1031,13 +1031,12 @@ Test order of first/last revisions $ hg debugrevspec -s '3: & first(4:0, 3)' * set: , >>, - > + >>> + 3 4 - 3 -BROKEN: should be '3 4' $ hg debugrevspec -s 'last(4:0, 3) & :1' * set: @@ -1052,13 +1051,12 @@ BROKEN: should be '3 4' $ hg debugrevspec -s ':1 & last(4:0, 3)' * set: , >>, - > + >>> + 0 1 - 0 -BROKEN: should be '0 1' Test matching