changeset 50392:385a4f8056e5

bundle: include required phases when saving a bundle (issue6794) We now properly computes and includes phases above secret in bundle, previously, they would be skipped, and then the code computing them would crash. Note that from this changeset, we also include the heads associated with the changegroup's "target" phase. This turned out to be necessary to ensure the movement of changeset included in the bundle, but already known locally. This explain why lines for "secret" heads appears in multiple tests.
author Jason R. Coombs <jaraco@jaraco.com>, Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 09 Mar 2023 01:26:04 +0100
parents c8a91b0d1077
children f95ab2c53303
files mercurial/bundle2.py mercurial/phases.py tests/test-bundle-phases.t tests/test-bundle-type.t tests/test-phase-archived.t
diffstat 5 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Wed Mar 08 17:33:33 2023 +0100
+++ b/mercurial/bundle2.py	Thu Mar 09 01:26:04 2023 +0100
@@ -1750,12 +1750,16 @@
             part.addparam(
                 b'nbchanges', b'%d' % cg.extras[b'clcount'], mandatory=False
             )
-        if opts.get(b'phases') and repo.revs(
-            b'%ln and secret()', outgoing.ancestorsof
-        ):
-            part.addparam(
-                b'targetphase', b'%d' % phases.secret, mandatory=False
-            )
+        if opts.get(b'phases'):
+            target_phase = phases.draft
+            for head in outgoing.ancestorsof:
+                target_phase = max(target_phase, repo[head].phase())
+            if target_phase > phases.draft:
+                part.addparam(
+                    b'targetphase',
+                    b'%d' % target_phase,
+                    mandatory=False,
+                )
     if repository.REPO_FEATURE_SIDE_DATA in repo.features:
         part.addparam(b'exp-sidedata', b'1')
 
--- a/mercurial/phases.py	Wed Mar 08 17:33:33 2023 +0100
+++ b/mercurial/phases.py	Thu Mar 09 01:26:04 2023 +0100
@@ -827,10 +827,8 @@
     cl = repo.changelog
 
     headsbyphase = {i: [] for i in allphases}
-    # No need to keep track of secret phase; any heads in the subset that
-    # are not mentioned are implicitly secret.
-    for phase in allphases[:secret]:
-        revset = b"heads(%%ln & %s())" % phasenames[phase]
+    for phase in allphases:
+        revset = b"heads(%%ln & _phase(%d))" % phase
         headsbyphase[phase] = [cl.node(r) for r in repo.revs(revset, subset)]
     return headsbyphase
 
--- a/tests/test-bundle-phases.t	Wed Mar 08 17:33:33 2023 +0100
+++ b/tests/test-bundle-phases.t	Thu Mar 09 01:26:04 2023 +0100
@@ -44,6 +44,7 @@
   cache:rev-branch-cache -- {} (mandatory: False)
   phase-heads -- {} (mandatory: True)
       26805aba1e600a82e93661149f2313866a221a7b draft
+      9bc730a19041f9ec7cb33c626e811aa233efb18c secret
   $ hg strip --no-backup C
 
 Phases show on incoming, and are also restored when pulling.  Secret commits
@@ -374,6 +375,7 @@
   phase-heads -- {} (mandatory: True)
       dc0947a82db884575bb76ea10ac97b08536bfa03 public
       03ca77807e919db8807c3749086dc36fb478cac0 draft
+      4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4 secret
   $ hg strip --no-backup A
   $ hg unbundle -q bundle
   $ rm bundle
@@ -398,6 +400,7 @@
       4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4
   cache:rev-branch-cache -- {} (mandatory: False)
   phase-heads -- {} (mandatory: True)
+      4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4 secret
   $ rm bundle
 
   $ hg bundle --base A -r D bundle
@@ -411,6 +414,7 @@
   cache:rev-branch-cache -- {} (mandatory: False)
   phase-heads -- {} (mandatory: True)
       dc0947a82db884575bb76ea10ac97b08536bfa03 public
+      4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4 secret
   $ rm bundle
 
   $ hg bundle --base 'B + C' -r 'D + E' bundle
@@ -423,4 +427,5 @@
   cache:rev-branch-cache -- {} (mandatory: False)
   phase-heads -- {} (mandatory: True)
       03ca77807e919db8807c3749086dc36fb478cac0 draft
+      4e4f9194f9f181c57f62e823e8bdfa46ab9e4ff4 secret
   $ rm bundle
--- a/tests/test-bundle-type.t	Wed Mar 08 17:33:33 2023 +0100
+++ b/tests/test-bundle-type.t	Thu Mar 09 01:26:04 2023 +0100
@@ -383,6 +383,7 @@
       66e2c4b43e0cf8f0bdff0733a0b97ce57874e35d public
       a8c3a1ed30eb71f03f476c5fa7ead831ef991a55 draft
       2ea90778052ba7558fab36e3fd5d149512ff986b draft
+      b9f5f740a8cd76700020e3903ee55ecff78bd3e5 secret
   bzip2-v2;cg.version=03
   
   adding changesets
--- a/tests/test-phase-archived.t	Wed Mar 08 17:33:33 2023 +0100
+++ b/tests/test-phase-archived.t	Thu Mar 09 01:26:04 2023 +0100
@@ -181,8 +181,6 @@
 The archived changeset should still be hidden
 
   $ hg log -G -T '{rev} {node|short} [{phase}] {desc|firstline}\n'
-  o  2 f90bf4e57854 [draft] some more commit (known-bad-output !)
-  | (known-bad-output !)
   @  1 d1e73e428f29 [draft] unbundletesting
   |
   o  0 c1863a3840c6 [draft] root
@@ -191,8 +189,7 @@
 It may still be around:
 
   $ hg log --hidden -G -T '{rev} {node|short} [{phase}] {desc|firstline}\n'
-  o  2 f90bf4e57854 [draft] some more commit (known-bad-output !)
-  o  2 f90bf4e57854 [archived] some more commit (missing-correct-output !)
+  o  2 f90bf4e57854 [archived] some more commit
   |
   @  1 d1e73e428f29 [draft] unbundletesting
   |