Mercurial > evolve
comparison hgext/obsolete.py @ 52:62bdc2567099
Rollback support
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Thu, 08 Sep 2011 17:32:51 +0200 |
parents | d98e06ab8320 |
children | 0bcbf690dfca |
comparison
equal
deleted
inserted
replaced
51:d98e06ab8320 | 52:62bdc2567099 |
---|---|
3 # Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org> | 3 # Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
4 # Logilab SA <contact@logilab.fr> | 4 # Logilab SA <contact@logilab.fr> |
5 # | 5 # |
6 # This software may be used and distributed according to the terms of the | 6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
8 import os | |
8 | 9 |
9 from mercurial import util | 10 from mercurial import util |
10 from mercurial import context | 11 from mercurial import context |
11 from mercurial import revset | 12 from mercurial import revset |
12 from mercurial import scmutil | 13 from mercurial import scmutil |
13 from mercurial import extensions | 14 from mercurial import extensions |
14 from mercurial import pushkey | 15 from mercurial import pushkey |
15 from mercurial import discovery | 16 from mercurial import discovery |
16 from mercurial import error | 17 from mercurial import error |
17 from mercurial.node import hex, bin | 18 from mercurial.node import hex, bin |
19 from mercurial.lock import release | |
18 | 20 |
19 # Patch changectx | 21 # Patch changectx |
20 ############################# | 22 ############################# |
21 | 23 |
22 def obsolete(ctx): | 24 def obsolete(ctx): |
117 if not repo.local(): | 119 if not repo.local(): |
118 return | 120 return |
119 | 121 |
120 opull = repo.pull | 122 opull = repo.pull |
121 opush = repo.push | 123 opush = repo.push |
124 orollback = repo.rollback | |
125 o_writejournal = repo._writejournal | |
122 | 126 |
123 class obsoletingrepo(repo.__class__): | 127 class obsoletingrepo(repo.__class__): |
124 | 128 |
125 | 129 |
126 ### Hidden revision support | 130 ### Hidden revision support |
220 self.changelog.hiddenrevs.add(repo[obj].rev()) | 224 self.changelog.hiddenrevs.add(repo[obj].rev()) |
221 except error.RepoLookupError: | 225 except error.RepoLookupError: |
222 pass #unknow revision (but keep propagating the data | 226 pass #unknow revision (but keep propagating the data |
223 self._writeobsrels() | 227 self._writeobsrels() |
224 | 228 |
229 ### rollback support | |
230 | |
231 def _writejournal(self, desc): | |
232 entries = list(o_writejournal(desc)) | |
233 filename = 'obsolete-relations' | |
234 filepath = self.join(filename) | |
235 if os.path.exists(filepath): | |
236 journalname = 'journal.' + filename | |
237 journalpath = self.join(journalname) | |
238 util.copyfile(filepath, journalpath) | |
239 entries.append(journalpath) | |
240 return tuple(entries) | |
241 | |
242 def rollback(self, dryrun=False): | |
243 wlock = lock = None | |
244 try: | |
245 wlock = self.wlock() | |
246 lock = self.lock() | |
247 ret = orollback(dryrun) | |
248 if not (ret or dryrun): #rollback did not failed | |
249 src = self.join('undo.obsolete-relations') | |
250 dst = self.join('obsolete-relations') | |
251 if os.path.exists(src): | |
252 util.rename(src, dst) | |
253 elif os.path.exists(dst): #unlink in any case | |
254 os.unlink(dst) | |
255 # invalidate cache | |
256 self.__dict__.pop('_obssubrels', None) | |
257 self.__dict__.pop('_obsobjrels', None) | |
258 return ret | |
259 finally: | |
260 release(lock, wlock) | |
261 | |
225 repo.__class__ = obsoletingrepo | 262 repo.__class__ = obsoletingrepo |
226 | 263 |
227 | 264 |
228 ### Other Extension compat | 265 ### Other Extension compat |
229 ############################ | 266 ############################ |