Patchwork [1,of,4] phase: apply publishing enforcement for "serve" source

login
register
mail settings
Submitter Pierre-Yves David
Date April 10, 2014, 5:13 p.m.
Message ID <a049f28c37ddc81665f4.1397149994@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4279/
State Accepted
Commit 63659b8090212fd83270c12029a8a1ba7b26d6fe
Headers show

Comments

Pierre-Yves David - April 10, 2014, 5:13 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1396919450 25200
#      Mon Apr 07 18:10:50 2014 -0700
# Node ID a049f28c37ddc81665f40e4ce84fcffa205f3c45
# Parent  774ff56cbe3440bef50909f369cdaaf0069d96f6
phase: apply publishing enforcement for "serve" source

When a changegroup is added from a push on a publishing server, we ensure they
are added as public. This is used to enforces publishing on server when the
client is not aware of phases. It also prevents race condition where a reader
could see the changeset as draft before they get turned public by the client.
Finally this save rounds trip as the client does not need additional request to
turn them public.

However this logic was only enforced when the changegroup was from "push"
source. And "push" is used for local pushes only. Wireprotocol push use "serve"
as source since Mercurial 1.9. We now enforce this logic for both "push" and
"serve" sources.

One could notes that this logic was mainly useful during wireprotocol exchanges.
So this code is finally put into good use, 9 version after its introduction.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -675,11 +675,11 @@  def addchangegroup(repo, source, srctype
                       node=hex(cl.node(clstart)), source=srctype,
                       url=url, pending=p)
 
         added = [cl.node(r) for r in xrange(clstart, clend)]
         publishing = repo.ui.configbool('phases', 'publish', True)
-        if srctype == 'push':
+        if srctype in ('push', 'serve'):
             # Old servers can not push the boundary themselves.
             # New servers won't push the boundary if changeset already
             # exists locally as secret
             #
             # We should not use added here but the list of all change in
diff --git a/tests/test-http.t b/tests/test-http.t
--- a/tests/test-http.t
+++ b/tests/test-http.t
@@ -265,11 +265,10 @@  test http authentication
   "GET /?cmd=branchmap HTTP/1.1" 200 -
   "GET /?cmd=listkeys HTTP/1.1" 401 - x-hgarg-1:namespace=bookmarks
   "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=bookmarks
   "POST /?cmd=unbundle HTTP/1.1" 200 - x-hgarg-1:heads=686173686564+5eb5abfefeea63c80dd7553bcc3783f37e0c5524
   "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=phases
-  "POST /?cmd=pushkey HTTP/1.1" 200 - x-hgarg-1:key=7f4e523d01f2cc3765ac8934da3d14db775ff872&namespace=phases&new=0&old=1
   "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=bookmarks
 
 #endif
   $ cd ..
 
diff --git a/tests/test-push-http.t b/tests/test-push-http.t
--- a/tests/test-push-http.t
+++ b/tests/test-push-http.t
@@ -66,11 +66,10 @@  expect success
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: changegroup hook: HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_URL=remote:http:*: (glob)
-  remote: pushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1 HG_RET=1
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
 
 expect success, server lacks the httpheader capability
@@ -83,11 +82,10 @@  expect success, server lacks the httphea
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: changegroup hook: HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_URL=remote:http:*: (glob)
-  remote: pushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1 HG_RET=1
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
 
 expect success, server lacks the unbundlehash capability
@@ -100,11 +98,10 @@  expect success, server lacks the unbundl
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: changegroup hook: HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_URL=remote:http:*: (glob)
-  remote: pushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1 HG_RET=1
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
 
 expect push success, phase change failure
@@ -121,22 +118,19 @@  expect push success, phase change failur
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
-  remote: prepushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1
-  updating ba677d0156c1 to public failed!
   % serve errors
 
 expect phase change success
 
   $ echo "prepushkey = python \"$TESTDIR/printenv.py\" prepushkey 0" >> .hg/hgrc
   $ req
   pushing to http://localhost:$HGPORT/
   searching for changes
   no changes found
-  remote: prepushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1
   % serve errors
   [1]
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)