From patchwork Fri May 29 14:38:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 5] revset: make internal _list() expression remove duplicated revisions From: Yuya Nishihara X-Patchwork-Id: 9357 Message-Id: <5be635444c0156a6d068.1432910285@mimosa> To: mercurial-devel@selenic.com Date: Fri, 29 May 2015 23:38:05 +0900 # HG changeset patch # User Yuya Nishihara # Date 1432446581 -32400 # Sun May 24 14:49:41 2015 +0900 # Node ID 5be635444c0156a6d0688d5ba3688a9a9db7f561 # Parent 5617fab1b1f1905663bd38053144a93a746f34db revset: make internal _list() expression remove duplicated revisions This allows us to optimize chained 'or' operations to _list() expression. Unlike _intlist() or _hexlist(), it's difficult to remove duplicates by the caller of _list() because different symbols can point to the same revision. If the caller knows all symbols are unique, that probably means revisions or nodes are known, therefore, _intlist() or _hexlist() should be used instead. So, it makes sense to check duplicates by _list() function. '%ls' is no longer used in core, this won't cause performance regression. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1920,9 +1920,18 @@ def _list(repo, subset, x): s = getstring(x, "internal error") if not s: return baseset() - ls = [repo[r].rev() for r in s.split('\0')] - s = subset - return baseset([r for r in ls if r in s]) + # remove duplicates here. it's difficult for caller to deduplicate sets + # because different symbols can point to the same rev. + ls = [] + seen = set() + for t in s.split('\0'): + r = repo[t].rev() + if r in seen: + continue + if r in subset: + ls.append(r) + seen.add(r) + return baseset(ls) # for internal use def _intlist(repo, subset, x):