Mercurial > hg
comparison mercurial/shelve.py @ 46284:d7f763c8c58e
shelve: make gennames() helper generate relative backup paths
When I saw `gennames()`, I thought it was meant to take a relative
filename as argument. Maybe it was or maybe it wasn't, but it seems
simpler to pass it a relative path anyway, so that's what this patch
does. That also makes the call to backupvfs.exists() more natural (I
expect a relative path to be passed there too).
Differential Revision: https://phab.mercurial-scm.org/D9711
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Jan 2021 23:09:04 -0800 |
parents | 8db5fa212ab0 |
children | e79f8ae0901b |
comparison
equal
deleted
inserted
replaced
46283:8db5fa212ab0 | 46284:d7f763c8c58e |
---|---|
95 yield base | 95 yield base |
96 base, ext = base.rsplit(b'.', 1) | 96 base, ext = base.rsplit(b'.', 1) |
97 for i in itertools.count(1): | 97 for i in itertools.count(1): |
98 yield b'%s-%d.%s' % (base, i, ext) | 98 yield b'%s-%d.%s' % (base, i, ext) |
99 | 99 |
100 name = self.backupvfs.join(self.fname) | 100 for n in gennames(self.fname): |
101 for n in gennames(name): | |
102 if not self.backupvfs.exists(n): | 101 if not self.backupvfs.exists(n): |
103 return n | 102 return self.backupvfs.join(n) |
104 | 103 |
105 def movetobackup(self): | 104 def movetobackup(self): |
106 if not self.backupvfs.isdir(): | 105 if not self.backupvfs.isdir(): |
107 self.backupvfs.makedir() | 106 self.backupvfs.makedir() |
108 util.rename(self.vfs.join(self.fname), self.backupfilename()) | 107 util.rename(self.vfs.join(self.fname), self.backupfilename()) |