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

login
register
mail settings
Submitter Pierre-Yves David
Date June 4, 2017, 2:49 p.m.
Message ID <33062379c342992425c1.1496587772@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21171/
State Accepted
Headers show

Comments

Pierre-Yves David - June 4, 2017, 2:49 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Yuya Nishihara - June 7, 2017, 1:37 p.m.
On Sun, 04 Jun 2017 15:49:32 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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

> @@ -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()):

No need to make a list here since dict keys aren't modified. Removed list()
in flight.

>          for l in items:
>              if l is not None:
>                  l.sort()
> +        headssum[branch] = items + ([],)

Patch

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()