##// END OF EJS Templates
shelve: replace repo instance in Shelf class by vfs instance...
Martin von Zweigbergk -
r46917:ba9be8f5 default draft
parent child Browse files
Show More
@@ -80,11 +80,13 b' class Shelf(object):'
80 80 differences and lets you work with the shelf as a whole.
81 81 """
82 82
83 def __init__(self, repo, name):
84 self.repo = repo
83 def __init__(self, vfs, name):
84 self.vfs = vfs
85 85 self.name = name
86 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
87 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
86
87 @staticmethod
88 def open(repo, name):
89 return Shelf(vfsmod.vfs(repo.vfs.join(shelvedir)), name)
88 90
89 91 def exists(self):
90 92 return self.vfs.exists(
@@ -105,8 +107,8 b' class Shelf(object):'
105 107 self.vfs, self.name + b'.shelve'
106 108 ).read()
107 109
108 def writebundle(self, bases, node):
109 cgversion = changegroup.safeversion(self.repo)
110 def writebundle(self, repo, bases, node):
111 cgversion = changegroup.safeversion(repo)
110 112 if cgversion == b'01':
111 113 btype = b'HG10BZ'
112 114 compression = None
@@ -114,7 +116,7 b' class Shelf(object):'
114 116 btype = b'HG20'
115 117 compression = b'BZ'
116 118
117 repo = self.repo.unfiltered()
119 repo = repo.unfiltered()
118 120
119 121 outgoing = discovery.outgoing(
120 122 repo, missingroots=bases, ancestorsof=[node]
@@ -123,7 +125,7 b' class Shelf(object):'
123 125
124 126 bundle_filename = self.vfs.join(self.name + b'.hg')
125 127 bundle2.writebundle(
126 self.repo.ui,
128 repo.ui,
127 129 cg,
128 130 bundle_filename,
129 131 btype,
@@ -131,27 +133,27 b' class Shelf(object):'
131 133 compression=compression,
132 134 )
133 135
134 def applybundle(self, tr):
136 def applybundle(self, repo, tr):
135 137 filename = self.name + b'.hg'
136 138 fp = self.vfs(filename)
137 139 try:
138 140 targetphase = phases.internal
139 if not phases.supportinternal(self.repo):
141 if not phases.supportinternal(repo):
140 142 targetphase = phases.secret
141 gen = exchange.readbundle(self.repo.ui, fp, filename, self.vfs)
142 pretip = self.repo[b'tip']
143 gen = exchange.readbundle(repo.ui, fp, filename, self.vfs)
144 pretip = repo[b'tip']
143 145 bundle2.applybundle(
144 self.repo,
146 repo,
145 147 gen,
146 148 tr,
147 149 source=b'unshelve',
148 150 url=b'bundle:' + self.vfs.join(filename),
149 151 targetphase=targetphase,
150 152 )
151 shelvectx = self.repo[b'tip']
153 shelvectx = repo[b'tip']
152 154 if pretip == shelvectx:
153 155 shelverev = tr.changes[b'revduplicates'][-1]
154 shelvectx = self.repo[shelverev]
156 shelvectx = repo[shelverev]
155 157 return shelvectx
156 158 finally:
157 159 fp.close()
@@ -159,7 +161,7 b' class Shelf(object):'
159 161 def open_patch(self, mode=b'rb'):
160 162 return self.vfs(self.name + b'.patch', mode)
161 163
162 def _backupfilename(self, filename):
164 def _backupfilename(self, backupvfs, filename):
163 165 def gennames(base):
164 166 yield base
165 167 base, ext = base.rsplit(b'.', 1)
@@ -167,17 +169,18 b' class Shelf(object):'
167 169 yield b'%s-%d.%s' % (base, i, ext)
168 170
169 171 for n in gennames(filename):
170 if not self.backupvfs.exists(n):
171 return self.backupvfs.join(n)
172 if not backupvfs.exists(n):
173 return backupvfs.join(n)
172 174
173 def movetobackup(self):
174 if not self.backupvfs.isdir():
175 self.backupvfs.makedir()
175 def movetobackup(self, backupvfs):
176 if not backupvfs.isdir():
177 backupvfs.makedir()
176 178 for suffix in shelvefileextensions:
177 179 filename = self.name + b'.' + suffix
178 180 if self.vfs.exists(filename):
179 181 util.rename(
180 self.vfs.join(filename), self._backupfilename(filename)
182 self.vfs.join(filename),
183 self._backupfilename(backupvfs, filename),
181 184 )
182 185
183 186
@@ -375,7 +378,7 b' def getshelvename(repo, parent, opts):'
375 378 label = label.replace(b'.', b'_', 1)
376 379
377 380 if name:
378 if Shelf(repo, name).exists():
381 if Shelf.open(repo, name).exists():
379 382 e = _(b"a shelved change named '%s' already exists") % name
380 383 raise error.Abort(e)
381 384
@@ -389,7 +392,7 b' def getshelvename(repo, parent, opts):'
389 392
390 393 else:
391 394 for n in gennames():
392 if not Shelf(repo, n).exists():
395 if not Shelf.open(repo, n).exists():
393 396 name = n
394 397 break
395 398
@@ -465,10 +468,10 b' def _nothingtoshelvemessaging(ui, repo, '
465 468
466 469 def _shelvecreatedcommit(repo, node, name, match):
467 470 info = {b'node': hex(node)}
468 shelf = Shelf(repo, name)
471 shelf = Shelf.open(repo, name)
469 472 shelf.writeinfo(info)
470 473 bases = list(mutableancestors(repo[node]))
471 shelf.writebundle(bases, node)
474 shelf.writebundle(repo, bases, node)
472 475 with shelf.open_patch(b'wb') as fp:
473 476 cmdutil.exportfile(
474 477 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match
@@ -594,8 +597,9 b' def cleanupcmd(ui, repo):'
594 597 """subcommand that deletes all shelves"""
595 598
596 599 with repo.wlock():
600 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
597 601 for _mtime, name in listshelves(repo):
598 Shelf(repo, name).movetobackup()
602 Shelf.open(repo, name).movetobackup(backupvfs)
599 603 cleanupoldbackups(repo)
600 604
601 605
@@ -604,13 +608,14 b' def deletecmd(ui, repo, pats):'
604 608 if not pats:
605 609 raise error.InputError(_(b'no shelved changes specified!'))
606 610 with repo.wlock():
611 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
607 612 for name in pats:
608 shelf = Shelf(repo, name)
613 shelf = Shelf.open(repo, name)
609 614 if not shelf.exists():
610 615 raise error.InputError(
611 616 _(b"shelved change '%s' not found") % name
612 617 )
613 shelf.movetobackup()
618 shelf.movetobackup(backupvfs)
614 619 cleanupoldbackups(repo)
615 620
616 621
@@ -629,7 +634,7 b' def listshelves(repo):'
629 634 if name in seen:
630 635 continue
631 636 seen.add(name)
632 shelf = Shelf(repo, name)
637 shelf = Shelf.open(repo, name)
633 638 if not shelf.exists():
634 639 continue
635 640 mtime = shelf.mtime()
@@ -660,7 +665,7 b' def listcmd(ui, repo, pats, opts):'
660 665 ui.write(age, label=b'shelve.age')
661 666 ui.write(b' ' * (12 - len(age)))
662 667 used += 12
663 with Shelf(repo, name).open_patch() as fp:
668 with Shelf.open(repo, name).open_patch() as fp:
664 669 while True:
665 670 line = fp.readline()
666 671 if not line:
@@ -693,7 +698,7 b' def patchcmds(ui, repo, pats, opts):'
693 698 pats = [name]
694 699
695 700 for shelfname in pats:
696 if not Shelf(repo, shelfname).exists():
701 if not Shelf.open(repo, shelfname).exists():
697 702 raise error.Abort(_(b"cannot find shelf %s") % shelfname)
698 703
699 704 listcmd(ui, repo, pats, opts)
@@ -784,7 +789,8 b' def restorebranch(ui, repo, branchtorest'
784 789 def unshelvecleanup(ui, repo, name, opts):
785 790 """remove related files after an unshelve"""
786 791 if not opts.get(b'keep'):
787 Shelf(repo, name).movetobackup()
792 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
793 Shelf.open(repo, name).movetobackup(backupvfs)
788 794 cleanupoldbackups(repo)
789 795
790 796
@@ -884,12 +890,12 b' def _unshelverestorecommit(ui, repo, tr,'
884 890 """Recreate commit in the repository during the unshelve"""
885 891 repo = repo.unfiltered()
886 892 node = None
887 shelf = Shelf(repo, basename)
893 shelf = Shelf.open(repo, basename)
888 894 if shelf.hasinfo():
889 895 node = shelf.readinfo()[b'node']
890 896 if node is None or node not in repo:
891 897 with ui.configoverride({(b'ui', b'quiet'): True}):
892 shelvectx = shelf.applybundle(tr)
898 shelvectx = shelf.applybundle(repo, tr)
893 899 # We might not strip the unbundled changeset, so we should keep track of
894 900 # the unshelve node in case we need to reuse it (eg: unshelve --keep)
895 901 if node is None:
@@ -1113,7 +1119,7 b' def unshelvecmd(ui, repo, *shelved, **op'
1113 1119 else:
1114 1120 basename = shelved[0]
1115 1121
1116 if not Shelf(repo, basename).exists():
1122 if not Shelf.open(repo, basename).exists():
1117 1123 raise error.InputError(_(b"shelved change '%s' not found") % basename)
1118 1124
1119 1125 return _dounshelve(ui, repo, basename, opts)
General Comments 0
You need to be logged in to leave comments. Login now