##// END OF EJS Templates
shelve: make shelvestate use simplekeyvaluefile...
Kostia Balytskyi -
r32285:fe3105e6 default
parent child Browse files
Show More
@@ -167,7 +167,7 b' class shelvedstate(object):'
167 Handles saving and restoring a shelved state. Ensures that different
167 Handles saving and restoring a shelved state. Ensures that different
168 versions of a shelved state are possible and handles them appropriately.
168 versions of a shelved state are possible and handles them appropriately.
169 """
169 """
170 _version = 1
170 _version = 2
171 _filename = 'shelvedstate'
171 _filename = 'shelvedstate'
172 _keep = 'keep'
172 _keep = 'keep'
173 _nokeep = 'nokeep'
173 _nokeep = 'nokeep'
@@ -175,26 +175,9 b' class shelvedstate(object):'
175 _noactivebook = ':no-active-bookmark'
175 _noactivebook = ':no-active-bookmark'
176
176
177 @classmethod
177 @classmethod
178 def load(cls, repo):
178 def _verifyandtransform(cls, d):
179 # Order is important, because old shelvestate file uses it
179 """Some basic shelvestate syntactic verification and transformation"""
180 # to detemine values of fields (i.g. version is on the first line,
181 # name is on the second and so forth). Please do not change.
182 keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents',
183 'nodestoremove', 'branchtorestore', 'keep', 'activebook']
184 d = {}
185 fp = repo.vfs(cls._filename)
186 try:
180 try:
187 for key in keys:
188 d[key] = fp.readline().strip()
189 finally:
190 fp.close()
191
192 # some basic syntactic verification and transformation
193 try:
194 d['version'] = int(d['version'])
195 if d['version'] != cls._version:
196 raise error.Abort(_('this version of shelve is incompatible '
197 'with the version used in this repo'))
198 d['originalwctx'] = nodemod.bin(d['originalwctx'])
181 d['originalwctx'] = nodemod.bin(d['originalwctx'])
199 d['pendingctx'] = nodemod.bin(d['pendingctx'])
182 d['pendingctx'] = nodemod.bin(d['pendingctx'])
200 d['parents'] = [nodemod.bin(h)
183 d['parents'] = [nodemod.bin(h)
@@ -204,6 +187,50 b' class shelvedstate(object):'
204 except (ValueError, TypeError, KeyError) as err:
187 except (ValueError, TypeError, KeyError) as err:
205 raise error.CorruptedState(str(err))
188 raise error.CorruptedState(str(err))
206
189
190 @classmethod
191 def _getversion(cls, repo):
192 """Read version information from shelvestate file"""
193 fp = repo.vfs(cls._filename)
194 try:
195 version = int(fp.readline().strip())
196 except ValueError as err:
197 raise error.CorruptedState(str(err))
198 finally:
199 fp.close()
200 return version
201
202 @classmethod
203 def _readold(cls, repo):
204 """Read the old position-based version of a shelvestate file"""
205 # Order is important, because old shelvestate file uses it
206 # to detemine values of fields (i.g. name is on the second line,
207 # originalwctx is on the third and so forth). Please do not change.
208 keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents',
209 'nodestoremove', 'branchtorestore', 'keep', 'activebook']
210 # this is executed only seldomly, so it is not a big deal
211 # that we open this file twice
212 fp = repo.vfs(cls._filename)
213 d = {}
214 try:
215 for key in keys:
216 d[key] = fp.readline().strip()
217 finally:
218 fp.close()
219 return d
220
221 @classmethod
222 def load(cls, repo):
223 version = cls._getversion(repo)
224 if version < cls._version:
225 d = cls._readold(repo)
226 elif version == cls._version:
227 d = scmutil.simplekeyvaluefile(repo.vfs, cls._filename)\
228 .read(firstlinenonkeyval=True)
229 else:
230 raise error.Abort(_('this version of shelve is incompatible '
231 'with the version used in this repo'))
232
233 cls._verifyandtransform(d)
207 try:
234 try:
208 obj = cls()
235 obj = cls()
209 obj.name = d['name']
236 obj.name = d['name']
@@ -224,19 +251,20 b' class shelvedstate(object):'
224 @classmethod
251 @classmethod
225 def save(cls, repo, name, originalwctx, pendingctx, nodestoremove,
252 def save(cls, repo, name, originalwctx, pendingctx, nodestoremove,
226 branchtorestore, keep=False, activebook=''):
253 branchtorestore, keep=False, activebook=''):
227 fp = repo.vfs(cls._filename, 'wb')
254 info = {
228 fp.write('%i\n' % cls._version)
255 "name": name,
229 fp.write('%s\n' % name)
256 "originalwctx": nodemod.hex(originalwctx.node()),
230 fp.write('%s\n' % nodemod.hex(originalwctx.node()))
257 "pendingctx": nodemod.hex(pendingctx.node()),
231 fp.write('%s\n' % nodemod.hex(pendingctx.node()))
258 "parents": ' '.join([nodemod.hex(p)
232 fp.write('%s\n' %
259 for p in repo.dirstate.parents()]),
233 ' '.join([nodemod.hex(p) for p in repo.dirstate.parents()]))
260 "nodestoremove": ' '.join([nodemod.hex(n)
234 fp.write('%s\n' %
261 for n in nodestoremove]),
235 ' '.join([nodemod.hex(n) for n in nodestoremove]))
262 "branchtorestore": branchtorestore,
236 fp.write('%s\n' % branchtorestore)
263 "keep": cls._keep if keep else cls._nokeep,
237 fp.write('%s\n' % (cls._keep if keep else cls._nokeep))
264 "activebook": activebook or cls._noactivebook
238 fp.write('%s\n' % (activebook or cls._noactivebook))
265 }
239 fp.close()
266 scmutil.simplekeyvaluefile(repo.vfs, cls._filename)\
267 .write(info, firstline=str(cls._version))
240
268
241 @classmethod
269 @classmethod
242 def clear(cls, repo):
270 def clear(cls, repo):
@@ -1591,9 +1591,8 b' shelve on new branch, conflict with prev'
1591 Removing restore branch information from shelvedstate file(making it looks like
1591 Removing restore branch information from shelvedstate file(making it looks like
1592 in previous versions) and running unshelve --continue
1592 in previous versions) and running unshelve --continue
1593
1593
1594 $ head -n 6 < .hg/shelvedstate > .hg/shelvedstate_oldformat
1594 $ cp .hg/shelvedstate .hg/shelvedstate_old
1595 $ rm .hg/shelvedstate
1595 $ cat .hg/shelvedstate_old | grep -v 'branchtorestore' > .hg/shelvedstate
1596 $ mv .hg/shelvedstate_oldformat .hg/shelvedstate
1597
1596
1598 $ echo "aaabbbccc" > a
1597 $ echo "aaabbbccc" > a
1599 $ rm a.orig
1598 $ rm a.orig
@@ -1737,3 +1736,48 b' Unshelving when there are deleted files '
1737 [255]
1736 [255]
1738 $ hg st
1737 $ hg st
1739 ! a
1738 ! a
1739 $ cd ..
1740
1741 New versions of Mercurial know how to read onld shelvedstate files
1742 $ hg init oldshelvedstate
1743 $ cd oldshelvedstate
1744 $ echo root > root && hg ci -Am root
1745 adding root
1746 $ echo 1 > a
1747 $ hg add a
1748 $ hg shelve --name ashelve
1749 shelved as ashelve
1750 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1751 $ echo 2 > a
1752 $ hg ci -Am a
1753 adding a
1754 $ hg unshelve
1755 unshelving change 'ashelve'
1756 rebasing shelved changes
1757 rebasing 2:003d2d94241c "changes to: root" (tip)
1758 merging a
1759 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
1760 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
1761 [1]
1762 putting v1 shelvedstate file in place of a created v2
1763 $ cat << EOF > .hg/shelvedstate
1764 > 1
1765 > ashelve
1766 > 8b058dae057a5a78f393f4535d9e363dd5efac9d
1767 > 8b058dae057a5a78f393f4535d9e363dd5efac9d
1768 > 8b058dae057a5a78f393f4535d9e363dd5efac9d 003d2d94241cc7aff0c3a148e966d6a4a377f3a7
1769 > 003d2d94241cc7aff0c3a148e966d6a4a377f3a7
1770 >
1771 > nokeep
1772 > :no-active-bookmark
1773 > EOF
1774 $ echo 1 > a
1775 $ hg resolve --mark a
1776 (no more unresolved files)
1777 continue: hg unshelve --continue
1778 mercurial does not crash
1779 $ hg unshelve --continue
1780 rebasing 2:003d2d94241c "changes to: root" (tip)
1781 unshelve of 'ashelve' complete
1782 $ cd ..
1783
General Comments 0
You need to be logged in to leave comments. Login now