Patchwork util: make sortdict.keys() return a copy

login
register
mail settings
Submitter via Mercurial-devel
Date Jan. 31, 2017, 7:31 a.m.
Message ID <d10efbadb064038d3f7e.1485847876@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/18289/
State Accepted
Headers show

Comments

via Mercurial-devel - Jan. 31, 2017, 7:31 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1485845936 28800
#      Mon Jan 30 22:58:56 2017 -0800
# Branch stable
# Node ID d10efbadb064038d3f7ee6ce7bf0988733a2faa5
# Parent  312b861924c89716d9bdd28dd8698665ef6d0498
util: make sortdict.keys() return a copy

dict.keys() is documented to return a copy, so it's surprising that
sortdict.keys() did not. I noticed this because we have an extension
that calls readlocaltags(). That method tries to remove any tags that
point to non-existent revisions (most likely stripped). However, since
it's unintentionally working on the instance it's modifying, it
sometimes fails to remove tags when there are multiple bad tags in a
row. This was not caught because localrepo.tags() does an additional
layer of filtering.

sortdict is also used in other places, but I have not checked whether
its keys() and/or __delitem__() methods are used there.
Yuya Nishihara - Jan. 31, 2017, 2:37 p.m.
On Mon, 30 Jan 2017 23:31:16 -0800, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1485845936 28800
> #      Mon Jan 30 22:58:56 2017 -0800
> # Branch stable
> # Node ID d10efbadb064038d3f7ee6ce7bf0988733a2faa5
> # Parent  312b861924c89716d9bdd28dd8698665ef6d0498
> util: make sortdict.keys() return a copy

Seems good for stable, queued, thanks.

Patch

diff -r 312b861924c8 -r d10efbadb064 mercurial/util.py
--- a/mercurial/util.py	Mon Jan 30 22:50:20 2017 +0900
+++ b/mercurial/util.py	Mon Jan 30 22:58:56 2017 -0800
@@ -550,7 +550,7 @@ 
         except ValueError:
             pass
     def keys(self):
-        return self._list
+        return self._list[:]
     def iterkeys(self):
         return self._list.__iter__()
     def iteritems(self):