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

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Sat Oct 5 09:52:47 EDT 2019


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

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 at 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)



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


More information about the Mercurial-devel mailing list