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

login
register
mail settings
Submitter Kostia Balytskyi
Date Nov. 29, 2016, 3:22 p.m.
Message ID <4166a4cfdc14629e169f.1480432978@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17787/
State Accepted
Headers show

Comments

Kostia Balytskyi - Nov. 29, 2016, 3:22 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1480425731 28800
#      Tue Nov 29 05:22:11 2016 -0800
# Node ID 4166a4cfdc14629e169f12e83607b065887594b7
# Parent  93bb69fa1f1abbe0a42455ad8df691fdf29b2e3a
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
@@ -185,8 +185,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())
@@ -207,7 +211,7 @@  class shelvedstate(object):
             fp.close()
 
         try:
-            obj = cls()
+            obj = cls(ui, repo)
             obj.name = name
             obj.wctx = repo[wctx]
             obj.pendingctx = repo[pendingctx]
@@ -240,6 +244,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)
@@ -576,8 +585,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)
@@ -654,7 +662,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)
@@ -810,7 +818,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: