82 def __init__(self, repo, name, filetype=None): |
82 def __init__(self, repo, name, filetype=None): |
83 self.repo = repo |
83 self.repo = repo |
84 self.name = name |
84 self.name = name |
85 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
85 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
86 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
86 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
87 self.ui = self.repo.ui |
|
88 if filetype: |
87 if filetype: |
89 self.fname = name + b'.' + filetype |
88 self.fname = name + b'.' + filetype |
90 else: |
89 else: |
91 self.fname = name |
90 self.fname = name |
92 |
91 |
141 shelvectx = self.repo[shelverev] |
140 shelvectx = self.repo[shelverev] |
142 return shelvectx |
141 return shelvectx |
143 finally: |
142 finally: |
144 fp.close() |
143 fp.close() |
145 |
144 |
|
145 |
|
146 class Shelf(object): |
|
147 """Represents a shelf, including possibly multiple files storing it. |
|
148 |
|
149 Old shelves will have a .patch and a .hg file. Newer shelves will |
|
150 also have a .shelve file. This class abstracts away some of the |
|
151 differences and lets you work with the shelf as a whole. |
|
152 """ |
|
153 |
|
154 def __init__(self, repo, name): |
|
155 self.repo = repo |
|
156 self.name = name |
|
157 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
|
158 |
|
159 def exists(self): |
|
160 return self.vfs.exists(self.name + b'.' + patchextension) |
|
161 |
|
162 def writeinfo(self, info): |
|
163 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) |
|
164 |
|
165 def readinfo(self): |
|
166 return scmutil.simplekeyvaluefile( |
|
167 self.vfs, self.name + b'.shelve' |
|
168 ).read() |
|
169 |
146 def writebundle(self, bases, node): |
170 def writebundle(self, bases, node): |
147 cgversion = changegroup.safeversion(self.repo) |
171 cgversion = changegroup.safeversion(self.repo) |
148 if cgversion == b'01': |
172 if cgversion == b'01': |
149 btype = b'HG10BZ' |
173 btype = b'HG10BZ' |
150 compression = None |
174 compression = None |
157 outgoing = discovery.outgoing( |
181 outgoing = discovery.outgoing( |
158 repo, missingroots=bases, ancestorsof=[node] |
182 repo, missingroots=bases, ancestorsof=[node] |
159 ) |
183 ) |
160 cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve') |
184 cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve') |
161 |
185 |
|
186 bundle_filename = self.vfs.join(self.name + b'.hg') |
162 bundle2.writebundle( |
187 bundle2.writebundle( |
163 self.ui, cg, self.fname, btype, self.vfs, compression=compression |
188 self.repo.ui, |
164 ) |
189 cg, |
165 |
190 bundle_filename, |
166 |
191 btype, |
167 class Shelf(object): |
192 self.vfs, |
168 """Represents a shelf, including possibly multiple files storing it. |
193 compression=compression, |
169 |
194 ) |
170 Old shelves will have a .patch and a .hg file. Newer shelves will |
|
171 also have a .shelve file. This class abstracts away some of the |
|
172 differences and lets you work with the shelf as a whole. |
|
173 """ |
|
174 |
|
175 def __init__(self, repo, name): |
|
176 self.repo = repo |
|
177 self.name = name |
|
178 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
|
179 |
|
180 def exists(self): |
|
181 return self.vfs.exists(self.name + b'.' + patchextension) |
|
182 |
|
183 def writeinfo(self, info): |
|
184 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info) |
|
185 |
|
186 def readinfo(self): |
|
187 return scmutil.simplekeyvaluefile( |
|
188 self.vfs, self.name + b'.shelve' |
|
189 ).read() |
|
190 |
195 |
191 |
196 |
192 class shelvedstate(object): |
197 class shelvedstate(object): |
193 """Handle persistence during unshelving operations. |
198 """Handle persistence during unshelving operations. |
194 |
199 |
473 |
478 |
474 def _shelvecreatedcommit(repo, node, name, match): |
479 def _shelvecreatedcommit(repo, node, name, match): |
475 info = {b'node': hex(node)} |
480 info = {b'node': hex(node)} |
476 Shelf(repo, name).writeinfo(info) |
481 Shelf(repo, name).writeinfo(info) |
477 bases = list(mutableancestors(repo[node])) |
482 bases = list(mutableancestors(repo[node])) |
478 shelvedfile(repo, name, b'hg').writebundle(bases, node) |
483 Shelf(repo, name).writebundle(bases, node) |
479 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp: |
484 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp: |
480 cmdutil.exportfile( |
485 cmdutil.exportfile( |
481 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match |
486 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match |
482 ) |
487 ) |
483 |
488 |