##// END OF EJS Templates
shelve: move method for creating backup to new shelf class...
Martin von Zweigbergk -
r46911:a69ab3ff default draft
parent child Browse files
Show More
@@ -81,7 +81,6 b' class shelvedfile(object):'
81 def __init__(self, repo, name, filetype=None):
81 def __init__(self, repo, name, filetype=None):
82 self.name = name
82 self.name = name
83 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
83 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
84 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
85 if filetype:
84 if filetype:
86 self.fname = name + b'.' + filetype
85 self.fname = name + b'.' + filetype
87 else:
86 else:
@@ -90,22 +89,6 b' class shelvedfile(object):'
90 def exists(self):
89 def exists(self):
91 return self.vfs.exists(self.fname)
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 class Shelf(object):
93 class Shelf(object):
111 """Represents a shelf, including possibly multiple files storing it.
94 """Represents a shelf, including possibly multiple files storing it.
@@ -119,6 +102,7 b' class Shelf(object):'
119 self.repo = repo
102 self.repo = repo
120 self.name = name
103 self.name = name
121 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
104 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
105 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
122
106
123 def exists(self):
107 def exists(self):
124 return self.vfs.exists(self.name + b'.' + patchextension)
108 return self.vfs.exists(self.name + b'.' + patchextension)
@@ -188,6 +172,27 b' class Shelf(object):'
188 def open_patch(self, mode=b'rb'):
172 def open_patch(self, mode=b'rb'):
189 return self.vfs(self.name + b'.patch', mode)
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 class shelvedstate(object):
197 class shelvedstate(object):
193 """Handle persistence during unshelving operations.
198 """Handle persistence during unshelving operations.
@@ -602,10 +607,7 b' def cleanupcmd(ui, repo):'
602
607
603 with repo.wlock():
608 with repo.wlock():
604 for _mtime, name in listshelves(repo):
609 for _mtime, name in listshelves(repo):
605 for suffix in shelvefileextensions:
610 Shelf(repo, name).movetobackup()
606 shfile = shelvedfile(repo, name, suffix)
607 if shfile.exists():
608 shfile.movetobackup()
609 cleanupoldbackups(repo)
611 cleanupoldbackups(repo)
610
612
611
613
@@ -619,10 +621,7 b' def deletecmd(ui, repo, pats):'
619 raise error.InputError(
621 raise error.InputError(
620 _(b"shelved change '%s' not found") % name
622 _(b"shelved change '%s' not found") % name
621 )
623 )
622 for suffix in shelvefileextensions:
624 Shelf(repo, name).movetobackup()
623 shfile = shelvedfile(repo, name, suffix)
624 if shfile.exists():
625 shfile.movetobackup()
626 cleanupoldbackups(repo)
625 cleanupoldbackups(repo)
627
626
628
627
@@ -791,10 +790,7 b' def restorebranch(ui, repo, branchtorest'
791 def unshelvecleanup(ui, repo, name, opts):
790 def unshelvecleanup(ui, repo, name, opts):
792 """remove related files after an unshelve"""
791 """remove related files after an unshelve"""
793 if not opts.get(b'keep'):
792 if not opts.get(b'keep'):
794 for filetype in shelvefileextensions:
793 Shelf(repo, name).movetobackup()
795 shfile = shelvedfile(repo, name, filetype)
796 if shfile.exists():
797 shfile.movetobackup()
798 cleanupoldbackups(repo)
794 cleanupoldbackups(repo)
799
795
800
796
General Comments 0
You need to be logged in to leave comments. Login now