diff mercurial/scmutil.py @ 35185:66ecde8a704d

server: introduce a 'experimental.single-head-per-branch' option When the option is set, the repository will reject any transaction adding multiple heads to the same named branch. For now we reject all scenario with multiple heads. One could imagine handling closed branches differently. We prefer to keep things simple for now. The feature might get extended later. Branch closing is not the best experience Mercurial has to offer anyway.
author Boris Feld <boris.feld@octobus.net>
date Thu, 16 Nov 2017 03:52:42 +0100
parents bc775b8cc020
children 278f1feee73a
line wrap: on
line diff
--- a/mercurial/scmutil.py	Thu Nov 16 03:52:38 2017 +0100
+++ b/mercurial/scmutil.py	Thu Nov 16 03:52:42 2017 +0100
@@ -1286,6 +1286,21 @@
     first = ' '.join(short(h) for h in nodes[:maxnumnodes])
     return _("%s and %s others") % (first, len(nodes) - maxnumnodes)
 
+def enforcesinglehead(repo, tr, desc):
+    """check that no named branch has multiple heads"""
+    if desc in ('strip', 'repair'):
+        # skip the logic during strip
+        return
+    visible = repo.filtered('visible')
+    # possible improvement: we could restrict the check to affected branch
+    for name, heads in visible.branchmap().iteritems():
+        if len(heads) > 1:
+            msg = _('rejecting multiple heads on branch "%s"')
+            msg %= name
+            hint = _('%d heads: %s')
+            hint %= (len(heads), nodesummaries(repo, heads))
+            raise error.Abort(msg, hint=hint)
+
 def wrapconvertsink(sink):
     """Allow extensions to wrap the sink returned by convcmd.convertsink()
     before it is used, whether or not the convert extension was formally loaded.