##// END OF EJS Templates
narrow: avoid looking up dirstate again when editing dirstate...
Martin von Zweigbergk -
r39996:1a7d901a default
parent child Browse files
Show More
@@ -1,76 +1,75 b''
1 1 # narrowdirstate.py - extensions to mercurial dirstate to support narrow clones
2 2 #
3 3 # Copyright 2017 Google, Inc.
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 from mercurial.i18n import _
11 11 from mercurial import (
12 12 error,
13 13 match as matchmod,
14 14 )
15 15
16 16 def wrapdirstate(repo, dirstate):
17 17 """Add narrow spec dirstate ignore, block changes outside narrow spec."""
18 18
19 19 def _editfunc(fn):
20 20 def _wrapper(self, *args):
21 dirstate = repo.dirstate
22 21 narrowmatch = repo.narrowmatch()
23 22 for f in args:
24 if f is not None and not narrowmatch(f) and f not in dirstate:
23 if f is not None and not narrowmatch(f) and f not in self:
25 24 raise error.Abort(_("cannot track '%s' - it is outside " +
26 25 "the narrow clone") % f)
27 26 return fn(self, *args)
28 27 return _wrapper
29 28
30 29 class narrowdirstate(dirstate.__class__):
31 30 def walk(self, match, subrepos, unknown, ignored, full=True,
32 31 narrowonly=True):
33 32 if narrowonly:
34 33 # hack to not exclude explicitly-specified paths so that they
35 34 # can be warned later on e.g. dirstate.add()
36 35 em = matchmod.exact(match._root, match._cwd, match.files())
37 36 nm = matchmod.unionmatcher([repo.narrowmatch(), em])
38 37 match = matchmod.intersectmatchers(match, nm)
39 38 return super(narrowdirstate, self).walk(match, subrepos, unknown,
40 39 ignored, full)
41 40
42 41 # Prevent adding/editing/copying/deleting files that are outside the
43 42 # sparse checkout
44 43 @_editfunc
45 44 def normal(self, *args):
46 45 return super(narrowdirstate, self).normal(*args)
47 46
48 47 @_editfunc
49 48 def add(self, *args):
50 49 return super(narrowdirstate, self).add(*args)
51 50
52 51 @_editfunc
53 52 def normallookup(self, *args):
54 53 return super(narrowdirstate, self).normallookup(*args)
55 54
56 55 @_editfunc
57 56 def copy(self, *args):
58 57 return super(narrowdirstate, self).copy(*args)
59 58
60 59 @_editfunc
61 60 def remove(self, *args):
62 61 return super(narrowdirstate, self).remove(*args)
63 62
64 63 @_editfunc
65 64 def merge(self, *args):
66 65 return super(narrowdirstate, self).merge(*args)
67 66
68 67 def rebuild(self, parent, allfiles, changedfiles=None):
69 68 if changedfiles is None:
70 69 # Rebuilding entire dirstate, let's filter allfiles to match the
71 70 # narrowspec.
72 71 allfiles = [f for f in allfiles if repo.narrowmatch()(f)]
73 72 super(narrowdirstate, self).rebuild(parent, allfiles, changedfiles)
74 73
75 74 dirstate.__class__ = narrowdirstate
76 75 return dirstate
General Comments 0
You need to be logged in to leave comments. Login now