Patchwork [1,of,2,RFC] completion: add a debugpathcomplete command

login
register
mail settings
Submitter Kevin Bullock
Date March 14, 2013, 4:53 p.m.
Message ID <9A8A264A-B1DB-4FA8-A3A1-E5928D1B5C8C@ringworld.org>
Download mbox | patch
Permalink /patch/1127/
State Superseded
Commit 10669e24eb6c664f13110cf6012e381778c730b3
Headers show

Comments

Bryan O'Sullivan - March 14, 2013, 5:37 p.m.
On Thu, Mar 14, 2013 at 9:53 AM, Kevin Bullock <
kbullock+mercurial@ringworld.org> wrote:

> ...but I just tried to create a read-only proxy that gets you the unsorted
> map, and it's easy and functional.


Sure. But I don't want to add it. It's complex, slow, and defends us
against a problem we do not have.
Augie Fackler - March 14, 2013, 6:54 p.m.
On Mar 14, 2013, at 11:23 AM, Kevin Bullock <kbullock+mercurial@ringworld.org> wrote:

> Law of Demeter violations are something we need _less_ of in the codebase, not more. My naïve example is almost certainly not the right solution, but I still don't like pulling out a _marked private_ dict from inside an object just so that you can complete filenames faster.
> 
> Could we just add an accessor to dirstate for the unsorted map keys?

+1 - I'm reaally unhappy with adding a demeter violation here.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -45,6 +45,17 @@  def _decdirs(dirs, path):
             return
         del dirs[base]
 
+class mapproxy(object):
+    def __init__(self, target):
+        self._map = target
+    def __getitem__(self, key):
+        return self._map.get(key, ("?",))[0]
+    def __contains__(self, key):
+        return key in self._map
+    def __iter__(self):
+        for x in self._map:
+            yield x
+
 class dirstate(object):
 
     def __init__(self, opener, ui, root, validate):
@@ -72,6 +83,10 @@  class dirstate(object):
         return self._map
 
     @propertycache
+    def map(self):
+        return mapproxy(self._map)
+
+    @propertycache
     def _copymap(self):
         self._read()
         return self._copymap