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