changeset 38148:476324a304b2

graft: start using the cmdstate class to read and write data to graftstate This patch replaces the logic to read and write data to graftstate file to use the state.cmdstate() class. The previous graftstate format didn't had any version number on top of that, so we have to catch the CorruptedState error and then read the graftstate in case of old state files. This will help us to implement nice additions to graft commands like `--no-commit`, `--abort`, `--stop` flags. Passing on test-graft.t shows that things are working fine. Differential Revision: https://phab.mercurial-scm.org/D3654
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 25 May 2018 01:53:30 +0530
parents 58b08f4ce5f5
children d1690a64268e
files mercurial/commands.py
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri May 25 01:25:31 2018 +0530
+++ b/mercurial/commands.py	Fri May 25 01:53:30 2018 +0530
@@ -2224,7 +2224,7 @@
             raise error.Abort(_("can't specify --continue and revisions"))
         # read in unfinished revisions
         if graftstate.exists():
-            nodes = _readgraftstate(repo)['nodes']
+            nodes = _readgraftstate(repo, graftstate)['nodes']
             revs = [repo[node].rev() for node in nodes]
         else:
             cmdutil.wrongtooltocontinue(repo, _('graft'))
@@ -2351,8 +2351,10 @@
             # report any conflicts
             if stats.unresolvedcount > 0:
                 # write out state for --continue
-                nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]]
-                repo.vfs.write('graftstate', ''.join(nodelines))
+                nodes = [repo[rev].hex() for rev in revs[pos:]]
+                statedata = {'nodes': nodes}
+                stateversion = 1
+                graftstate.save(stateversion, statedata)
                 extra = ''
                 if opts.get('user'):
                     extra += ' --user %s' % procutil.shellquote(opts['user'])
@@ -2381,10 +2383,13 @@
 
     return 0
 
-def _readgraftstate(repo):
+def _readgraftstate(repo, graftstate):
     """read the graft state file and return a dict of the data stored in it"""
-    nodes = repo.vfs.read('graftstate').splitlines()
-    return {'nodes': nodes}
+    try:
+        return graftstate.read()
+    except error.CorruptedState:
+        nodes = repo.vfs.read('graftstate').splitlines()
+        return {'nodes': nodes}
 
 @command('grep',
     [('0', 'print0', None, _('end fields with NUL')),