##// END OF EJS Templates
undo-files: move the undo cleanup code in the transaction module...
marmoute -
r51194:3d0b5760 stable
parent child Browse files
Show More
@@ -19,6 +19,7 b' from mercurial import ('
19 repair,
19 repair,
20 requirements,
20 requirements,
21 scmutil,
21 scmutil,
22 transaction,
22 util,
23 util,
23 wireprototypes,
24 wireprototypes,
24 )
25 )
@@ -293,7 +294,7 b' def handlechangegroup_widen(op, inpart):'
293 finally:
294 finally:
294 f.close()
295 f.close()
295
296
296 repair.cleanup_undo_files(repo)
297 transaction.cleanup_undo_files(repo)
297
298
298 # Remove partial backup only if there were no exceptions
299 # Remove partial backup only if there were no exceptions
299 op._widen_uninterr.__exit__(None, None, None)
300 op._widen_uninterr.__exit__(None, None, None)
@@ -7,8 +7,6 b''
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9
9
10 import errno
11
12 from .i18n import _
10 from .i18n import _
13 from .node import (
11 from .node import (
14 hex,
12 hex,
@@ -31,7 +29,6 b' from . import ('
31 )
29 )
32 from .utils import (
30 from .utils import (
33 hashutil,
31 hashutil,
34 stringutil,
35 urlutil,
32 urlutil,
36 )
33 )
37
34
@@ -114,43 +111,6 b' def _collectbrokencsets(repo, files, str'
114 return s
111 return s
115
112
116
113
117 UNDO_BACKUP = b'undo.backupfiles'
118
119
120 def cleanup_undo_files(repo):
121 """remove "undo" files used by the rollback logic
122
123 This is useful to prevent rollback running in situation were it does not
124 make sense. For example after a strip.
125 """
126 backup_entries = []
127 undo_files = []
128 vfsmap = repo.vfs_map
129 try:
130 with repo.svfs(UNDO_BACKUP) as f:
131 backup_entries = transaction.read_backup_files(repo.ui.warn, f)
132 except OSError as e:
133 if e.errno != errno.ENOENT:
134 msg = _(b'could not read %s: %s\n')
135 msg %= (repo.svfs.join(UNDO_BACKUP), stringutil.forcebytestr(e))
136 repo.ui.warn(msg)
137
138 for location, f, backup_path, c in backup_entries:
139 if location in vfsmap and backup_path:
140 undo_files.append((vfsmap[location], backup_path))
141
142 undo_files.append((repo.svfs, UNDO_BACKUP))
143 undo_files.extend(repo.undofiles())
144 for undovfs, undofile in undo_files:
145 try:
146 undovfs.unlink(undofile)
147 except OSError as e:
148 if e.errno != errno.ENOENT:
149 msg = _(b'error removing %s: %s\n')
150 msg %= (undovfs.join(undofile), stringutil.forcebytestr(e))
151 repo.ui.warn(msg)
152
153
154 def strip(ui, repo, nodelist, backup=True, topic=b'backup'):
114 def strip(ui, repo, nodelist, backup=True, topic=b'backup'):
155 # This function requires the caller to lock the repo, but it operates
115 # This function requires the caller to lock the repo, but it operates
156 # within a transaction of its own, and thus requires there to be no current
116 # within a transaction of its own, and thus requires there to be no current
@@ -299,7 +259,7 b' def strip(ui, repo, nodelist, backup=Tru'
299 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
259 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
300 repo._bookmarks.applychanges(repo, tr, bmchanges)
260 repo._bookmarks.applychanges(repo, tr, bmchanges)
301
261
302 cleanup_undo_files(repo)
262 transaction.cleanup_undo_files(repo)
303
263
304 except: # re-raises
264 except: # re-raises
305 if backupfile:
265 if backupfile:
@@ -20,10 +20,10 b' from . import ('
20 narrowspec,
20 narrowspec,
21 phases,
21 phases,
22 pycompat,
22 pycompat,
23 repair,
24 requirements as requirementsmod,
23 requirements as requirementsmod,
25 scmutil,
24 scmutil,
26 store,
25 store,
26 transaction,
27 util,
27 util,
28 )
28 )
29 from .revlogutils import (
29 from .revlogutils import (
@@ -932,4 +932,4 b' def local_copy(src_repo, dest_repo):'
932 dest_repo.store.write(tr)
932 dest_repo.store.write(tr)
933
933
934 # clean up transaction file as they do not make sense
934 # clean up transaction file as they do not make sense
935 repair.cleanup_undo_files(dest_repo)
935 transaction.cleanup_undo_files(dest_repo)
@@ -11,6 +11,7 b''
11 # This software may be used and distributed according to the terms of the
11 # This software may be used and distributed according to the terms of the
12 # GNU General Public License version 2 or any later version.
12 # GNU General Public License version 2 or any later version.
13
13
14 import errno
14 import os
15 import os
15
16
16 from .i18n import _
17 from .i18n import _
@@ -39,6 +40,43 b' def active(func):'
39 return _active
40 return _active
40
41
41
42
43 UNDO_BACKUP = b'undo.backupfiles'
44
45
46 def cleanup_undo_files(repo):
47 """remove "undo" files used by the rollback logic
48
49 This is useful to prevent rollback running in situation were it does not
50 make sense. For example after a strip.
51 """
52 backup_entries = []
53 undo_files = []
54 vfsmap = repo.vfs_map
55 try:
56 with repo.svfs(UNDO_BACKUP) as f:
57 backup_entries = read_backup_files(repo.ui.warn, f)
58 except OSError as e:
59 if e.errno != errno.ENOENT:
60 msg = _(b'could not read %s: %s\n')
61 msg %= (repo.svfs.join(UNDO_BACKUP), stringutil.forcebytestr(e))
62 repo.ui.warn(msg)
63
64 for location, f, backup_path, c in backup_entries:
65 if location in vfsmap and backup_path:
66 undo_files.append((vfsmap[location], backup_path))
67
68 undo_files.append((repo.svfs, UNDO_BACKUP))
69 undo_files.extend(repo.undofiles())
70 for undovfs, undofile in undo_files:
71 try:
72 undovfs.unlink(undofile)
73 except OSError as e:
74 if e.errno != errno.ENOENT:
75 msg = _(b'error removing %s: %s\n')
76 msg %= (undovfs.join(undofile), stringutil.forcebytestr(e))
77 repo.ui.warn(msg)
78
79
42 def _playback(
80 def _playback(
43 journal,
81 journal,
44 report,
82 report,
General Comments 0
You need to be logged in to leave comments. Login now