Patchwork D3654: graft: start using the cmdstate class to read and write data to graftstate

login
register
mail settings
Submitter phabricator
Date May 25, 2018, 4:17 p.m.
Message ID <399f51119cb6c6e682f8f880a4a3ea01@localhost.localdomain>
Download mbox | patch
Permalink /patch/31860/
State Not Applicable
Headers show

Comments

phabricator - May 25, 2018, 4:17 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG476324a304b2: graft: start using the cmdstate class to read and write data to graftstate (authored by pulkit, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D3654?vs=8885&id=8891#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3654?vs=8885&id=8891

REVISION DETAIL
  https://phab.mercurial-scm.org/D3654

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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')),