Patchwork [RFC-STABLE] subrepo: allows to drop courtesy phase sync (issue3781)

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 31, 2013, 1:27 a.m.
Message ID <43509c58558afd9106cf.1359595650@yamac.lan>
Download mbox | patch
Permalink /patch/765/
State Accepted
Commit 751135cca13ce102d4ed17ccb8062f2998425207
Headers show

Comments

Pierre-Yves David - Jan. 31, 2013, 1:27 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1359593069 -3600
# Branch stable
# Node ID 43509c58558afd9106cf28d7f80a419f39b9ac3d
# Parent  68eecbaf1bd32a616748331cc9f22d55b1316ce3
subrepo: allows to drop courtesy phase sync (issue3781)

Publishing server may contains draft changeset when they are created locally. As
publishing is the default, it is actually fairly common. Because of this
"inconsistency" phases synchronization may be done even to publishing server.

This may cause severe issues for subrepo. It is possible to reference read-only
repository as subrepo. Push in a super repo recursively push subrepo. Those
pushes to potential read only repo are not optional, they are "suffered" not
"choosed". This does not break because as the repo is untouched the push is
supposed to be empty. If the reference repo locally contains draft changesets, a
courtesy push is triggered to turn them public. As the repo is read only, the
push fails (after possible prompt asking for credential). Failure of the
sub-push aborts the whole subrepo push. This force the user to define a custom
default-push for such subrepo.

This changeset introduce a prevention of this error client side by skipping the
courtesy phase synchronisation in problematic situation. The phases
synchronisation is skipped when four conditions are gathered:
- this is a subrepo push, (normal push to read-only repo)
- and remote support phase
- and remote is publishing
- and no changesets was pushed (if we pushed changesets, repo is not read only)

The internal config option used in this version is not definitive. It is here to
demonstrate a working fix to the issue.

In the future we probably wants to track subrepo changes and avoid pushing to
untouched one. That will prevent any attempt to push to read-only or unreachable
subrepo.

Another fix to prevent courtesy push from older clients to push to newer server
is also still needed.
Matt Mackall - Feb. 1, 2013, 8:40 p.m.
On Thu, 2013-01-31 at 02:27 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@logilab.fr>
> # Date 1359593069 -3600
> # Branch stable
> # Node ID 43509c58558afd9106cf28d7f80a419f39b9ac3d
> # Parent  68eecbaf1bd32a616748331cc9f22d55b1316ce3
> subrepo: allows to drop courtesy phase sync (issue3781)

Queued for stable, thanks. We'll probably want to revisit this with a
tidier fix in the future.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1872,10 +1872,24 @@  class localrepository(object):
                                      outgoing.commonheads,
                                      outgoing.missing)
                     cheads.extend(c.node() for c in revset)
                 # even when we don't push, exchanging phase data is useful
                 remotephases = remote.listkeys('phases')
+                if (self.ui.configbool('ui', '_usedassubrepo', False)
+                    and remotephases    # server supports phases
+                    and ret is None # nothing was pushed
+                    and remotephases.get('publishing', False)):
+                    # When:
+                    # - this is a subrepo push
+                    # - and remote support phase
+                    # - and no changeset was pushed
+                    # - and remote is publishing
+                    # We may be in issue 3871 case!
+                    # We drop the possible phase synchronisation done by
+                    # courtesy to publish changesets possibly locally draft
+                    # on the remote.
+                    remotephases = {'publishing': 'True'}
                 if not remotephases: # old server or public only repo
                     phases.advanceboundary(self, phases.public, cheads)
                     # don't push any phase data as there is nothing to push
                 else:
                     ana = phases.analyzeremotephases(self, cheads, remotephases)
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -418,10 +418,11 @@  class hgsubrepo(abstractsubrepo):
         self._repo = hg.repository(r.baseui, root, create=create)
         for s, k in [('ui', 'commitsubrepos')]:
             v = r.ui.config(s, k)
             if v:
                 self._repo.ui.setconfig(s, k, v)
+        self._repo.ui.setconfig('ui', '_usedassubrepo', 'True')
         self._initrepo(r, state[0], create)
 
     @annotatesubrepoerror
     def _initrepo(self, parentrepo, source, create):
         self._repo._subparent = parentrepo
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -1049,5 +1049,29 @@  Forgetting an explicit path in a subrepo
   $ hg forget s/f19
   $ hg st -S
   ? s/f19
   $ rm s/f19
   $ cd ..
+
+Courtesy phases synchronisation to publishing server does not block the push
+(issue3781)
+
+  $ cp -r main issue3781
+  $ cp -r main issue3781-dest
+  $ cd issue3781-dest/s
+  $ hg phase tip # show we have draft changeset
+  5: draft
+  $ chmod a-w .hg/store/phaseroots # prevent phase push
+  $ cd ../../issue3781
+  $ cat >> .hg/hgrc << EOF
+  > [paths]
+  > default=../issue3781-dest/
+  > EOF
+  $ hg push
+  pushing to $TESTTMP/issue3781-dest
+  pushing subrepo s to $TESTTMP/issue3781-dest/s
+  searching for changes
+  no changes found
+  searching for changes
+  no changes found
+  [1]
+