Patchwork D9704: shelve: move method for reading .hg to new shelf class

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2021, 8:37 p.m.
Message ID <differential-rev-PHID-DREV-bvufe77ft262stlafl4v-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48015/
State Superseded
Headers show

Comments

phabricator - Jan. 8, 2021, 8:37 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -80,7 +80,6 @@ 
     the vfs layer"""
 
     def __init__(self, repo, name, filetype=None):
-        self.repo = repo
         self.name = name
         self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
         self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
@@ -118,30 +117,6 @@ 
     def opener(self, mode=b'rb'):
         return self.vfs(self.fname, mode)
 
-    def applybundle(self, tr):
-        fp = self.opener()
-        try:
-            targetphase = phases.internal
-            if not phases.supportinternal(self.repo):
-                targetphase = phases.secret
-            gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
-            pretip = self.repo[b'tip']
-            bundle2.applybundle(
-                self.repo,
-                gen,
-                tr,
-                source=b'unshelve',
-                url=b'bundle:' + self.vfs.join(self.fname),
-                targetphase=targetphase,
-            )
-            shelvectx = self.repo[b'tip']
-            if pretip == shelvectx:
-                shelverev = tr.changes[b'revduplicates'][-1]
-                shelvectx = self.repo[shelverev]
-            return shelvectx
-        finally:
-            fp.close()
-
 
 class Shelf(object):
     """Represents a shelf, including possibly multiple files storing it.
@@ -193,6 +168,31 @@ 
             compression=compression,
         )
 
+    def applybundle(self, tr):
+        filename = self.name + b'.hg'
+        fp = self.vfs(filename)
+        try:
+            targetphase = phases.internal
+            if not phases.supportinternal(self.repo):
+                targetphase = phases.secret
+            gen = exchange.readbundle(self.repo.ui, fp, filename, self.vfs)
+            pretip = self.repo[b'tip']
+            bundle2.applybundle(
+                self.repo,
+                gen,
+                tr,
+                source=b'unshelve',
+                url=b'bundle:' + self.vfs.join(filename),
+                targetphase=targetphase,
+            )
+            shelvectx = self.repo[b'tip']
+            if pretip == shelvectx:
+                shelverev = tr.changes[b'revduplicates'][-1]
+                shelvectx = self.repo[shelverev]
+            return shelvectx
+        finally:
+            fp.close()
+
 
 class shelvedstate(object):
     """Handle persistence during unshelving operations.
@@ -904,7 +904,7 @@ 
         node = Shelf(repo, basename).readinfo()[b'node']
     if node is None or node not in repo:
         with ui.configoverride({(b'ui', b'quiet'): True}):
-            shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr)
+            shelvectx = Shelf(repo, basename).applybundle(tr)
         # We might not strip the unbundled changeset, so we should keep track of
         # the unshelve node in case we need to reuse it (eg: unshelve --keep)
         if node is None: