[PATCH 07 of 10 shelve-ext] shelve: add shelve type saving and loading

Kostia Balytskyi ikostia at fb.com
Tue Nov 29 10:23:01 EST 2016


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1480425731 28800
#      Tue Nov 29 05:22:11 2016 -0800
# Node ID bcf8d603cc8b678f875ceca24dd2b14eda09bce7
# Parent  d1356cbb72cfe91a2b427098c66bc00937912d79
shelve: add shelve type saving and loading

We need shelve type to be stored in .hg/shelvedstate in order
to be able to run abort or continue action properly. If the shelve
is obsbased, those actions should create markes, if it is traditional,
the actions should strip commits.

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -197,6 +197,8 @@ class shelvedstate(object):
     _filename = 'shelvedstate'
     _keep = 'keep'
     _nokeep = 'nokeep'
+    _obsbased = 'obsbased'
+    _traditional = 'traditional'
 
     def __init__(self, ui, repo):
         self.ui = ui
@@ -218,6 +220,7 @@ class shelvedstate(object):
             nodestoprune = [nodemod.bin(h) for h in fp.readline().split()]
             branchtorestore = fp.readline().strip()
             keep = fp.readline().strip() == cls._keep
+            obsshelve = fp.readline().strip() == cls._obsbased
         except (ValueError, TypeError) as err:
             raise error.CorruptedState(str(err))
         finally:
@@ -232,6 +235,7 @@ class shelvedstate(object):
             obj.nodestoprune = nodestoprune
             obj.branchtorestore = branchtorestore
             obj.keep = keep
+            obj.obsshelve = obsshelve
         except error.RepoLookupError as err:
             raise error.CorruptedState(str(err))
 
@@ -239,7 +243,7 @@ class shelvedstate(object):
 
     @classmethod
     def save(cls, repo, name, originalwctx, pendingctx, nodestoprune,
-             branchtorestore, keep=False):
+             branchtorestore, keep=False, obsshelve=False):
         fp = repo.vfs(cls._filename, 'wb')
         fp.write('%i\n' % cls._version)
         fp.write('%s\n' % name)
@@ -251,6 +255,7 @@ class shelvedstate(object):
                  ' '.join([nodemod.hex(n) for n in nodestoprune]))
         fp.write('%s\n' % branchtorestore)
         fp.write('%s\n' % (cls._keep if keep else cls._nokeep))
+        fp.write('%s\n' % (cls._obsbased if obsshelve else cls._traditional))
         fp.close()
 
     @classmethod


More information about the Mercurial-devel mailing list