Patchwork D9525: singlehead: introduce option to restrict to public changes

login
register
mail settings
Submitter phabricator
Date Dec. 5, 2020, 10:37 p.m.
Message ID <differential-rev-PHID-DREV-cg27in7j2hukdrqgdh27-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47808/
State Superseded
Headers show

Comments

phabricator - Dec. 5, 2020, 10:37 p.m.
joerg.sonnenberger created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The new experimental.single-head-per-branch:public-changes-only option
  restricts the single-head-per-branch filter to public changesets. This
  is useful when serving one repository with different views as publishing
  and non-publishing repository.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/scmutil.py
  tests/test-single-head.t

CHANGE DETAILS




To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-single-head.t b/tests/test-single-head.t
--- a/tests/test-single-head.t
+++ b/tests/test-single-head.t
@@ -277,7 +277,7 @@ 
   c_aL0
   c_aM0
 
-Let's make a new head and push everythin. The server feedback will mention
+Let's make a new head and push everything. The server feedback will mention
 exactly one new head because c_aM0 is closed.
 
   $ hg up 'desc("c_aG0")'
@@ -291,3 +291,98 @@ 
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 3 files (+1 heads)
+  $ cd ..
+
+
+Test that singe-head-per-branch can be restricted to public changes
+-------------------------------------------------------------------
+
+  $ hg clone -r 49003e504178 single-head-server public-only
+  adding changesets
+  adding manifests
+  adding file changes
+  added 9 changesets with 9 changes to 9 files
+  1 new obsolescence markers
+  new changesets ea207398892e:49003e504178 (9 drafts)
+  updating to branch branch_A
+  9 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd public-only
+  $ cat <<EOF >> .hg/hgrc
+  > [phases]
+  > publish = no
+  > [experimental]
+  > single-head-per-branch = yes
+  > single-head-per-branch:public-changes-only = yes
+  > EOF
+  > hg phase -p :
+  $ hg update 'desc("c_aG0")'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ mkcommit c_dO0
+  created new head
+  $ hg log -G
+  @  changeset:   9:8058fd35cc2b
+  |  branch:      branch_A
+  |  tag:         tip
+  |  parent:      7:a33fb808fb4b
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     c_dO0
+  |
+  | o  changeset:   8:49003e504178
+  |/|  branch:      branch_A
+  | |  parent:      7:a33fb808fb4b
+  | |  parent:      3:840af1c6bc88
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     c_aI0
+  | |
+  o |  changeset:   7:a33fb808fb4b
+  | |  branch:      branch_A
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     c_aG0
+  | |
+  o |  changeset:   6:99a2dc242c5d
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     c_dF1
+  | |
+  o |    changeset:   5:6ed1df20edb1
+  |\ \   parent:      4:9bf953aa81f6
+  | | |  parent:      2:286d02a6e2a2
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |  summary:     c_dE0
+  | | |
+  | o |  changeset:   4:9bf953aa81f6
+  | | |  parent:      1:134bc3852ad2
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |  summary:     c_dD0
+  | | |
+  | | o  changeset:   3:840af1c6bc88
+  | | |  branch:      branch_A
+  | | |  parent:      0:ea207398892e
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |  summary:     c_aC0
+  | | |
+  o | |  changeset:   2:286d02a6e2a2
+  |/ /   user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     c_dB0
+  | |
+  o |  changeset:   1:134bc3852ad2
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     c_dA0
+  |
+  o  changeset:   0:ea207398892e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     ROOT
+  
+  $ hg phase -p .
+  abort: rejecting multiple heads on branch "branch_A"
+  (2 heads: 49003e504178 8058fd35cc2b)
+  [255]
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -2189,12 +2189,12 @@ 
     return _(b"%s and %d others") % (first, len(nodes) - maxnumnodes)
 
 
-def enforcesinglehead(repo, tr, desc, accountclosed=False):
+def enforcesinglehead(repo, tr, desc, accountclosed=False, filter=b'visible'):
     """check that no named branch has multiple heads"""
     if desc in (b'strip', b'repair'):
         # skip the logic during strip
         return
-    visible = repo.filtered(b'visible')
+    visible = repo.filtered(filter)
     # possible improvement: we could restrict the check to affected branch
     bm = visible.branchmap()
     for name in bm:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2230,7 +2230,13 @@ 
                 accountclosed = singleheadsub.get(
                     b"account-closed-heads", False
                 )
-                scmutil.enforcesinglehead(repo, tr2, desc, accountclosed)
+                if singleheadsub.get(b"public-changes-only", False):
+                    filter = b"immutable"
+                else:
+                    filter = b"visible"
+                scmutil.enforcesinglehead(
+                    repo, tr2, desc, accountclosed, filter
+                )
             if hook.hashook(repo.ui, b'pretxnclose-bookmark'):
                 for name, (old, new) in sorted(
                     tr.changes[b'bookmarks'].items()
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1079,6 +1079,11 @@ 
 )
 coreconfigitem(
     b'experimental',
+    b'single-head-per-branch:public-changes-only',
+    default=False,
+)
+coreconfigitem(
+    b'experimental',
     b'sshserver.support-v2',
     default=False,
 )