204 raise NoRepo("%s is not a local Mercurial repo" % path) |
204 raise NoRepo("%s is not a local Mercurial repo" % path) |
205 self.lastrev = None |
205 self.lastrev = None |
206 self.lastctx = None |
206 self.lastctx = None |
207 self._changescache = None |
207 self._changescache = None |
208 self.convertfp = None |
208 self.convertfp = None |
|
209 # Restrict converted revisions to startrev descendants |
|
210 startnode = ui.config('convert', 'hg.startrev') |
|
211 if startnode is not None: |
|
212 try: |
|
213 startnode = self.repo.lookup(startnode) |
|
214 except repo.RepoError: |
|
215 raise util.Abort(_('%s is not a valid start revision') |
|
216 % startnode) |
|
217 startrev = self.repo.changelog.rev(startnode) |
|
218 children = {startnode: 1} |
|
219 for rev in self.repo.changelog.descendants(startrev): |
|
220 children[self.repo.changelog.node(rev)] = 1 |
|
221 self.keep = children.__contains__ |
|
222 else: |
|
223 self.keep = util.always |
209 |
224 |
210 def changectx(self, rev): |
225 def changectx(self, rev): |
211 if self.lastrev != rev: |
226 if self.lastrev != rev: |
212 self.lastctx = self.repo[rev] |
227 self.lastctx = self.repo[rev] |
213 self.lastrev = rev |
228 self.lastrev = rev |
214 return self.lastctx |
229 return self.lastctx |
215 |
230 |
|
231 def parents(self, ctx): |
|
232 return [p.node() for p in ctx.parents() |
|
233 if p and self.keep(p.node())] |
|
234 |
216 def getheads(self): |
235 def getheads(self): |
217 if self.rev: |
236 if self.rev: |
218 return [hex(self.repo[self.rev].node())] |
237 heads = [self.repo[self.rev].node()] |
219 else: |
238 else: |
220 return [hex(node) for node in self.repo.heads()] |
239 heads = self.repo.heads() |
|
240 return [hex(h) for h in heads if self.keep(h)] |
221 |
241 |
222 def getfile(self, name, rev): |
242 def getfile(self, name, rev): |
223 try: |
243 try: |
224 return self.changectx(rev)[name].data() |
244 return self.changectx(rev)[name].data() |
225 except revlog.LookupError, err: |
245 except revlog.LookupError, err: |
228 def getmode(self, name, rev): |
248 def getmode(self, name, rev): |
229 return self.changectx(rev).manifest().flags(name) |
249 return self.changectx(rev).manifest().flags(name) |
230 |
250 |
231 def getchanges(self, rev): |
251 def getchanges(self, rev): |
232 ctx = self.changectx(rev) |
252 ctx = self.changectx(rev) |
|
253 parents = self.parents(ctx) |
|
254 if not parents: |
|
255 files = util.sort(ctx.manifest().keys()) |
|
256 return [(f, rev) for f in files], {} |
233 if self._changescache and self._changescache[0] == rev: |
257 if self._changescache and self._changescache[0] == rev: |
234 m, a, r = self._changescache[1] |
258 m, a, r = self._changescache[1] |
235 else: |
259 else: |
236 m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3] |
260 m, a, r = self.repo.status(parents[0], ctx.node())[:3] |
237 changes = [(name, rev) for name in m + a + r] |
261 changes = [(name, rev) for name in m + a + r] |
238 return util.sort(changes), self.getcopies(ctx, m + a) |
262 return util.sort(changes), self.getcopies(ctx, m + a) |
239 |
263 |
240 def getcopies(self, ctx, files): |
264 def getcopies(self, ctx, files): |
241 copies = {} |
265 copies = {} |
242 for name in files: |
266 for name in files: |
243 try: |
267 try: |
244 copies[name] = ctx.filectx(name).renamed()[0] |
268 copynode = ctx.filectx(name).renamed()[0] |
|
269 if self.keep(copynode): |
|
270 copies[name] = copynode |
245 except TypeError: |
271 except TypeError: |
246 pass |
272 pass |
247 return copies |
273 return copies |
248 |
274 |
249 def getcommit(self, rev): |
275 def getcommit(self, rev): |
250 ctx = self.changectx(rev) |
276 ctx = self.changectx(rev) |
251 parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid] |
277 parents = [hex(p) for p in self.parents(ctx)] |
252 if self.saverev: |
278 if self.saverev: |
253 crev = rev |
279 crev = rev |
254 else: |
280 else: |
255 crev = None |
281 crev = None |
256 return commit(author=ctx.user(), date=util.datestr(ctx.date()), |
282 return commit(author=ctx.user(), date=util.datestr(ctx.date()), |
257 desc=ctx.description(), rev=crev, parents=parents, |
283 desc=ctx.description(), rev=crev, parents=parents, |
258 branch=ctx.branch(), extra=ctx.extra()) |
284 branch=ctx.branch(), extra=ctx.extra()) |
259 |
285 |
260 def gettags(self): |
286 def gettags(self): |
261 tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] |
287 tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] |
262 return dict([(name, hex(node)) for name, node in tags]) |
288 return dict([(name, hex(node)) for name, node in tags |
|
289 if self.keep(node)]) |
263 |
290 |
264 def getchangedfiles(self, rev, i): |
291 def getchangedfiles(self, rev, i): |
265 ctx = self.changectx(rev) |
292 ctx = self.changectx(rev) |
266 i = i or 0 |
293 parents = self.parents(ctx) |
267 changes = self.repo.status(ctx.parents()[i].node(), ctx.node())[:3] |
294 if not parents and i is None: |
|
295 i = 0 |
|
296 changes = [], ctx.manifest().keys(), [] |
|
297 else: |
|
298 i = i or 0 |
|
299 changes = self.repo.status(parents[i], ctx.node())[:3] |
268 |
300 |
269 if i == 0: |
301 if i == 0: |
270 self._changescache = (rev, changes) |
302 self._changescache = (rev, changes) |
271 |
303 |
272 return changes[0] + changes[1] + changes[2] |
304 return changes[0] + changes[1] + changes[2] |