subrepo: allows to drop courtesy phase sync (issue3781) stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 31 Jan 2013 01:44:29 +0100
branchstable
changeset 18520 751135cca13c
parent 18519 ca430fb6a668
child 18521 0af2fe7b3274
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.
mercurial/localrepo.py
mercurial/subrepo.py
tests/test-subrepo.t
--- a/mercurial/localrepo.py	Thu Jan 31 19:13:13 2013 +0100
+++ b/mercurial/localrepo.py	Thu Jan 31 01:44:29 2013 +0100
@@ -1874,6 +1874,20 @@
                     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
--- a/mercurial/subrepo.py	Thu Jan 31 19:13:13 2013 +0100
+++ b/mercurial/subrepo.py	Thu Jan 31 01:44:29 2013 +0100
@@ -423,6 +423,7 @@
             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
--- a/tests/test-subrepo.t	Thu Jan 31 19:13:13 2013 +0100
+++ b/tests/test-subrepo.t	Thu Jan 31 01:44:29 2013 +0100
@@ -1062,3 +1062,27 @@
   ? 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]
+