Patchwork [03,of,10,shelve-ext,v2] shelve: move node-pruning functionality to be member of shelvedstate

login
register
mail settings
Submitter Kostia Balytskyi
Date Jan. 19, 2017, 3:10 p.m.
Message ID <249273f6db8bf0fdfbbf.1484838630@devvm1416.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18252/
State Deferred
Headers show

Comments

Kostia Balytskyi - Jan. 19, 2017, 3:10 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1484740179 28800
#      Wed Jan 18 03:49:39 2017 -0800
# Node ID 249273f6db8bf0fdfbbf36bcbd9e3553e5715212
# Parent  155f97b77a4866075fa709daa3bef6dac9108e81
shelve: move node-pruning functionality to be member of shelvedstate

Node-pruning can be node stripping or marker creation, depending on
whether shelve is traditional or obs-based. Thus it makes sense to
move it to a separate function. Also, since we already have
shelvedstate object and this functionality operates on that object,
it makes sense to make it a method.

Having shelvedstate object contain repo and ui as members allows for
calling 'state.prunenodes()' instead of 'state.prunenodes(repo, ui)'
which is better IMO.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -173,8 +173,12 @@  class shelvedstate(object):
     _keep = 'keep'
     _nokeep = 'nokeep'
 
+    def __init__(self, ui, repo):
+        self.ui = ui
+        self.repo = repo
+
     @classmethod
-    def load(cls, repo):
+    def load(cls, ui, repo):
         fp = repo.vfs(cls._filename)
         try:
             version = int(fp.readline().strip())
@@ -195,7 +199,7 @@  class shelvedstate(object):
             fp.close()
 
         try:
-            obj = cls()
+            obj = cls(ui, repo)
             obj.name = name
             obj.wctx = repo[wctx]
             obj.pendingctx = repo[pendingctx]
@@ -228,6 +232,11 @@  class shelvedstate(object):
     def clear(cls, repo):
         util.unlinkpath(repo.join(cls._filename), ignoremissing=True)
 
+    def prunenodes(self):
+        """Cleanup temporary nodes from the repo"""
+        repair.strip(self.ui, self.repo, self.nodestoprune, backup=False,
+                     topic='shelve')
+
 def cleanupoldbackups(repo):
     vfs = scmutil.vfs(repo.join(backupdir))
     maxbackups = repo.ui.configint('shelve', 'maxbackups', 10)
@@ -570,8 +579,7 @@  def unshelveabort(ui, repo, state, opts)
                 raise
 
             mergefiles(ui, repo, state.wctx, state.pendingctx)
-            repair.strip(ui, repo, state.nodestoprune, backup=False,
-                         topic='shelve')
+            state.prunenodes()
         finally:
             shelvedstate.clear(repo)
             ui.warn(_("unshelve of '%s' aborted\n") % state.name)
@@ -648,7 +656,7 @@  def unshelvecontinue(ui, repo, state, op
         mergefiles(ui, repo, state.wctx, shelvectx)
         restorebranch(ui, repo, state.branchtorestore)
 
-        repair.strip(ui, repo, state.nodestoprune, backup=False, topic='shelve')
+        state.prunenodes()
         shelvedstate.clear(repo)
         unshelvecleanup(ui, repo, state.name, opts)
         ui.status(_("unshelve of '%s' complete\n") % state.name)
@@ -804,7 +812,7 @@  def _dounshelve(ui, repo, *shelved, **op
             ui.warn(_('tool option will be ignored\n'))
 
         try:
-            state = shelvedstate.load(repo)
+            state = shelvedstate.load(ui, repo)
             if opts.get('keep') is None:
                 opts['keep'] = state.keep
         except IOError as err: