Patchwork [2,of,6,v3] convert: Don't use long list comprehensions

login
register
mail settings
Submitter David Soria Parra
Date Dec. 7, 2016, 9:51 p.m.
Message ID <c0168cd90fd67ccd2027.1481147512@devbig415.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17871/
State Superseded
Headers show

Comments

David Soria Parra - Dec. 7, 2016, 9:51 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1481139493 28800
#      Wed Dec 07 11:38:13 2016 -0800
# Node ID c0168cd90fd67ccd20271416e0994abe6f95a201
# Parent  1f9a627a126694d67f3664dae387d8b98fa44ddb
convert: Don't use long list comprehensions

We are iterating over p4changes. Make the continue condition more clear
and easier to add new conditions in future patches, by removing the list
comprehension and move the condition into the existing for-loop.

Patch

diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py
--- a/hgext/convert/p4.py
+++ b/hgext/convert/p4.py
@@ -126,14 +126,16 @@ 
 
         # handle revision limiting
         startrev = self.ui.config('convert', 'p4.startrev', default=0)
-        self.p4changes = [x for x in self.p4changes
-                          if ((not startrev or int(x) >= int(startrev)) and
-                              (not self.revs or int(x) <= int(self.revs[0])))]
 
         # now read the full changelists to get the list of file revisions
         ui.status(_('collecting p4 changelists\n'))
         lastid = None
         for change in self.p4changes:
+            if startrev and int(change) < int(startrev):
+                continue
+            if self.revs and int(change) > int(self.revs[0]):
+                continue
+
             cmd = "p4 -G describe -s %s" % change
             stdout = util.popen(cmd, mode='rb')
             d = marshal.load(stdout)