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