Patchwork D9703: shelve: move method for writing bundle to new shelf class

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2021, 8:37 p.m.
Message ID <differential-rev-PHID-DREV-2h7nd4uqgmtesijyifma-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48014/
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/D9703

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
@@ -84,7 +84,6 @@ 
         self.name = name
         self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
         self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
-        self.ui = self.repo.ui
         if filetype:
             self.fname = name + b'.' + filetype
         else:
@@ -143,26 +142,6 @@ 
         finally:
             fp.close()
 
-    def writebundle(self, bases, node):
-        cgversion = changegroup.safeversion(self.repo)
-        if cgversion == b'01':
-            btype = b'HG10BZ'
-            compression = None
-        else:
-            btype = b'HG20'
-            compression = b'BZ'
-
-        repo = self.repo.unfiltered()
-
-        outgoing = discovery.outgoing(
-            repo, missingroots=bases, ancestorsof=[node]
-        )
-        cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve')
-
-        bundle2.writebundle(
-            self.ui, cg, self.fname, btype, self.vfs, compression=compression
-        )
-
 
 class Shelf(object):
     """Represents a shelf, including possibly multiple files storing it.
@@ -188,6 +167,32 @@ 
             self.vfs, self.name + b'.shelve'
         ).read()
 
+    def writebundle(self, bases, node):
+        cgversion = changegroup.safeversion(self.repo)
+        if cgversion == b'01':
+            btype = b'HG10BZ'
+            compression = None
+        else:
+            btype = b'HG20'
+            compression = b'BZ'
+
+        repo = self.repo.unfiltered()
+
+        outgoing = discovery.outgoing(
+            repo, missingroots=bases, ancestorsof=[node]
+        )
+        cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve')
+
+        bundle_filename = self.vfs.join(self.name + b'.hg')
+        bundle2.writebundle(
+            self.repo.ui,
+            cg,
+            bundle_filename,
+            btype,
+            self.vfs,
+            compression=compression,
+        )
+
 
 class shelvedstate(object):
     """Handle persistence during unshelving operations.
@@ -475,7 +480,7 @@ 
     info = {b'node': hex(node)}
     Shelf(repo, name).writeinfo(info)
     bases = list(mutableancestors(repo[node]))
-    shelvedfile(repo, name, b'hg').writebundle(bases, node)
+    Shelf(repo, name).writebundle(bases, node)
     with shelvedfile(repo, name, patchextension).opener(b'wb') as fp:
         cmdutil.exportfile(
             repo, [node], fp, opts=mdiff.diffopts(git=True), match=match