##// END OF EJS Templates
convert extension: Save a few opens on the map file...
Edouard Gomez -
r4588:9855939d default
parent child Browse files
Show More
@@ -33,15 +33,18 b' class convert(object):'
33 self.source = source
33 self.source = source
34 self.dest = dest
34 self.dest = dest
35 self.ui = ui
35 self.ui = ui
36 self.mapfile = mapfile
37 self.opts = opts
36 self.opts = opts
38 self.commitcache = {}
37 self.commitcache = {}
38 self.mapfile = mapfile
39 self.mapfilefd = None
39
40
40 self.map = {}
41 self.map = {}
41 try:
42 try:
42 for l in file(self.mapfile):
43 origmapfile = open(self.mapfile, 'r')
44 for l in origmapfile:
43 sv, dv = l[:-1].split()
45 sv, dv = l[:-1].split()
44 self.map[sv] = dv
46 self.map[sv] = dv
47 origmapfile.close()
45 except IOError:
48 except IOError:
46 pass
49 pass
47
50
@@ -118,6 +121,16 b' class convert(object):'
118
121
119 return s
122 return s
120
123
124 def mapentry(self, src, dst):
125 if self.mapfilefd is None:
126 try:
127 self.mapfilefd = open(self.mapfile, "a")
128 except IOError, (errno, strerror):
129 raise util.Abort("Could not open map file %s: %s, %s\n" % (self.mapfile, errno, strerror))
130 self.map[src] = dst
131 self.mapfilefd.write("%s %s\n" % (src, dst))
132 self.mapfilefd.flush()
133
121 def copy(self, rev):
134 def copy(self, rev):
122 c = self.commitcache[rev]
135 c = self.commitcache[rev]
123 files = self.source.getchanges(rev)
136 files = self.source.getchanges(rev)
@@ -133,10 +146,11 b' class convert(object):'
133
146
134 r = [self.map[v] for v in c.parents]
147 r = [self.map[v] for v in c.parents]
135 f = [f for f, v in files]
148 f = [f for f, v in files]
136 self.map[rev] = self.dest.putcommit(f, r, c)
149 newnode = self.dest.putcommit(f, r, c)
137 file(self.mapfile, "a").write("%s %s\n" % (rev, self.map[rev]))
150 self.mapentry(rev, newnode)
138
151
139 def convert(self):
152 def convert(self):
153 try:
140 self.ui.status("scanning source...\n")
154 self.ui.status("scanning source...\n")
141 heads = self.source.getheads()
155 heads = self.source.getheads()
142 parents = self.walktree(heads)
156 parents = self.walktree(heads)
@@ -166,7 +180,13 b' class convert(object):'
166 # write another hash correspondence to override the previous
180 # write another hash correspondence to override the previous
167 # one so we don't end up with extra tag heads
181 # one so we don't end up with extra tag heads
168 if nrev:
182 if nrev:
169 file(self.mapfile, "a").write("%s %s\n" % (c, nrev))
183 self.mapentry(c, nrev)
184 finally:
185 self.cleanup()
186
187 def cleanup(self):
188 if self.mapfilefd:
189 self.mapfilefd.close()
170
190
171 def _convert(ui, src, dest=None, mapfile=None, **opts):
191 def _convert(ui, src, dest=None, mapfile=None, **opts):
172 '''Convert a foreign SCM repository to a Mercurial one.
192 '''Convert a foreign SCM repository to a Mercurial one.
General Comments 0
You need to be logged in to leave comments. Login now