changeset 46276:eb7b2929ae49

shelve: move method for writing bundle to new shelf class Differential Revision: https://phab.mercurial-scm.org/D9703
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Jan 2021 11:25:39 -0800
parents 157305bf859f
children ed2f2150d57c
files mercurial/shelve.py
diffstat 1 files changed, 27 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/shelve.py	Thu Jan 07 11:28:41 2021 -0800
+++ b/mercurial/shelve.py	Thu Jan 07 11:25:39 2021 -0800
@@ -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