[PATCH 05 of 10] revset: use try-except instead of if-else because of perf

Pulkit Goyal 7895pulkit at gmail.com
Mon May 22 16:52:15 EDT 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1495398823 -19800
#      Mon May 22 02:03:43 2017 +0530
# Node ID 05143c5cb16a9e50b40321d5417e0c91ba6afb16
# Parent  7cb5bf075d4aa046f7b39149c720d63253d510d6
revset: use try-except instead of if-else because of perf

For wdir(), we now raises an exception which will be raised when wdir() will be
passed, so catching that exception is better checking for wdir() using if-else.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1456,10 +1456,10 @@
         up = ps.update
         parentrevs = cl.parentrevs
         for r in getset(repo, fullreposet(repo), x):
-            if r == node.wdirrev:
+            try:
+                up(parentrevs(r))
+            except error.WdirUnsupported:
                 up(p.rev() for p in repo[r].parents())
-            else:
-                up(parentrevs(r))
     ps -= {node.nullrev}
     return subset & ps
 


More information about the Mercurial-devel mailing list