annotate hgext/narrow/narrowrevlog.py @ 36691:1b179d151578

templater: fix position of terminator character in error message Since a template expression starts after the '{' character, the expression should be considered to end immediately before the terminator '{'.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 04 Mar 2018 07:03:50 -0500
parents 66b4ffe90676
children 6ff8bd691fb8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
1 # narrowrevlog.py - revlog storing irrelevant nodes as "ellipsis" nodes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
2 #
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
3 # Copyright 2017 Google, Inc.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
4 #
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
7
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
8 from __future__ import absolute_import
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
9
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
10 from mercurial import (
36094
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
11 error,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
12 manifest,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
13 revlog,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
14 util,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
15 )
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
16
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
17 def readtransform(self, text):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
18 return text, False
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
19
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
20 def writetransform(self, text):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
21 return text, False
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
22
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
23 def rawtransform(self, text):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
24 return False
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
25
36090
9445a3141501 narrow: move from ELLIPSIS_NODE_FLAG to revlog.REVIDX_ELLIPSIS
Augie Fackler <augie@google.com>
parents: 36083
diff changeset
26 revlog.addflagprocessor(revlog.REVIDX_ELLIPSIS,
36083
9772ef9f6c04 narrow: assume addflagprocessor will always exist on revlog module
Augie Fackler <augie@google.com>
parents: 36082
diff changeset
27 (readtransform, writetransform, rawtransform))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
28
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
29 def setup():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
30 # We just wanted to add the flag processor, which is done at module
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
31 # load time.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
32 pass
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
33
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
34 class excludeddir(manifest.treemanifest):
36093
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
35 """Stand-in for a directory that is excluded from the repository.
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
36
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
37 With narrowing active on a repository that uses treemanifests,
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
38 some of the directory revlogs will be excluded from the resulting
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
39 clone. This is a huge storage win for clients, but means we need
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
40 some sort of pseudo-manifest to surface to internals so we can
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
41 detect a merge conflict outside the narrowspec. That's what this
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
42 class is: it stands in for a directory whose node is known, but
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
43 whose contents are unknown.
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
44 """
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
45 def __init__(self, dir, node):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
46 super(excludeddir, self).__init__(dir)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
47 self._node = node
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
48 # Add an empty file, which will be included by iterators and such,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
49 # appearing as the directory itself (i.e. something like "dir/")
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
50 self._files[''] = node
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
51 self._flags[''] = 't'
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
52
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
53 # Manifests outside the narrowspec should never be modified, so avoid
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
54 # copying. This makes a noticeable difference when there are very many
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
55 # directories outside the narrowspec. Also, it makes sense for the copy to
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
56 # be of the same type as the original, which would not happen with the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
57 # super type's copy().
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
58 def copy(self):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
59 return self
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
60
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
61 class excludeddirmanifestctx(manifest.treemanifestctx):
36093
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
62 """context wrapper for excludeddir - see that docstring for rationale"""
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
63 def __init__(self, dir, node):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
64 self._dir = dir
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
65 self._node = node
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
66
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
67 def read(self):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
68 return excludeddir(self._dir, self._node)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
69
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
70 def write(self, *args):
36094
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
71 raise error.ProgrammingError(
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
72 'attempt to write manifest from excluded dir %s' % self._dir)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
73
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
74 class excludedmanifestrevlog(manifest.manifestrevlog):
36093
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
75 """Stand-in for excluded treemanifest revlogs.
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
76
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
77 When narrowing is active on a treemanifest repository, we'll have
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
78 references to directories we can't see due to the revlog being
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
79 skipped. This class exists to conform to the manifestrevlog
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
80 interface for those directories and proactively prevent writes to
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
81 outside the narrowspec.
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
82 """
ed4e68efebfe narrowrevlog: document excludeddir class and friends
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
83
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
84 def __init__(self, dir):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
85 self._dir = dir
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
86
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
87 def __len__(self):
36094
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
88 raise error.ProgrammingError(
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
89 'attempt to get length of excluded dir %s' % self._dir)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
90
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
91 def rev(self, node):
36094
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
92 raise error.ProgrammingError(
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
93 'attempt to get rev from excluded dir %s' % self._dir)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
94
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
95 def linkrev(self, node):
36094
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
96 raise error.ProgrammingError(
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
97 'attempt to get linkrev from excluded dir %s' % self._dir)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
98
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
99 def node(self, rev):
36094
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
100 raise error.ProgrammingError(
142ce66a4118 narrowrevlog: replace AssertionError with ProgrammingError
Augie Fackler <augie@google.com>
parents: 36093
diff changeset
101 'attempt to get node from excluded dir %s' % self._dir)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
102
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
103 def add(self, *args, **kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
104 # We should never write entries in dirlogs outside the narrow clone.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
105 # However, the method still gets called from writesubtree() in
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
106 # _addtree(), so we need to handle it. We should possibly make that
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
107 # avoid calling add() with a clean manifest (_dirty is always False
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
108 # in excludeddir instances).
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
109 pass
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
110
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
111 def makenarrowmanifestrevlog(mfrevlog, repo):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
112 if util.safehasattr(mfrevlog, '_narrowed'):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
113 return
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
114
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
115 class narrowmanifestrevlog(mfrevlog.__class__):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
116 # This function is called via debug{revlog,index,data}, but also during
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
117 # at least some push operations. This will be used to wrap/exclude the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
118 # child directories when using treemanifests.
36095
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 36094
diff changeset
119 def dirlog(self, d):
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 36094
diff changeset
120 if d and not d.endswith('/'):
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 36094
diff changeset
121 d = d + '/'
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 36094
diff changeset
122 if not repo.narrowmatch().visitdir(d[:-1] or '.'):
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 36094
diff changeset
123 return excludedmanifestrevlog(d)
59adb3051718 manifest: clean up dirlog() to take a d parameter to avoid shadowing dir()
Augie Fackler <augie@google.com>
parents: 36094
diff changeset
124 result = super(narrowmanifestrevlog, self).dirlog(d)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
125 makenarrowmanifestrevlog(result, repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
126 return result
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
127
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
128 mfrevlog.__class__ = narrowmanifestrevlog
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
129 mfrevlog._narrowed = True
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
130
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
131 def makenarrowmanifestlog(mfl, repo):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
132 class narrowmanifestlog(mfl.__class__):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
133 def get(self, dir, node, verify=True):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
134 if not repo.narrowmatch().visitdir(dir[:-1] or '.'):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
135 return excludeddirmanifestctx(dir, node)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
136 return super(narrowmanifestlog, self).get(dir, node, verify=verify)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
137 mfl.__class__ = narrowmanifestlog
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
138
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
139 def makenarrowfilelog(fl, narrowmatch):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
140 class narrowfilelog(fl.__class__):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
141 def renamed(self, node):
36096
48b592d986e7 narrowrevlog: add what little I can remember about rename filtering
Augie Fackler <augie@google.com>
parents: 36095
diff changeset
142 # Renames that come from outside the narrowspec are
48b592d986e7 narrowrevlog: add what little I can remember about rename filtering
Augie Fackler <augie@google.com>
parents: 36095
diff changeset
143 # problematic at least for git-diffs, because we lack the
48b592d986e7 narrowrevlog: add what little I can remember about rename filtering
Augie Fackler <augie@google.com>
parents: 36095
diff changeset
144 # base text for the rename. This logic was introduced in
48b592d986e7 narrowrevlog: add what little I can remember about rename filtering
Augie Fackler <augie@google.com>
parents: 36095
diff changeset
145 # 3cd72b1 of narrowhg (authored by martinvonz, reviewed by
48b592d986e7 narrowrevlog: add what little I can remember about rename filtering
Augie Fackler <augie@google.com>
parents: 36095
diff changeset
146 # adgar), but that revision doesn't have any additional
48b592d986e7 narrowrevlog: add what little I can remember about rename filtering
Augie Fackler <augie@google.com>
parents: 36095
diff changeset
147 # commentary on what problems we can encounter.
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
148 m = super(narrowfilelog, self).renamed(node)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
149 if m and not narrowmatch(m[0]):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
150 return None
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
151 return m
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
152
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
153 def size(self, rev):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
154 # We take advantage of the fact that remotefilelog
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
155 # lacks a node() method to just skip the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
156 # rename-checking logic when on remotefilelog. This
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
157 # might be incorrect on other non-revlog-based storage
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
158 # engines, but for now this seems to be fine.
36097
66b4ffe90676 narrowrevlog: add a TODO around remotefilelog moving to core
Augie Fackler <augie@google.com>
parents: 36096
diff changeset
159 #
66b4ffe90676 narrowrevlog: add a TODO around remotefilelog moving to core
Augie Fackler <augie@google.com>
parents: 36096
diff changeset
160 # TODO: when remotefilelog is in core, improve this to
66b4ffe90676 narrowrevlog: add a TODO around remotefilelog moving to core
Augie Fackler <augie@google.com>
parents: 36096
diff changeset
161 # explicitly look for remotefilelog instead of cheating
66b4ffe90676 narrowrevlog: add a TODO around remotefilelog moving to core
Augie Fackler <augie@google.com>
parents: 36096
diff changeset
162 # with a hasattr check.
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
163 if util.safehasattr(self, 'node'):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
164 node = self.node(rev)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
165 # Because renamed() is overridden above to
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
166 # sometimes return None even if there is metadata
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
167 # in the revlog, size can be incorrect for
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
168 # copies/renames, so we need to make sure we call
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
169 # the super class's implementation of renamed()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
170 # for the purpose of size calculation.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
171 if super(narrowfilelog, self).renamed(node):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
172 return len(self.read(node))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
173 return super(narrowfilelog, self).size(rev)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
174
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
175 def cmp(self, node, text):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
176 different = super(narrowfilelog, self).cmp(node, text)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
177 if different:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
178 # Similar to size() above, if the file was copied from
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
179 # a file outside the narrowspec, the super class's
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
180 # would have returned True because we tricked it into
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
181 # thinking that the file was not renamed.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
182 if super(narrowfilelog, self).renamed(node):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
183 t2 = self.read(node)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
184 return t2 != text
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
185 return different
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
186
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
187 fl.__class__ = narrowfilelog