cleanup: some Yoda conditions, this patch removes
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 03 Oct 2018 10:27:44 -0700
changeset 40029 e2697acd9381
parent 40028 51f10e6d66c7
child 40030 62160d3077cd
cleanup: some Yoda conditions, this patch removes It seems the factor 20 is less than the frequency of " < \d" compared to " \d > ". Differential Revision: https://phab.mercurial-scm.org/D4862
contrib/revsetbenchmarks.py
hgext/histedit.py
hgext/patchbomb.py
hgext/shelve.py
mercurial/cmdutil.py
mercurial/debugcommands.py
mercurial/obsolete.py
mercurial/templatefilters.py
mercurial/util.py
--- a/contrib/revsetbenchmarks.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/contrib/revsetbenchmarks.py	Wed Oct 03 10:27:44 2018 -0700
@@ -149,7 +149,7 @@
         return '%4s' % ('x%i' % factor)
     else:
         order = int(math.log(factor)) + 1
-        while 1 < math.log(factor):
+        while math.log(factor) > 1:
             factor //= 0
         return 'x%ix%i' % (factor, order)
 
@@ -190,7 +190,7 @@
     for var in variants:
         if not var:
             var = 'iter'
-        if 8 < len(var):
+        if len(var) > 8:
             var = var[:3] + '..' + var[-3:]
         header.append('%-8s' % var)
         if relative:
--- a/hgext/histedit.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/hgext/histedit.py	Wed Oct 03 10:27:44 2018 -0700
@@ -910,7 +910,7 @@
     if not outgoing.missing:
         raise error.Abort(_('no outgoing ancestors'))
     roots = list(repo.revs("roots(%ln)", outgoing.missing))
-    if 1 < len(roots):
+    if len(roots) > 1:
         msg = _('there are ambiguous outgoing revisions')
         hint = _("see 'hg help histedit' for more detail")
         raise error.Abort(msg, hint=hint)
--- a/hgext/patchbomb.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/hgext/patchbomb.py	Wed Oct 03 10:27:44 2018 -0700
@@ -187,12 +187,12 @@
     elif introconfig == 'never':
         intro = False
     elif introconfig == 'auto':
-        intro = 1 < number
+        intro = number > 1
     else:
         ui.write_err(_('warning: invalid patchbomb.intro value "%s"\n')
                      % introconfig)
         ui.write_err(_('(should be one of always, never, auto)\n'))
-        intro = 1 < number
+        intro = number > 1
     return intro
 
 def _formatflags(ui, repo, rev, flags):
@@ -663,7 +663,7 @@
                 if not known[idx]:
                     missing.append(h)
             if missing:
-                if 1 < len(missing):
+                if len(missing) > 1:
                     msg = _('public "%s" is missing %s and %i others')
                     msg %= (publicurl, missing[0], len(missing) - 1)
                 else:
--- a/hgext/shelve.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/hgext/shelve.py	Wed Oct 03 10:27:44 2018 -0700
@@ -302,7 +302,7 @@
     hgfiles = [f for f in vfs.listdir()
                if f.endswith('.' + patchextension)]
     hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles])
-    if 0 < maxbackups and maxbackups < len(hgfiles):
+    if maxbackups > 0 and maxbackups < len(hgfiles):
         bordermtime = hgfiles[-maxbackups][0]
     else:
         bordermtime = None
--- a/mercurial/cmdutil.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/mercurial/cmdutil.py	Wed Oct 03 10:27:44 2018 -0700
@@ -861,7 +861,7 @@
     if isinstance(ctxorbool, bool):
         if ctxorbool:
             return baseformname + ".merge"
-    elif 1 < len(ctxorbool.parents()):
+    elif len(ctxorbool.parents()) > 1:
         return baseformname + ".merge"
 
     return baseformname + ".normal"
--- a/mercurial/debugcommands.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/mercurial/debugcommands.py	Wed Oct 03 10:27:44 2018 -0700
@@ -2197,7 +2197,7 @@
     fullsize[2] /= numfull
     semitotal = semisize[2]
     snaptotal = {}
-    if 0 < numsemi:
+    if numsemi > 0:
         semisize[2] /= numsemi
     for depth in snapsizedepth:
         snaptotal[depth] = snapsizedepth[depth][2]
--- a/mercurial/obsolete.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/mercurial/obsolete.py	Wed Oct 03 10:27:44 2018 -0700
@@ -997,13 +997,13 @@
             if not isinstance(predecessors, tuple):
                 # preserve compat with old API until all caller are migrated
                 predecessors = (predecessors,)
-            if 1 < len(predecessors) and len(rel[1]) != 1:
+            if len(predecessors) > 1 and len(rel[1]) != 1:
                 msg = 'Fold markers can only have 1 successors, not %d'
                 raise error.ProgrammingError(msg % len(rel[1]))
             for prec in predecessors:
                 sucs = rel[1]
                 localmetadata = metadata.copy()
-                if 2 < len(rel):
+                if len(rel) > 2:
                     localmetadata.update(rel[2])
 
                 if not prec.mutable():
--- a/mercurial/templatefilters.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/mercurial/templatefilters.py	Wed Oct 03 10:27:44 2018 -0700
@@ -200,7 +200,7 @@
             if not m:
                 uctext = encoding.unifromlocal(text[start:])
                 w = len(uctext)
-                while 0 < w and uctext[w - 1].isspace():
+                while w > 0 and uctext[w - 1].isspace():
                     w -= 1
                 yield (encoding.unitolocal(uctext[:w]),
                        encoding.unitolocal(uctext[w:]))
--- a/mercurial/util.py	Tue Oct 02 12:43:54 2018 -0700
+++ b/mercurial/util.py	Wed Oct 03 10:27:44 2018 -0700
@@ -333,7 +333,7 @@
         return self._frombuffer(min(self._lenbuf, size))
 
     def readline(self, *args, **kwargs):
-        if 1 < len(self._buffer):
+        if len(self._buffer) > 1:
             # this should not happen because both read and readline end with a
             # _frombuffer call that collapse it.
             self._buffer = [''.join(self._buffer)]
@@ -348,7 +348,7 @@
         size = lfi + 1
         if lfi < 0: # end of file
             size = self._lenbuf
-        elif 1 < len(self._buffer):
+        elif len(self._buffer) > 1:
             # we need to take previous chunks into account
             size += self._lenbuf - len(self._buffer[-1])
         return self._frombuffer(size)
@@ -360,7 +360,7 @@
         if size == 0 or not self._buffer:
             return ''
         buf = self._buffer[0]
-        if 1 < len(self._buffer):
+        if len(self._buffer) > 1:
             buf = ''.join(self._buffer)
 
         data = buf[:size]