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

login
register
mail settings
Submitter phabricator
Date Aug. 17, 2019, 8:38 p.m.
Message ID <differential-rev-PHID-DREV-hmecco3yaeef3hy5k5tb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41339/
State New
Headers show

Comments

phabricator - Aug. 17, 2019, 8:38 p.m.
navaneeth.suresh created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We store mergestate records in `.hg/merge`. This patch adds a method
  of storage in changeset extras. This will help in the exchange of
  mergestate records to other repos. Also, this can be used by
  `shelve --unresolved` to store the mergestate records.
  
  It uses the storage format supported for hg versions 3.7 or later. For the
  time being, I have omitted the storage of the content of the local version
  of unresolved files.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: mercurial-devel
phabricator - Aug. 19, 2019, 3:06 p.m.
pulkit added inline comments.

INLINE COMMENTS

> shelve.py:416
>  
> +def _encodemergerecords(records):
> +    """Encode mergestate records to store in changeset extras.

What do you think about refactoring the code to write mergestate v2 on disk and use that encoding to achieve this?

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - Aug. 20, 2019, 1:23 p.m.
navaneeth.suresh added inline comments.

INLINE COMMENTS

> pulkit wrote in shelve.py:416
> What do you think about refactoring the code to write mergestate v2 on disk and use that encoding to achieve this?

i feel like the current approach is more simpler and easy to understand.

REPOSITORY
  rHG Mercurial

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

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

To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - Sept. 12, 2019, 5:46 a.m.
pulkit added inline comments.

INLINE COMMENTS

> navaneeth.suresh wrote in shelve.py:416
> i feel like the current approach is more simpler and easy to understand.

It will be nice to use only way to encode mergestates at all the places.

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -413,6 +413,36 @@ 
         cmdutil.exportfile(repo, [node], fp, opts=mdiff.diffopts(git=True),
                            match=match)
 
+def _encodemergerecords(records):
+    """Encode mergestate records to store in changeset extras.
+    Takes list of tuples as input and returns str.
+    """
+    items = [
+        '%s\033%s' % (rtype, record)
+        for rtype, record in sorted(records)
+    ]
+    return "\n".join(items)
+
+def _decodemergerecords(data):
+    """Decode mergestate record from changeset extras to return
+    a list of tuples.
+    """
+    records = []
+    for l in data.split('\n'):
+        rtype, record = l.split('\033')
+        records.append((rtype, record))
+    return records
+
+def _storeunresolvedmerge(ui, repo, name=None, extra=None):
+    """Store the mergestate information in changeset extra
+
+    This will clear the mergestate and also stores the mergestate
+    information for later restoration.
+    """
+    ms = merge.mergestate.read(repo)
+    extra['mergerecords'] = _encodemergerecords(ms._readrecords())
+    ms.reset()
+
 def _includeunknownfiles(repo, pats, opts, extra):
     s = repo.status(match=scmutil.match(repo[None], pats, opts),
                     unknown=True)