changeset 50433:bcf54837241d

bundle: prevent implicite bundling of internal changeset Now that the two mains source of on-disk bundle are preventing the inclusion of internal changesets in their bundling. We can add a lower level check that would prevent any other leakage of internal-phase changesets. We keep the door open to some usage, like the temporary bundle using during strip for example.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 08 Mar 2023 11:01:11 +0100
parents cc712ce3361f
children 95acba2c29f6
files mercurial/bundle2.py mercurial/repair.py
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Fri Mar 10 07:19:25 2023 +0100
+++ b/mercurial/bundle2.py	Wed Mar 08 11:01:11 2023 +0100
@@ -1703,6 +1703,7 @@
     vfs=None,
     compression=None,
     compopts=None,
+    allow_internal=False,
 ):
     if bundletype.startswith(b'HG10'):
         cg = changegroup.makechangegroup(repo, outgoing, b'01', source)
@@ -1718,6 +1719,14 @@
     elif not bundletype.startswith(b'HG20'):
         raise error.ProgrammingError(b'unknown bundle type: %s' % bundletype)
 
+    # enforce that no internal phase are to be bundled
+    bundled_internal = repo.revs(b"%ln and _internal()", outgoing.ancestorsof)
+    if bundled_internal and not allow_internal:
+        count = len(repo.revs(b'%ln and _internal()', outgoing.missing))
+        msg = "backup bundle would contains %d internal changesets"
+        msg %= count
+        raise error.ProgrammingError(msg)
+
     caps = {}
     if opts.get(b'obsolescence', False):
         caps[b'obsmarkers'] = (b'V1',)
--- a/mercurial/repair.py	Fri Mar 10 07:19:25 2023 +0100
+++ b/mercurial/repair.py	Wed Mar 08 11:01:11 2023 +0100
@@ -36,7 +36,14 @@
 
 
 def backupbundle(
-    repo, bases, heads, node, suffix, compress=True, obsolescence=True
+    repo,
+    bases,
+    heads,
+    node,
+    suffix,
+    compress=True,
+    obsolescence=True,
+    tmp_backup=False,
 ):
     """create a bundle with the specified revisions as a backup"""
 
@@ -83,6 +90,7 @@
         contentopts,
         vfs,
         compression=comp,
+        allow_internal=tmp_backup,
     )
 
 
@@ -199,6 +207,7 @@
             b'temp',
             compress=False,
             obsolescence=False,
+            tmp_backup=True,
         )
 
     with ui.uninterruptible():