Mercurial > hg
comparison mercurial/shelve.py @ 46280:7e300d297547
shelve: move method for getting stat (mtime) to new shelf class
Only the mtime was needed, so I made it restricted to that in the
move.
The new `Shelf` class expects its argument to be a shelf name (not a
arbitrary filename like `shelvedfile` would accept), so only the
shelf name is now passed in.
Differential Revision: https://phab.mercurial-scm.org/D9707
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 07 Jan 2021 14:54:56 -0800 |
parents | 14ce2eb6e8a4 |
children | a34607b6d320 |
comparison
equal
deleted
inserted
replaced
46279:14ce2eb6e8a4 | 46280:7e300d297547 |
---|---|
108 def movetobackup(self): | 108 def movetobackup(self): |
109 if not self.backupvfs.isdir(): | 109 if not self.backupvfs.isdir(): |
110 self.backupvfs.makedir() | 110 self.backupvfs.makedir() |
111 util.rename(self.filename(), self.backupfilename()) | 111 util.rename(self.filename(), self.backupfilename()) |
112 | 112 |
113 def stat(self): | |
114 return self.vfs.stat(self.fname) | |
115 | |
116 | 113 |
117 class Shelf(object): | 114 class Shelf(object): |
118 """Represents a shelf, including possibly multiple files storing it. | 115 """Represents a shelf, including possibly multiple files storing it. |
119 | 116 |
120 Old shelves will have a .patch and a .hg file. Newer shelves will | 117 Old shelves will have a .patch and a .hg file. Newer shelves will |
127 self.name = name | 124 self.name = name |
128 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) | 125 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
129 | 126 |
130 def exists(self): | 127 def exists(self): |
131 return self.vfs.exists(self.name + b'.' + patchextension) | 128 return self.vfs.exists(self.name + b'.' + patchextension) |
129 | |
130 def mtime(self): | |
131 return self.vfs.stat(self.name + b'.' + patchextension)[stat.ST_MTIME] | |
132 | 132 |
133 def writeinfo(self, info): | 133 def writeinfo(self, info): |
134 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) | 134 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) |
135 | 135 |
136 def readinfo(self): | 136 def readinfo(self): |
640 info = [] | 640 info = [] |
641 for (name, _type) in names: | 641 for (name, _type) in names: |
642 pfx, sfx = name.rsplit(b'.', 1) | 642 pfx, sfx = name.rsplit(b'.', 1) |
643 if not pfx or sfx != patchextension: | 643 if not pfx or sfx != patchextension: |
644 continue | 644 continue |
645 st = shelvedfile(repo, name).stat() | 645 mtime = Shelf(repo, pfx).mtime() |
646 info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename())) | 646 info.append((mtime, shelvedfile(repo, pfx).filename())) |
647 return sorted(info, reverse=True) | 647 return sorted(info, reverse=True) |
648 | 648 |
649 | 649 |
650 def listcmd(ui, repo, pats, opts): | 650 def listcmd(ui, repo, pats, opts): |
651 """subcommand that displays the list of shelves""" | 651 """subcommand that displays the list of shelves""" |