Patchwork D6966: shelve: add method for storing mergestate in changeset extras

login
register
mail settings
Submitter phabricator
Date Oct. 5, 2019, 1:52 p.m.
Message ID <16d093ab2bc779ae85d841ee0ab0be3a@localhost.localdomain>
Download mbox | patch
Permalink /patch/41967/
State Not Applicable
Headers show

Comments

phabricator - Oct. 5, 2019, 1:52 p.m.
navaneeth.suresh edited the summary of this revision.
navaneeth.suresh updated this revision to Diff 16813.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6966?vs=16806&id=16813

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6966/new/

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: martinvonz, mercurial-devel

Patch

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -26,6 +26,7 @@ 
 import errno
 import itertools
 import stat
+import struct
 
 from .i18n import _
 from . import (
@@ -56,6 +57,8 @@ 
     stringutil,
 )
 
+_pack = struct.pack
+
 backupdir = 'shelve-backup'
 shelvedir = 'shelved'
 shelvefileextensions = ['hg', 'patch', 'shelve']
@@ -66,6 +69,12 @@ 
 # generic user for all shelve operations
 shelveuser = 'shelve@localhost'
 
+# Merge state record types. See ``mergestate`` docs for more.
+RECORD_LOCAL = b'L'
+RECORD_OTHER = b'O'
+RECORD_MERGED = b'F'
+RECORD_OVERRIDE = b't'
+
 class shelvedfile(object):
     """Helper for the file storing a single shelve
 
@@ -413,6 +422,22 @@ 
         cmdutil.exportfile(repo, [node], fp, opts=mdiff.diffopts(git=True),
                            match=match)
 
+def _storeunresolvedmerge(ui, repo, name=None, extra=None):
+    """Store the mergestate information in changeset extra
+    for later restoration.
+    """
+    ms = merge.mergestate.read(repo)
+    records = ms._readrecords()
+    allowlist = (RECORD_LOCAL, RECORD_OTHER, RECORD_MERGED)
+    mergedata = ''
+    for key, data in records:
+        assert len(key) == 1
+        if key not in allowlist:
+            key, data = RECORD_OVERRIDE, '%s%s' % (key, data)
+        format = r'>sI%is' % len(data)
+        mergedata = mergedata + _pack(format, key, len(data), data)
+    extra['mergerecords'] = mergedata
+
 def _includeunknownfiles(repo, pats, opts, extra):
     s = repo.status(match=scmutil.match(repo[None], pats, opts),
                     unknown=True)