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

login
register
mail settings
Submitter Pulkit Goyal
Date May 22, 2017, 8:52 p.m.
Message ID <05143c5cb16a9e50b403.1495486335@workspace>
Download mbox | patch
Permalink /patch/20846/
State Accepted
Headers show

Comments

Pulkit Goyal - May 22, 2017, 8:52 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@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.

Patch

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