Patchwork D7805: graft: don't remove from a list in a loop

login
register
mail settings
Submitter phabricator
Date Jan. 9, 2020, 2:58 p.m.
Message ID <b428e84eb54107e7fc61aa7afe1c867f@localhost.localdomain>
Download mbox | patch
Permalink /patch/44235/
State Not Applicable
Headers show

Comments

phabricator - Jan. 9, 2020, 2:58 p.m.
Closed by commit rHGdf82c06e1a05: graft: don&#039;t remove from a list in a loop (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7805?vs=19057&id=19129

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7805/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7805

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, mharbison72, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3082,14 +3082,13 @@ 
         crev = repo[b'.'].rev()
         ancestors = repo.changelog.ancestors([crev], inclusive=True)
         # XXX make this lazy in the future
-        # don't mutate while iterating, create a copy
-        for rev in list(revs):
+        for rev in revs:
             if rev in ancestors:
                 ui.warn(
                     _(b'skipping ancestor revision %d:%s\n') % (rev, repo[rev])
                 )
-                # XXX remove on list is slow
-                revs.remove(rev)
+        revs = [r for r in revs if r not in ancestors]
+
         if not revs:
             return -1