hgext/narrow/narrowdirstate.py
changeset 38869 ad24b581e4d9
parent 38836 fed6fe856333
child 39960 1a7d901a0a0c
equal deleted inserted replaced
38868:0db50770f388 38869:ad24b581e4d9
     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,
    13     match as matchmod,
    14     narrowspec,
       
    15 )
    14 )
    16 
    15 
    17 def wrapdirstate(repo, dirstate):
    16 def wrapdirstate(repo, dirstate):
    18     """Add narrow spec dirstate ignore, block changes outside narrow spec."""
    17     """Add narrow spec dirstate ignore, block changes outside narrow spec."""
    19 
    18 
    25                 if f is not None and not narrowmatch(f) and f not in dirstate:
    24                 if f is not None and not narrowmatch(f) and f not in dirstate:
    26                     raise error.Abort(_("cannot track '%s' - it is outside " +
    25                     raise error.Abort(_("cannot track '%s' - it is outside " +
    27                         "the narrow clone") % f)
    26                         "the narrow clone") % f)
    28             return fn(self, *args)
    27             return fn(self, *args)
    29         return _wrapper
    28         return _wrapper
    30 
       
    31     def _narrowbackupname(backupname):
       
    32         assert 'dirstate' in backupname
       
    33         return backupname.replace('dirstate', narrowspec.FILENAME)
       
    34 
    29 
    35     class narrowdirstate(dirstate.__class__):
    30     class narrowdirstate(dirstate.__class__):
    36         def walk(self, match, subrepos, unknown, ignored, full=True,
    31         def walk(self, match, subrepos, unknown, ignored, full=True,
    37                  narrowonly=True):
    32                  narrowonly=True):
    38             if narrowonly:
    33             if narrowonly:
    75                 # Rebuilding entire dirstate, let's filter allfiles to match the
    70                 # Rebuilding entire dirstate, let's filter allfiles to match the
    76                 # narrowspec.
    71                 # narrowspec.
    77                 allfiles = [f for f in allfiles if repo.narrowmatch()(f)]
    72                 allfiles = [f for f in allfiles if repo.narrowmatch()(f)]
    78             super(narrowdirstate, self).rebuild(parent, allfiles, changedfiles)
    73             super(narrowdirstate, self).rebuild(parent, allfiles, changedfiles)
    79 
    74 
    80         def restorebackup(self, tr, backupname):
       
    81             narrowspec.restorebackup(self._opener,
       
    82                                      _narrowbackupname(backupname))
       
    83             super(narrowdirstate, self).restorebackup(tr, backupname)
       
    84 
       
    85         def savebackup(self, tr, backupname):
       
    86             super(narrowdirstate, self).savebackup(tr, backupname)
       
    87             narrowspec.savebackup(self._opener, _narrowbackupname(backupname))
       
    88 
       
    89         def clearbackup(self, tr, backupname):
       
    90             super(narrowdirstate, self).clearbackup(tr, backupname)
       
    91             narrowspec.clearbackup(self._opener, _narrowbackupname(backupname))
       
    92 
       
    93     dirstate.__class__ = narrowdirstate
    75     dirstate.__class__ = narrowdirstate
    94     return dirstate
    76     return dirstate