[PATCH 1 of 4] revrange: drop unnecessary deduplication of revisions

Yuya Nishihara yuya at tcha.org
Mon Jun 1 15:21:04 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1432457602 -32400
#      Sun May 24 17:53:22 2015 +0900
# Node ID bbd7b058bb0fc3bd5c1159717c579dfa0fc87a53
# Parent  4cc3fb23881d9abc7745501ef0d777e5976ddb52
revrange: drop unnecessary deduplication of revisions

Because "l" is a smartset, duplicated entries are omitted by addsets.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -709,14 +709,12 @@ def revrange(repo, revs):
             return defval
         return repo[val].rev()
 
-    seen, l = set(), revset.baseset([])
+    l = revset.baseset([])
 
     revsetaliases = [alias for (alias, _) in
                      repo.ui.configitems("revsetalias")]
 
     for spec in revs:
-        if l and not seen:
-            seen = set(l)
         # attempt to parse old-style ranges first to deal with
         # things like old-tag which contain query metacharacters
         try:
@@ -727,7 +725,6 @@ def revrange(repo, revs):
                 raise error.RepoLookupError
 
             if isinstance(spec, int):
-                seen.add(spec)
                 l = l + revset.baseset([spec])
                 continue
 
@@ -741,24 +738,15 @@ def revrange(repo, revs):
                 if end == nullrev and start < 0:
                     start = nullrev
                 rangeiter = repo.changelog.revs(start, end)
-                if not seen and not l:
+                if not l:
                     # by far the most common case: revs = ["-1:0"]
                     l = revset.baseset(rangeiter)
-                    # defer syncing seen until next iteration
                     continue
                 newrevs = set(rangeiter)
-                if seen:
-                    newrevs.difference_update(seen)
-                    seen.update(newrevs)
-                else:
-                    seen = newrevs
                 l = l + revset.baseset(sorted(newrevs, reverse=start > end))
                 continue
             elif spec and spec in repo: # single unquoted rev
                 rev = revfix(repo, spec, None)
-                if rev in seen:
-                    continue
-                seen.add(rev)
                 l = l + revset.baseset([rev])
                 continue
         except error.RepoLookupError:
@@ -766,10 +754,9 @@ def revrange(repo, revs):
 
         # fall through to new-style queries if old-style fails
         m = revset.match(repo.ui, spec, repo)
-        if seen or l:
-            dl = [r for r in m(repo) if r not in seen]
+        if l:
+            dl = [r for r in m(repo)]
             l = l + revset.baseset(dl)
-            seen.update(dl)
         else:
             l = m(repo)
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -858,6 +858,16 @@ test that `or` operation combines elemen
   4
   5
 
+test that more than one `-r`s are combined in the right order and deduplicated:
+
+  $ hg log -T '{rev}\n' -r 3 -r 3 -r 4 -r 5:2 -r 'ancestors(4)'
+  3
+  4
+  5
+  2
+  0
+  1
+
 test that `or` operation skips duplicated revisions from right-hand side
 
   $ try 'reverse(1::5) or ancestors(4)'


More information about the Mercurial-devel mailing list