hgext/narrow/narrowdirstate.py
changeset 40087 41fcdfe3bfeb
parent 39961 1a7d901a0a0c
child 40088 1d09ba0d2ed3
equal deleted inserted replaced
40086:aa41f1b01f31 40087:41fcdfe3bfeb
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
    10 from mercurial.i18n import _
    10 from mercurial.i18n import _
    11 from mercurial import (
    11 from mercurial import (
    12     error,
    12     error,
    13     match as matchmod,
       
    14 )
    13 )
    15 
    14 
    16 def wrapdirstate(repo, dirstate):
    15 def wrapdirstate(repo, dirstate):
    17     """Add narrow spec dirstate ignore, block changes outside narrow spec."""
    16     """Add narrow spec dirstate ignore, block changes outside narrow spec."""
    18 
    17 
    28 
    27 
    29     class narrowdirstate(dirstate.__class__):
    28     class narrowdirstate(dirstate.__class__):
    30         def walk(self, match, subrepos, unknown, ignored, full=True,
    29         def walk(self, match, subrepos, unknown, ignored, full=True,
    31                  narrowonly=True):
    30                  narrowonly=True):
    32             if narrowonly:
    31             if narrowonly:
    33                 # hack to not exclude explicitly-specified paths so that they
    32                 match = repo.narrowmatch(match, includeexact=True)
    34                 # can be warned later on e.g. dirstate.add()
       
    35                 em = matchmod.exact(match._root, match._cwd, match.files())
       
    36                 nm = matchmod.unionmatcher([repo.narrowmatch(), em])
       
    37                 match = matchmod.intersectmatchers(match, nm)
       
    38             return super(narrowdirstate, self).walk(match, subrepos, unknown,
    33             return super(narrowdirstate, self).walk(match, subrepos, unknown,
    39                                                     ignored, full)
    34                                                     ignored, full)
    40 
    35 
    41         # Prevent adding/editing/copying/deleting files that are outside the
    36         # Prevent adding/editing/copying/deleting files that are outside the
    42         # sparse checkout
    37         # sparse checkout