Patchwork [1,of,2] bundle2: add a "check:heads" handler

login
register
mail settings
Submitter Pierre-Yves David
Date April 13, 2014, 6:58 p.m.
Message ID <66d9aab7e6895fae7e72.1397415490@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4335/
State Accepted
Commit 0bea9db7543bb15f08275b700d7e5e478cc73e54
Headers show

Comments

Pierre-Yves David - April 13, 2014, 6:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1397223781 25200
#      Fri Apr 11 06:43:01 2014 -0700
# Node ID 66d9aab7e6895fae7e723d5122c9301e3d2d90ec
# Parent  054309870e8372d756050919881cdc717f3e6b53
bundle2: add a "check:heads" handler

This part is intended to hold the same role as the `heads` argument of the
unbundle function. It the client fill it with the know heads at bundle time and
the server will abort its heads changed.


G: changed mercurial/bundle2.py

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -655,5 +655,19 @@  def handlechangegroup(op, inpart):
 def handlechangegroup(op, inpart):
     p = dict(inpart.advisoryparams)
     ret = int(p['return'])
     op.records.add('changegroup', {'return': ret}, int(p['in-reply-to']))
 
+@parthandler('check:heads')
+def handlechangegroup(op, inpart):
+    """check that head of the repo did not changed
+
+    This is use to detect push race when using unbundle.
+    This replace the "heads" argument or unbundle."""
+    h = inpart.read(20)
+    heads = []
+    while len(h) == 20:
+        heads.append(h)
+        h = inpart.read(20)
+    assert not h
+    if heads != op.repo.heads():
+        raise exchange.PushRaced()