##// END OF EJS Templates
rawdata: forward the method call on `filelog` object...
marmoute -
r42946:bf1e8d2a default
parent child Browse files
Show More
@@ -1,239 +1,242 b''
1 # filelog.py - file history class for mercurial
1 # filelog.py - file history class for mercurial
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from .i18n import _
10 from .i18n import _
11 from .node import (
11 from .node import (
12 nullid,
12 nullid,
13 nullrev,
13 nullrev,
14 )
14 )
15 from . import (
15 from . import (
16 error,
16 error,
17 repository,
17 repository,
18 revlog,
18 revlog,
19 )
19 )
20 from .utils import (
20 from .utils import (
21 interfaceutil,
21 interfaceutil,
22 storageutil,
22 storageutil,
23 )
23 )
24
24
25 @interfaceutil.implementer(repository.ifilestorage)
25 @interfaceutil.implementer(repository.ifilestorage)
26 class filelog(object):
26 class filelog(object):
27 def __init__(self, opener, path):
27 def __init__(self, opener, path):
28 self._revlog = revlog.revlog(opener,
28 self._revlog = revlog.revlog(opener,
29 '/'.join(('data', path + '.i')),
29 '/'.join(('data', path + '.i')),
30 censorable=True)
30 censorable=True)
31 # Full name of the user visible file, relative to the repository root.
31 # Full name of the user visible file, relative to the repository root.
32 # Used by LFS.
32 # Used by LFS.
33 self._revlog.filename = path
33 self._revlog.filename = path
34
34
35 def __len__(self):
35 def __len__(self):
36 return len(self._revlog)
36 return len(self._revlog)
37
37
38 def __iter__(self):
38 def __iter__(self):
39 return self._revlog.__iter__()
39 return self._revlog.__iter__()
40
40
41 def hasnode(self, node):
41 def hasnode(self, node):
42 if node in (nullid, nullrev):
42 if node in (nullid, nullrev):
43 return False
43 return False
44
44
45 try:
45 try:
46 self._revlog.rev(node)
46 self._revlog.rev(node)
47 return True
47 return True
48 except (TypeError, ValueError, IndexError, error.LookupError):
48 except (TypeError, ValueError, IndexError, error.LookupError):
49 return False
49 return False
50
50
51 def revs(self, start=0, stop=None):
51 def revs(self, start=0, stop=None):
52 return self._revlog.revs(start=start, stop=stop)
52 return self._revlog.revs(start=start, stop=stop)
53
53
54 def parents(self, node):
54 def parents(self, node):
55 return self._revlog.parents(node)
55 return self._revlog.parents(node)
56
56
57 def parentrevs(self, rev):
57 def parentrevs(self, rev):
58 return self._revlog.parentrevs(rev)
58 return self._revlog.parentrevs(rev)
59
59
60 def rev(self, node):
60 def rev(self, node):
61 return self._revlog.rev(node)
61 return self._revlog.rev(node)
62
62
63 def node(self, rev):
63 def node(self, rev):
64 return self._revlog.node(rev)
64 return self._revlog.node(rev)
65
65
66 def lookup(self, node):
66 def lookup(self, node):
67 return storageutil.fileidlookup(self._revlog, node,
67 return storageutil.fileidlookup(self._revlog, node,
68 self._revlog.indexfile)
68 self._revlog.indexfile)
69
69
70 def linkrev(self, rev):
70 def linkrev(self, rev):
71 return self._revlog.linkrev(rev)
71 return self._revlog.linkrev(rev)
72
72
73 def commonancestorsheads(self, node1, node2):
73 def commonancestorsheads(self, node1, node2):
74 return self._revlog.commonancestorsheads(node1, node2)
74 return self._revlog.commonancestorsheads(node1, node2)
75
75
76 # Used by dagop.blockdescendants().
76 # Used by dagop.blockdescendants().
77 def descendants(self, revs):
77 def descendants(self, revs):
78 return self._revlog.descendants(revs)
78 return self._revlog.descendants(revs)
79
79
80 def heads(self, start=None, stop=None):
80 def heads(self, start=None, stop=None):
81 return self._revlog.heads(start, stop)
81 return self._revlog.heads(start, stop)
82
82
83 # Used by hgweb, children extension.
83 # Used by hgweb, children extension.
84 def children(self, node):
84 def children(self, node):
85 return self._revlog.children(node)
85 return self._revlog.children(node)
86
86
87 def iscensored(self, rev):
87 def iscensored(self, rev):
88 return self._revlog.iscensored(rev)
88 return self._revlog.iscensored(rev)
89
89
90 def revision(self, node, _df=None, raw=False):
90 def revision(self, node, _df=None, raw=False):
91 return self._revlog.revision(node, _df=_df, raw=raw)
91 return self._revlog.revision(node, _df=_df, raw=raw)
92
92
93 def rawdata(self, node, _df=None):
94 return self._revlog.rawdata(node, _df=_df)
95
93 def emitrevisions(self, nodes, nodesorder=None,
96 def emitrevisions(self, nodes, nodesorder=None,
94 revisiondata=False, assumehaveparentrevisions=False,
97 revisiondata=False, assumehaveparentrevisions=False,
95 deltamode=repository.CG_DELTAMODE_STD):
98 deltamode=repository.CG_DELTAMODE_STD):
96 return self._revlog.emitrevisions(
99 return self._revlog.emitrevisions(
97 nodes, nodesorder=nodesorder, revisiondata=revisiondata,
100 nodes, nodesorder=nodesorder, revisiondata=revisiondata,
98 assumehaveparentrevisions=assumehaveparentrevisions,
101 assumehaveparentrevisions=assumehaveparentrevisions,
99 deltamode=deltamode)
102 deltamode=deltamode)
100
103
101 def addrevision(self, revisiondata, transaction, linkrev, p1, p2,
104 def addrevision(self, revisiondata, transaction, linkrev, p1, p2,
102 node=None, flags=revlog.REVIDX_DEFAULT_FLAGS,
105 node=None, flags=revlog.REVIDX_DEFAULT_FLAGS,
103 cachedelta=None):
106 cachedelta=None):
104 return self._revlog.addrevision(revisiondata, transaction, linkrev,
107 return self._revlog.addrevision(revisiondata, transaction, linkrev,
105 p1, p2, node=node, flags=flags,
108 p1, p2, node=node, flags=flags,
106 cachedelta=cachedelta)
109 cachedelta=cachedelta)
107
110
108 def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None,
111 def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None,
109 maybemissingparents=False):
112 maybemissingparents=False):
110 if maybemissingparents:
113 if maybemissingparents:
111 raise error.Abort(_('revlog storage does not support missing '
114 raise error.Abort(_('revlog storage does not support missing '
112 'parents write mode'))
115 'parents write mode'))
113
116
114 return self._revlog.addgroup(deltas, linkmapper, transaction,
117 return self._revlog.addgroup(deltas, linkmapper, transaction,
115 addrevisioncb=addrevisioncb)
118 addrevisioncb=addrevisioncb)
116
119
117 def getstrippoint(self, minlink):
120 def getstrippoint(self, minlink):
118 return self._revlog.getstrippoint(minlink)
121 return self._revlog.getstrippoint(minlink)
119
122
120 def strip(self, minlink, transaction):
123 def strip(self, minlink, transaction):
121 return self._revlog.strip(minlink, transaction)
124 return self._revlog.strip(minlink, transaction)
122
125
123 def censorrevision(self, tr, node, tombstone=b''):
126 def censorrevision(self, tr, node, tombstone=b''):
124 return self._revlog.censorrevision(tr, node, tombstone=tombstone)
127 return self._revlog.censorrevision(tr, node, tombstone=tombstone)
125
128
126 def files(self):
129 def files(self):
127 return self._revlog.files()
130 return self._revlog.files()
128
131
129 def read(self, node):
132 def read(self, node):
130 return storageutil.filtermetadata(self.revision(node))
133 return storageutil.filtermetadata(self.revision(node))
131
134
132 def add(self, text, meta, transaction, link, p1=None, p2=None):
135 def add(self, text, meta, transaction, link, p1=None, p2=None):
133 if meta or text.startswith('\1\n'):
136 if meta or text.startswith('\1\n'):
134 text = storageutil.packmeta(meta, text)
137 text = storageutil.packmeta(meta, text)
135 return self.addrevision(text, transaction, link, p1, p2)
138 return self.addrevision(text, transaction, link, p1, p2)
136
139
137 def renamed(self, node):
140 def renamed(self, node):
138 return storageutil.filerevisioncopied(self, node)
141 return storageutil.filerevisioncopied(self, node)
139
142
140 def size(self, rev):
143 def size(self, rev):
141 """return the size of a given revision"""
144 """return the size of a given revision"""
142
145
143 # for revisions with renames, we have to go the slow way
146 # for revisions with renames, we have to go the slow way
144 node = self.node(rev)
147 node = self.node(rev)
145 if self.renamed(node):
148 if self.renamed(node):
146 return len(self.read(node))
149 return len(self.read(node))
147 if self.iscensored(rev):
150 if self.iscensored(rev):
148 return 0
151 return 0
149
152
150 # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
153 # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
151 return self._revlog.size(rev)
154 return self._revlog.size(rev)
152
155
153 def cmp(self, node, text):
156 def cmp(self, node, text):
154 """compare text with a given file revision
157 """compare text with a given file revision
155
158
156 returns True if text is different than what is stored.
159 returns True if text is different than what is stored.
157 """
160 """
158 return not storageutil.filedataequivalent(self, node, text)
161 return not storageutil.filedataequivalent(self, node, text)
159
162
160 def verifyintegrity(self, state):
163 def verifyintegrity(self, state):
161 return self._revlog.verifyintegrity(state)
164 return self._revlog.verifyintegrity(state)
162
165
163 def storageinfo(self, exclusivefiles=False, sharedfiles=False,
166 def storageinfo(self, exclusivefiles=False, sharedfiles=False,
164 revisionscount=False, trackedsize=False,
167 revisionscount=False, trackedsize=False,
165 storedsize=False):
168 storedsize=False):
166 return self._revlog.storageinfo(
169 return self._revlog.storageinfo(
167 exclusivefiles=exclusivefiles, sharedfiles=sharedfiles,
170 exclusivefiles=exclusivefiles, sharedfiles=sharedfiles,
168 revisionscount=revisionscount, trackedsize=trackedsize,
171 revisionscount=revisionscount, trackedsize=trackedsize,
169 storedsize=storedsize)
172 storedsize=storedsize)
170
173
171 # TODO these aren't part of the interface and aren't internal methods.
174 # TODO these aren't part of the interface and aren't internal methods.
172 # Callers should be fixed to not use them.
175 # Callers should be fixed to not use them.
173
176
174 # Used by bundlefilelog, unionfilelog.
177 # Used by bundlefilelog, unionfilelog.
175 @property
178 @property
176 def indexfile(self):
179 def indexfile(self):
177 return self._revlog.indexfile
180 return self._revlog.indexfile
178
181
179 @indexfile.setter
182 @indexfile.setter
180 def indexfile(self, value):
183 def indexfile(self, value):
181 self._revlog.indexfile = value
184 self._revlog.indexfile = value
182
185
183 # Used by repo upgrade.
186 # Used by repo upgrade.
184 def clone(self, tr, destrevlog, **kwargs):
187 def clone(self, tr, destrevlog, **kwargs):
185 if not isinstance(destrevlog, filelog):
188 if not isinstance(destrevlog, filelog):
186 raise error.ProgrammingError('expected filelog to clone()')
189 raise error.ProgrammingError('expected filelog to clone()')
187
190
188 return self._revlog.clone(tr, destrevlog._revlog, **kwargs)
191 return self._revlog.clone(tr, destrevlog._revlog, **kwargs)
189
192
190 class narrowfilelog(filelog):
193 class narrowfilelog(filelog):
191 """Filelog variation to be used with narrow stores."""
194 """Filelog variation to be used with narrow stores."""
192
195
193 def __init__(self, opener, path, narrowmatch):
196 def __init__(self, opener, path, narrowmatch):
194 super(narrowfilelog, self).__init__(opener, path)
197 super(narrowfilelog, self).__init__(opener, path)
195 self._narrowmatch = narrowmatch
198 self._narrowmatch = narrowmatch
196
199
197 def renamed(self, node):
200 def renamed(self, node):
198 res = super(narrowfilelog, self).renamed(node)
201 res = super(narrowfilelog, self).renamed(node)
199
202
200 # Renames that come from outside the narrowspec are problematic
203 # Renames that come from outside the narrowspec are problematic
201 # because we may lack the base text for the rename. This can result
204 # because we may lack the base text for the rename. This can result
202 # in code attempting to walk the ancestry or compute a diff
205 # in code attempting to walk the ancestry or compute a diff
203 # encountering a missing revision. We address this by silently
206 # encountering a missing revision. We address this by silently
204 # removing rename metadata if the source file is outside the
207 # removing rename metadata if the source file is outside the
205 # narrow spec.
208 # narrow spec.
206 #
209 #
207 # A better solution would be to see if the base revision is available,
210 # A better solution would be to see if the base revision is available,
208 # rather than assuming it isn't.
211 # rather than assuming it isn't.
209 #
212 #
210 # An even better solution would be to teach all consumers of rename
213 # An even better solution would be to teach all consumers of rename
211 # metadata that the base revision may not be available.
214 # metadata that the base revision may not be available.
212 #
215 #
213 # TODO consider better ways of doing this.
216 # TODO consider better ways of doing this.
214 if res and not self._narrowmatch(res[0]):
217 if res and not self._narrowmatch(res[0]):
215 return None
218 return None
216
219
217 return res
220 return res
218
221
219 def size(self, rev):
222 def size(self, rev):
220 # Because we have a custom renamed() that may lie, we need to call
223 # Because we have a custom renamed() that may lie, we need to call
221 # the base renamed() to report accurate results.
224 # the base renamed() to report accurate results.
222 node = self.node(rev)
225 node = self.node(rev)
223 if super(narrowfilelog, self).renamed(node):
226 if super(narrowfilelog, self).renamed(node):
224 return len(self.read(node))
227 return len(self.read(node))
225 else:
228 else:
226 return super(narrowfilelog, self).size(rev)
229 return super(narrowfilelog, self).size(rev)
227
230
228 def cmp(self, node, text):
231 def cmp(self, node, text):
229 different = super(narrowfilelog, self).cmp(node, text)
232 different = super(narrowfilelog, self).cmp(node, text)
230
233
231 # Because renamed() may lie, we may get false positives for
234 # Because renamed() may lie, we may get false positives for
232 # different content. Check for this by comparing against the original
235 # different content. Check for this by comparing against the original
233 # renamed() implementation.
236 # renamed() implementation.
234 if different:
237 if different:
235 if super(narrowfilelog, self).renamed(node):
238 if super(narrowfilelog, self).renamed(node):
236 t2 = self.read(node)
239 t2 = self.read(node)
237 return t2 != text
240 return t2 != text
238
241
239 return different
242 return different
General Comments 0
You need to be logged in to leave comments. Login now