[PATCH 4 of 6] headsummary: expose the 'discardedheads' set in the headssummary

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sun Jun 4 10:49:32 EDT 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1496029933 -7200
#      Mon May 29 05:52:13 2017 +0200
# Node ID 33062379c342992425c1ba8083bafb46420ba7d0
# Parent  0be71c66f99550d0abc18fceaa86e0ac018bd382
# EXP-Topic pushrace
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 33062379c342
headsummary: expose the 'discardedheads' set in the headssummary

That information will be useful to detect push race on related part of the
history.

See next changeset for details.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -185,13 +185,15 @@ def findcommonoutgoing(repo, other, only
 def _headssummary(pushop):
     """compute a summary of branch and heads status before and after push
 
-    return {'branch': ([remoteheads], [newheads], [unsyncedheads])} mapping
+    return {'branch': ([remoteheads], [newheads],
+                       [unsyncedheads], [discardedheads])} mapping
 
-    - branch: the branch name
+    - branch: the branch name,
     - remoteheads: the list of remote heads known locally
-                   None if the branch is new
-    - newheads: the new remote heads (known locally) with outgoing pushed
-    - unsyncedheads: the list of remote heads unknown locally.
+                   None if the branch is new,
+    - newheads: the new remote heads (known locally) with outgoing pushed,
+    - unsyncedheads: the list of remote heads unknown locally,
+    - discardedheads: the list of heads made obsolete by the push.
     """
     repo = pushop.repo.unfiltered()
     remote = pushop.remote
@@ -238,10 +240,12 @@ def _headssummary(pushop):
     newmap.update(repo, (ctx.rev() for ctx in missingctx))
     for branch, newheads in newmap.iteritems():
         headssum[branch][1][:] = newheads
-    for branch, items in headssum.iteritems():
+    for branch, items in list(headssum.iteritems()):
         for l in items:
             if l is not None:
                 l.sort()
+        headssum[branch] = items + ([],)
+
     # If there are no obsstore, no post processing are needed.
     if repo.obsstore:
         allmissing = set(outgoing.missing)
@@ -249,10 +253,10 @@ def _headssummary(pushop):
         allfuturecommon = set(c.node() for c in cctx)
         allfuturecommon.update(allmissing)
         for branch, heads in sorted(headssum.iteritems()):
-            remoteheads, newheads, unsyncedheads = heads
+            remoteheads, newheads, unsyncedheads, placeholder = heads
             result = _postprocessobsolete(pushop, allfuturecommon, newheads)
-            newheads = sorted(result[0])
-            headssum[branch] = (remoteheads, newheads, unsyncedheads)
+            headssum[branch] = (remoteheads, sorted(result[0]), unsyncedheads,
+                                sorted(result[1]))
     return headssum
 
 def _oldheadssummary(repo, remoteheads, outgoing, inc=False):
@@ -275,7 +279,7 @@ def _oldheadssummary(repo, remoteheads, 
         unsynced = [None]
     else:
         unsynced = []
-    return {None: (oldheads, newheads, unsynced)}
+    return {None: (oldheads, newheads, unsynced, [])}
 
 def _nowarnheads(pushop):
     # Compute newly pushed bookmarks. We don't warn about bookmarked heads.
@@ -346,7 +350,7 @@ def checkheads(pushop):
     # error message, depending on unsynced status, is displayed.
     errormsg = None
     for branch, heads in sorted(headssum.iteritems()):
-        remoteheads, newheads, unsyncedheads = heads
+        remoteheads, newheads, unsyncedheads, discardedheads = heads
         # add unsynced data
         if remoteheads is None:
             oldhs = set()


More information about the Mercurial-devel mailing list