Patchwork D6837: cleanup: fix leakage of dirstate._map to client code

login
register
mail settings
Submitter phabricator
Date Sept. 10, 2019, 2:02 p.m.
Message ID <differential-rev-PHID-DREV-cmcdxeojz4ua5ahaqdfc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41634/
State Superseded
Headers show

Comments

phabricator - Sept. 10, 2019, 2:02 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We already had proper accessors for most of the behavior of
  dirstate._map that callers cared about exposed in the actual dirstate
  class as public methods. Sigh.
  
  There are two remaining privacy violations in the codebase after this change:
  
  1. In the perf extension, which I suspect has to stick around because it's really testing the dirstate implementation directly
  2. In lfs, where we deal with standins and mutating status. Looking at this, I _strongly_ suspect a formal dirstate interface would allow this to work via composition instead of inheritance and monkeypatching. Fortunately, such wins are a part of my motivation for this work. I anticipate we'll come back to this in due time.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/largefiles/reposetup.py
  mercurial/debugcommands.py
  mercurial/scmutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Sept. 10, 2019, 4:23 p.m.
mharbison72 added a comment.


  > 2. In lfs, where we deal with standins and mutating status.
  
  s/lfs/largefiles/?

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers
Cc: mharbison72, mercurial-devel
phabricator - Sept. 11, 2019, 1:54 p.m.
durin42 added a comment.


  In D6837#100331 <https://phab.mercurial-scm.org/D6837#100331>, @mharbison72 wrote:
  
  >> 2. In lfs, where we deal with standins and mutating status.
  >
  > s/lfs/largefiles/?
  
  Good catch, fixed.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers
Cc: mharbison72, mercurial-devel

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -319,7 +319,7 @@ 
     def __init__(self, ui, abort, dirstate):
         self._ui = ui
         self._abort = abort
-        allfiles = '\0'.join(dirstate._map)
+        allfiles = '\0'.join(dirstate)
         self._loweredfiles = set(encoding.lower(allfiles).split('\0'))
         self._dirstate = dirstate
         # The purpose of _newfiles is so that we don't complain about
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -751,7 +751,7 @@ 
         keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename
     else:
         keyfunc = None # sort by filename
-    for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc):
+    for file_, ent in sorted(repo.dirstate.iteritems(), key=keyfunc):
         if ent[3] == -1:
             timestr = 'unset               '
         elif nodates:
diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py
+++ b/hgext/largefiles/reposetup.py
@@ -234,7 +234,7 @@ 
                     result[2] = [f for f in result[2]
                                  if f not in lfdirstate]
 
-                    lfiles = set(lfdirstate._map)
+                    lfiles = set(lfdirstate)
                     # Unknown files
                     result[4] = set(result[4]).difference(lfiles)
                     # Ignored files