From patchwork Tue Jan 7 01:00:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7805: graft: don't remove from a list in a loop From: phabricator X-Patchwork-Id: 44169 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Tue, 7 Jan 2020 01:00:23 +0000 martinvonz created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY This addresses a TODO added in a1381eea7c7d (graft: do not use `.remove` on a smart set (regression), 2014-04-28). I couldn't measure any speedup. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D7805 AFFECTED FILES mercurial/commands.py CHANGE DETAILS To: martinvonz, #hg-reviewers Cc: mercurial-devel diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3080,14 +3080,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