Mercurial > evolve
comparison hgext/obsolete.py @ 205:7ba30bd95a88
obsolete: fix rollback wrapper for 2.2-rc
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Mon, 23 Apr 2012 14:54:06 +0200 |
parents | 50039b9b535e |
children | 168ea7d200a0 |
comparison
equal
deleted
inserted
replaced
204:50039b9b535e | 205:7ba30bd95a88 |
---|---|
367 ocancopy = repo.cancopy | 367 ocancopy = repo.cancopy |
368 | 368 |
369 # /!\ api change in Hg 2.2 (97efd26eb9576f39590812ea9) /!\ | 369 # /!\ api change in Hg 2.2 (97efd26eb9576f39590812ea9) /!\ |
370 if util.safehasattr(repo, '_journalfiles'): # Hg 2.2 | 370 if util.safehasattr(repo, '_journalfiles'): # Hg 2.2 |
371 o_journalfiles = repo._journalfiles | 371 o_journalfiles = repo._journalfiles |
372 else: # XXX remove this bloc while breaking support to Hg 2.1 | 372 o_writejournal = repo._writejournal |
373 o_writejournal = repo._writejournal | |
374 | 373 |
375 | 374 |
376 class obsoletingrepo(repo.__class__): | 375 class obsoletingrepo(repo.__class__): |
377 | 376 |
378 ### Public method | 377 ### Public method |
541 ### rollback support | 540 ### rollback support |
542 | 541 |
543 # /!\ api change in Hg 2.2 (97efd26eb9576f39590812ea9) /!\ | 542 # /!\ api change in Hg 2.2 (97efd26eb9576f39590812ea9) /!\ |
544 if util.safehasattr(repo, '_journalfiles'): # Hg 2.2 | 543 if util.safehasattr(repo, '_journalfiles'): # Hg 2.2 |
545 def _journalfiles(self): | 544 def _journalfiles(self): |
546 return o_journalfiles() + ('journal.obsolete-relations',) | 545 return o_journalfiles() + (self.join('journal.obsolete-relations'),) |
546 | |
547 def _writejournal(self, desc): | |
548 """wrapped version of _writejournal that save obsolete data""" | |
549 o_writejournal(desc) | |
550 filename = 'obsolete-relations' | |
551 filepath = self.join(filename) | |
552 if os.path.exists(filepath): | |
553 journalname = 'journal.' + filename | |
554 journalpath = self.join(journalname) | |
555 util.copyfile(filepath, journalpath) | |
556 | |
547 else: # XXX remove this bloc while breaking support to Hg 2.1 | 557 else: # XXX remove this bloc while breaking support to Hg 2.1 |
548 def _writejournal(self, desc): | 558 def _writejournal(self, desc): |
549 """wrapped version of _writejournal that save obsolete data""" | 559 """wrapped version of _writejournal that save obsolete data""" |
550 entries = list(o_writejournal(desc)) | 560 entries = list(o_writejournal(desc)) |
551 filename = 'obsolete-relations' | 561 filename = 'obsolete-relations' |
552 filepath = self.join(filename) | 562 filepath = self.join(filename) |
553 if os.path.exists(filepath): | 563 if os.path.exists(filepath): |
555 journalpath = self.join(journalname) | 565 journalpath = self.join(journalname) |
556 util.copyfile(filepath, journalpath) | 566 util.copyfile(filepath, journalpath) |
557 entries.append(journalpath) | 567 entries.append(journalpath) |
558 return tuple(entries) | 568 return tuple(entries) |
559 | 569 |
560 def _rollback(self, dryrun=False, **kwargs): | 570 def _rollback(self, dryrun, force): |
561 """wrapped version of _rollback that restore obsolete data""" | 571 """wrapped version of _rollback that restore obsolete data""" |
562 ret = o_rollback(dryrun, **kwargs) | 572 ret = o_rollback(dryrun, force) |
563 if not (ret or dryrun): #rollback did not failed | 573 if not (ret or dryrun): #rollback did not failed |
564 src = self.join('undo.obsolete-relations') | 574 src = self.join('undo.obsolete-relations') |
565 dst = self.join('obsolete-relations') | 575 dst = self.join('obsolete-relations') |
566 if os.path.exists(src): | 576 if os.path.exists(src): |
567 util.rename(src, dst) | 577 util.rename(src, dst) |
568 elif os.path.exists(dst): #unlink in any case | 578 elif os.path.exists(dst): |
579 # If no state was saved because the file did not existed before. | |
569 os.unlink(dst) | 580 os.unlink(dst) |
570 # invalidate cache | 581 # invalidate cache |
571 self.__dict__.pop('_obssubrels', None) | 582 self.__dict__.pop('_obssubrels', None) |
572 self.__dict__.pop('_obsobjrels', None) | 583 self.__dict__.pop('_obsobjrels', None) |
573 return ret | 584 return ret |