##// END OF EJS Templates
convert: merge sources getmode() into getfile()
Patrick Mezard -
r11134:33010ff1 default
parent child Browse files
Show More
@@ -109,18 +109,16 b' class bzr_source(converter_source):'
109 109 # the file is not available anymore - was deleted
110 110 raise IOError(_('%s is not available in %s anymore') %
111 111 (name, rev))
112 mode = self._modecache[(name, rev)]
112 113 if kind == 'symlink':
113 114 target = revtree.get_symlink_target(fileid)
114 115 if target is None:
115 116 raise util.Abort(_('%s.%s symlink has no target')
116 117 % (name, rev))
117 return target
118 return target, mode
118 119 else:
119 120 sio = revtree.get_file(fileid)
120 return sio.read()
121
122 def getmode(self, name, rev):
123 return self._modecache[(name, rev)]
121 return sio.read(), mode
124 122
125 123 def getchanges(self, version):
126 124 # set up caches: modecache and revtree
@@ -77,15 +77,10 b' class converter_source(object):'
77 77 raise NotImplementedError()
78 78
79 79 def getfile(self, name, rev):
80 """Return file contents as a string. rev is the identifier returned
81 by a previous call to getchanges(). Raise IOError to indicate that
82 name was deleted in rev.
83 """
84 raise NotImplementedError()
85
86 def getmode(self, name, rev):
87 """Return file mode, eg. '', 'x', or 'l'. rev is the identifier
88 returned by a previous call to getchanges().
80 """Return a pair (data, mode) where data is the file content
81 as a string and mode one of '', 'x' or 'l'. rev is the
82 identifier returned by a previous call to getchanges(). Raise
83 IOError to indicate that name was deleted in rev.
89 84 """
90 85 raise NotImplementedError()
91 86
@@ -192,8 +187,8 b' class converter_sink(object):'
192 187 changeset. 'files' is a list of (path, version) tuples,
193 188 'copies' is a dictionary mapping destinations to sources,
194 189 'source' is the source repository, and 'revmap' is a mapfile
195 of source revisions to converted revisions. Only getfile(),
196 getmode(), and lookuprev() should be called on 'source'.
190 of source revisions to converted revisions. Only getfile() and
191 lookuprev() should be called on 'source'.
197 192
198 193 Note that the sink repository is not told to update itself to
199 194 a particular revision (or even what that revision would be)
@@ -200,7 +200,7 b' class convert_cvs(converter_source):'
200 200 self._parse()
201 201 return self.heads
202 202
203 def _getfile(self, name, rev):
203 def getfile(self, name, rev):
204 204
205 205 def chunkedread(fp, count):
206 206 # file-objects returned by socked.makefile() do not handle
@@ -216,6 +216,7 b' class convert_cvs(converter_source):'
216 216 output.write(data)
217 217 return output.getvalue()
218 218
219 self._parse()
219 220 if rev.endswith("(DEAD)"):
220 221 raise IOError
221 222
@@ -255,18 +256,8 b' class convert_cvs(converter_source):'
255 256 else:
256 257 raise util.Abort(_("unknown CVS response: %s") % line)
257 258
258 def getfile(self, file, rev):
259 self._parse()
260 data, mode = self._getfile(file, rev)
261 self.modecache[(file, rev)] = mode
262 return data
263
264 def getmode(self, file, rev):
265 return self.modecache[(file, rev)]
266
267 259 def getchanges(self, rev):
268 260 self._parse()
269 self.modecache = {}
270 261 return sorted(self.files[rev].iteritems()), {}
271 262
272 263 def getcommit(self, rev):
@@ -157,11 +157,11 b' class darcs_source(converter_source, com'
157 157 def getfile(self, name, rev):
158 158 if rev != self.lastrev:
159 159 raise util.Abort(_('internal calling inconsistency'))
160 return open(os.path.join(self.tmppath, name), 'rb').read()
161
162 def getmode(self, name, rev):
163 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
164 return (mode & 0111) and 'x' or ''
160 path = os.path.join(self.tmppath, name)
161 data = open(path, 'rb').read()
162 mode = os.lstat(path).st_mode
163 mode = (mode & 0111) and 'x' or ''
164 return data, mode
165 165
166 166 def gettags(self):
167 167 return self.tags
@@ -100,8 +100,7 b' class filemapper(object):'
100 100 #
101 101 # - Filter and rename files. This is mostly wrapped by the filemapper
102 102 # class above. We hide the original filename in the revision that is
103 # returned by getchanges to be able to find things later in getfile
104 # and getmode.
103 # returned by getchanges to be able to find things later in getfile.
105 104 #
106 105 # - Return only revisions that matter for the files we're interested in.
107 106 # This involves rewriting the parents of the original revision to
@@ -318,10 +317,9 b' class filemap_source(converter_source):'
318 317 self.convertedorder.append((rev, True, None))
319 318 self._discard(*parents)
320 319
321 # Get the real changes and do the filtering/mapping.
322 # To be able to get the files later on in getfile and getmode,
323 # we hide the original filename in the rev part of the return
324 # value.
320 # Get the real changes and do the filtering/mapping. To be
321 # able to get the files later on in getfile, we hide the
322 # original filename in the rev part of the return value.
325 323 changes, copies = self.base.getchanges(rev)
326 324 newnames = {}
327 325 files = []
@@ -345,10 +343,6 b' class filemap_source(converter_source):'
345 343 realname, realrev = rev
346 344 return self.base.getfile(realname, realrev)
347 345
348 def getmode(self, name, rev):
349 realname, realrev = rev
350 return self.base.getmode(realname, realrev)
351
352 346 def gettags(self):
353 347 return self.base.gettags()
354 348
@@ -67,10 +67,9 b' class convert_git(converter_source):'
67 67 return data
68 68
69 69 def getfile(self, name, rev):
70 return self.catfile(rev, "blob")
71
72 def getmode(self, name, rev):
73 return self.modecache[(name, rev)]
70 data = self.catfile(rev, "blob")
71 mode = self.modecache[(name, rev)]
72 return data, mode
74 73
75 74 def getchanges(self, version):
76 75 self.modecache = {}
@@ -54,7 +54,6 b' class gnuarch_source(converter_source, c'
54 54 self.changes = {}
55 55 self.parents = {}
56 56 self.tags = {}
57 self.modecache = {}
58 57 self.catlogparser = Parser()
59 58 self.locale = locale.getpreferredencoding()
60 59 self.archives = []
@@ -142,16 +141,9 b' class gnuarch_source(converter_source, c'
142 141 if not os.path.exists(os.path.join(self.tmppath, name)):
143 142 raise IOError
144 143
145 data, mode = self._getfile(name, rev)
146 self.modecache[(name, rev)] = mode
147
148 return data
149
150 def getmode(self, name, rev):
151 return self.modecache[(name, rev)]
144 return self._getfile(name, rev)
152 145
153 146 def getchanges(self, rev):
154 self.modecache = {}
155 147 self._update(rev)
156 148 changes = []
157 149 copies = {}
@@ -134,11 +134,11 b' class mercurial_sink(converter_sink):'
134 134 files = dict(files)
135 135 def getfilectx(repo, memctx, f):
136 136 v = files[f]
137 data = source.getfile(f, v)
138 e = source.getmode(f, v)
137 data, mode = source.getfile(f, v)
139 138 if f == '.hgtags':
140 139 data = self._rewritetags(source, revmap, data)
141 return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f))
140 return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
141 copies.get(f))
142 142
143 143 pl = []
144 144 for p in parents:
@@ -266,13 +266,11 b' class mercurial_source(converter_source)'
266 266
267 267 def getfile(self, name, rev):
268 268 try:
269 return self.changectx(rev)[name].data()
269 fctx = self.changectx(rev)[name]
270 return fctx.data(), fctx.flags()
270 271 except error.LookupError, err:
271 272 raise IOError(err)
272 273
273 def getmode(self, name, rev):
274 return self.changectx(rev).manifest().flags(name)
275
276 274 def getchanges(self, rev):
277 275 ctx = self.changectx(rev)
278 276 parents = self.parents(ctx)
@@ -192,18 +192,16 b' class monotone_source(converter_source, '
192 192
193 193 return (files.items(), copies)
194 194
195 def getmode(self, name, rev):
196 self.mtnloadmanifest(rev)
197 node, attr = self.files.get(name, (None, ""))
198 return attr
199
200 195 def getfile(self, name, rev):
201 196 if not self.mtnisfile(name, rev):
202 197 raise IOError() # file was deleted or renamed
203 198 try:
204 return self.mtnrun("get_file_of", name, r=rev)
199 data = self.mtnrun("get_file_of", name, r=rev)
205 200 except:
206 201 raise IOError() # file was deleted or renamed
202 self.mtnloadmanifest(rev)
203 node, attr = self.files.get(name, (None, ""))
204 return data, attr
207 205
208 206 def getcommit(self, rev):
209 207 certs = self.mtngetcerts(rev)
@@ -41,7 +41,6 b' class p4_source(converter_source):'
41 41 self.parent = {}
42 42 self.encoding = "latin_1"
43 43 self.depotname = {} # mapping from local name to depot name
44 self.modecache = {}
45 44 self.re_type = re.compile(
46 45 "([a-z]+)?(text|binary|symlink|apple|resource|unicode|utf\d+)"
47 46 "(\+\w+)?$")
@@ -183,17 +182,12 b' class p4_source(converter_source):'
183 182 if mode is None:
184 183 raise IOError(0, "bad stat")
185 184
186 self.modecache[(name, rev)] = mode
187
188 185 if keywords:
189 186 contents = keywords.sub("$\\1$", contents)
190 187 if mode == "l" and contents.endswith("\n"):
191 188 contents = contents[:-1]
192 189
193 return contents
194
195 def getmode(self, name, rev):
196 return self.modecache[(name, rev)]
190 return contents, mode
197 191
198 192 def getchanges(self, rev):
199 193 return self.files[rev], {}
@@ -371,19 +371,10 b' class svn_source(converter_source):'
371 371
372 372 return self.heads
373 373
374 def getfile(self, file, rev):
375 data, mode = self._getfile(file, rev)
376 self.modecache[(file, rev)] = mode
377 return data
378
379 def getmode(self, file, rev):
380 return self.modecache[(file, rev)]
381
382 374 def getchanges(self, rev):
383 375 if self._changescache and self._changescache[0] == rev:
384 376 return self._changescache[1]
385 377 self._changescache = None
386 self.modecache = {}
387 378 (paths, parents) = self.paths[rev]
388 379 if parents:
389 380 files, self.removed, copies = self.expandpaths(rev, paths, parents)
@@ -826,10 +817,10 b' class svn_source(converter_source):'
826 817 raise util.Abort(_('svn: branch has no revision %s') % to_revnum)
827 818 raise
828 819
829 def _getfile(self, file, rev):
820 def getfile(self, file, rev):
830 821 # TODO: ra.get_file transmits the whole file instead of diffs.
831 822 if file in self.removed:
832 raise IOError()
823 raise IOError()
833 824 mode = ''
834 825 try:
835 826 new_module, revnum = self.revsplit(rev)[1:]
@@ -1100,12 +1091,11 b' class svn_sink(converter_sink, commandli'
1100 1091 # Apply changes to working copy
1101 1092 for f, v in files:
1102 1093 try:
1103 data = source.getfile(f, v)
1094 data, mode = source.getfile(f, v)
1104 1095 except IOError:
1105 1096 self.delete.append(f)
1106 1097 else:
1107 e = source.getmode(f, v)
1108 self.putfile(f, e, data)
1098 self.putfile(f, mode, data)
1109 1099 if f in copies:
1110 1100 self.copies.append([copies[f], f])
1111 1101 files = [f[0] for f in files]
General Comments 0
You need to be logged in to leave comments. Login now