##// END OF EJS Templates
shelve: move method for creating backup to new shelf class...
Martin von Zweigbergk -
r47003:e79f8ae0 default
parent child Browse files
Show More
@@ -81,7 +81,6 b' class shelvedfile(object):'
81 81 def __init__(self, repo, name, filetype=None):
82 82 self.name = name
83 83 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
84 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
85 84 if filetype:
86 85 self.fname = name + b'.' + filetype
87 86 else:
@@ -90,22 +89,6 b' class shelvedfile(object):'
90 89 def exists(self):
91 90 return self.vfs.exists(self.fname)
92 91
93 def backupfilename(self):
94 def gennames(base):
95 yield base
96 base, ext = base.rsplit(b'.', 1)
97 for i in itertools.count(1):
98 yield b'%s-%d.%s' % (base, i, ext)
99
100 for n in gennames(self.fname):
101 if not self.backupvfs.exists(n):
102 return self.backupvfs.join(n)
103
104 def movetobackup(self):
105 if not self.backupvfs.isdir():
106 self.backupvfs.makedir()
107 util.rename(self.vfs.join(self.fname), self.backupfilename())
108
109 92
110 93 class Shelf(object):
111 94 """Represents a shelf, including possibly multiple files storing it.
@@ -119,6 +102,7 b' class Shelf(object):'
119 102 self.repo = repo
120 103 self.name = name
121 104 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
105 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
122 106
123 107 def exists(self):
124 108 return self.vfs.exists(self.name + b'.' + patchextension)
@@ -188,6 +172,27 b' class Shelf(object):'
188 172 def open_patch(self, mode=b'rb'):
189 173 return self.vfs(self.name + b'.patch', mode)
190 174
175 def _backupfilename(self, filename):
176 def gennames(base):
177 yield base
178 base, ext = base.rsplit(b'.', 1)
179 for i in itertools.count(1):
180 yield b'%s-%d.%s' % (base, i, ext)
181
182 for n in gennames(filename):
183 if not self.backupvfs.exists(n):
184 return self.backupvfs.join(n)
185
186 def movetobackup(self):
187 if not self.backupvfs.isdir():
188 self.backupvfs.makedir()
189 for suffix in shelvefileextensions:
190 filename = self.name + b'.' + suffix
191 if self.vfs.exists(filename):
192 util.rename(
193 self.vfs.join(filename), self._backupfilename(filename)
194 )
195
191 196
192 197 class shelvedstate(object):
193 198 """Handle persistence during unshelving operations.
@@ -602,10 +607,7 b' def cleanupcmd(ui, repo):'
602 607
603 608 with repo.wlock():
604 609 for _mtime, name in listshelves(repo):
605 for suffix in shelvefileextensions:
606 shfile = shelvedfile(repo, name, suffix)
607 if shfile.exists():
608 shfile.movetobackup()
610 Shelf(repo, name).movetobackup()
609 611 cleanupoldbackups(repo)
610 612
611 613
@@ -619,10 +621,7 b' def deletecmd(ui, repo, pats):'
619 621 raise error.InputError(
620 622 _(b"shelved change '%s' not found") % name
621 623 )
622 for suffix in shelvefileextensions:
623 shfile = shelvedfile(repo, name, suffix)
624 if shfile.exists():
625 shfile.movetobackup()
624 Shelf(repo, name).movetobackup()
626 625 cleanupoldbackups(repo)
627 626
628 627
@@ -791,10 +790,7 b' def restorebranch(ui, repo, branchtorest'
791 790 def unshelvecleanup(ui, repo, name, opts):
792 791 """remove related files after an unshelve"""
793 792 if not opts.get(b'keep'):
794 for filetype in shelvefileextensions:
795 shfile = shelvedfile(repo, name, filetype)
796 if shfile.exists():
797 shfile.movetobackup()
793 Shelf(repo, name).movetobackup()
798 794 cleanupoldbackups(repo)
799 795
800 796
General Comments 0
You need to be logged in to leave comments. Login now