[PATCH 9 of 9 phases] push: add switch to push of secret changeset

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Wed Jan 18 10:33:15 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1326843379 -3600
# Node ID d46d6abdc30f5d19a93a49ae24ddf68dddee10eb
# Parent  86c3248fcb60571bea6f2805f40b6fc64bad503d
push: add switch to push of secret changeset

Implement the ability to include secret changeset in discovery and a switch
to turn this on during push.

diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py
+++ b/hgext/largefiles/reposetup.py
@@ -399,11 +399,12 @@ def reposetup(ui, repo):
                 lfdirstate.write()
                 return result
             finally:
                 wlock.release()
 
-        def push(self, remote, force=False, revs=None, newbranch=False):
+        def push(self, remote, force=False, revs=None, newbranch=False,
+                 includesecret=False):
             o = lfutil.findoutgoing(repo, remote, force)
             if o:
                 toupload = set()
                 o = repo.changelog.nodesbetween(o, revs)[0]
                 for n in o:
@@ -430,11 +431,11 @@ def reposetup(ui, repo):
                         set([ctx[f].data().strip()
                              for f in files
                              if lfutil.isstandin(f) and f in ctx]))
                 lfcommands.uploadlfiles(ui, self, remote, toupload)
             return super(lfiles_repo, self).push(remote, force, revs,
-                newbranch)
+                newbranch, includesecret)
 
     repo.__class__ = lfiles_repo
 
     def checkrequireslfiles(ui, repo, **kwargs):
         if 'largefiles' not in repo.requirements and util.any(
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -3161,12 +3161,12 @@ def reposetup(ui, repo):
                 force)
 
             return super(mqrepo, self).commit(text, user, date, match, force,
                                               editor, extra)
 
-        def checkpush(self, force, revs):
-            if self.mq.applied and not force:
+        def checkpush(self, force, revs, includesecret=False):
+            if self.mq.applied and not includesecret:
                 haspatches = True
                 if revs:
                     # Assume applied patches have no non-patch descendants
                     # and are not on remote already. If they appear in the
                     # set of resolved 'revs', bail out.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4370,10 +4370,11 @@ def pull(ui, repo, source="default", **o
      _('REV')),
     ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')),
     ('b', 'branch', [],
      _('a specific branch you would like to push'), _('BRANCH')),
     ('', 'new-branch', False, _('allow pushing a new branch')),
+    ('', 'secret', False, _('also push secret changeset')),
     ] + remoteopts,
     _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]'))
 def push(ui, repo, dest=None, **opts):
     """push changes to the specified destination
 
@@ -4431,11 +4432,12 @@ def push(ui, repo, dest=None, **opts):
             if not c.sub(s).push(opts):
                 return False
     finally:
         del repo._subtoppath
     result = repo.push(other, opts.get('force'), revs=revs,
-                       newbranch=opts.get('new_branch'))
+                       newbranch=opts.get('new_branch'),
+                       includesecret=opts.get('secret'))
 
     result = (result == 0)
 
     if opts.get('bookmark'):
         rb = other.listkeys('bookmarks')
diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -84,11 +84,12 @@ class outgoing(object):
     def missing(self):
         if self._missing is None:
             self._computecommonmissing()
         return self._missing
 
-def findcommonoutgoing(repo, other, onlyheads=None, force=False, commoninc=None):
+def findcommonoutgoing(repo, other, onlyheads=None, force=False, commoninc=None,
+                       includesecret=False):
     '''Return an outgoing instance to identify the nodes present in repo but
     not in other.
 
     If onlyheads is given, only nodes ancestral to nodes in onlyheads (inclusive)
     are included. If you already know the local repo's heads, passing them in
@@ -103,11 +104,11 @@ def findcommonoutgoing(repo, other, only
     if commoninc is None:
         commoninc = findcommonincoming(repo, other, force=force)
     og.commonheads, _any, _hds = commoninc
 
     # compute outgoing
-    if not repo._phaseroots[phases.secret]:
+    if includesecret or not repo._phaseroots[phases.secret]:
         og.missingheads = onlyheads or repo.heads()
     elif onlyheads is None:
         # use visible heads as it should be cached
         og.missingheads = phases.visibleheads(repo)
         og.excluded = [ctx.node() for ctx in repo.set('secret()')]
@@ -130,11 +131,11 @@ def findcommonoutgoing(repo, other, only
             missingheads = onlyheads
         og.missingheads = missingheads
 
     return og
 
-def prepush(repo, remote, force, revs, newbranch):
+def prepush(repo, remote, force, revs, newbranch, includesecret):
     '''Analyze the local and remote repositories and determine which
     changesets need to be pushed to the remote. Return value depends
     on circumstances:
 
     If we are not going to push anything, return a tuple (None, 1,
@@ -148,11 +149,12 @@ def prepush(repo, remote, force, revs, n
     the list of heads of the common set between local and remote to
     be after push completion.
     '''
     commoninc = findcommonincoming(repo, remote, force=force)
     outgoing = findcommonoutgoing(repo, remote, onlyheads=revs,
-                                      commoninc=commoninc, force=force)
+                                      commoninc=commoninc, force=force,
+                                      includesecret=includesecret)
     _common, inc, remoteheads = commoninc
 
     cl = repo.changelog
     outg = outgoing.missing
     common = outgoing.commonheads
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1570,18 +1570,19 @@ class localrepository(repo.repository):
         finally:
             lock.release()
 
         return result
 
-    def checkpush(self, force, revs):
+    def checkpush(self, force, revs, includesecret=False):
         """Extensions can override this function if additional checks have
         to be performed before pushing, or call it if they override push
         command.
         """
         pass
 
-    def push(self, remote, force=False, revs=None, newbranch=False):
+    def push(self, remote, force=False, revs=None, newbranch=False,
+             includesecret=False):
         '''Push outgoing changesets (limited by revs) from the current
         repository to remote. Return an integer:
           - 0 means HTTP error *or* nothing to push
           - 1 means we pushed and remote head count is unchanged *or*
             we have outgoing changesets but refused to push
@@ -1593,21 +1594,22 @@ class localrepository(repo.repository):
         # repo (local filesystem, old ssh servers).
         #
         # unbundle assumes local user cannot lock remote repo (new ssh
         # servers, http servers).
 
-        self.checkpush(force, revs)
+        self.checkpush(force, revs, includesecret=includesecret)
         lock = None
         unbundle = remote.capable('unbundle')
         if not unbundle:
             lock = remote.lock()
         try:
             # get local lock as we might write phase data
             locallock = self.lock()
             try:
-                cg, remote_heads, fut = discovery.prepush(self, remote, force,
-                                                           revs, newbranch)
+                dr = discovery.prepush(self, remote, force, revs, newbranch,
+                                       includesecret)
+                cg, remote_heads, fut = dr
                 ret = remote_heads
                 # create a callback for addchangegroup.
                 # If will be used branch of the conditionnal too.
                 if cg is not None:
                     if unbundle:
diff --git a/tests/test-check-code-hg.t b/tests/test-check-code-hg.t
--- a/tests/test-check-code-hg.t
+++ b/tests/test-check-code-hg.t
@@ -441,13 +441,10 @@
    >                     repo.ui.note(_("new remote heads on branch '%s'\n") % branch)
    warning: line over 80 characters
   mercurial/discovery.py:0:
    >     If onlyheads is given, only nodes ancestral to nodes in onlyheads (inclusive)
    warning: line over 80 characters
-  mercurial/discovery.py:0:
-   > def findcommonoutgoing(repo, other, onlyheads=None, force=False, commoninc=None):
-   warning: line over 80 characters
   mercurial/dispatch.py:0:
    >                                                 " (.hg not found)") % os.getcwd())
    warning: line over 80 characters
   mercurial/dispatch.py:0:
    >         aliases, entry = cmdutil.findcmd(cmd, cmdtable, lui.config("ui", "strict"))
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -199,11 +199,11 @@ Show all commands + options
   init: ssh, remotecmd, insecure
   log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, hidden, patch, git, limit, no-merges, stat, style, template, include, exclude
   merge: force, rev, preview, tool
   phase: public, draft, secret, force, rev
   pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
-  push: force, rev, bookmark, branch, new-branch, ssh, remotecmd, insecure
+  push: force, rev, bookmark, branch, new-branch, secret, ssh, remotecmd, insecure
   remove: after, force, include, exclude
   serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate
   status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude, subrepos
   summary: remote
   update: clean, check, date, rev
diff --git a/tests/test-mq-safety.t b/tests/test-mq-safety.t
--- a/tests/test-mq-safety.t
+++ b/tests/test-mq-safety.t
@@ -164,13 +164,13 @@ Pushing revs excluding applied patch
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
 
-Pushing applied patch with --force
+Pushing applied patch with --secret
 
-  $ hg push --force -r default ../forcepush2
+  $ hg push --secret -r default ../forcepush2
   pushing to ../forcepush2
   searching for changes
   adding changesets
   adding manifests
   adding file changes


More information about the Mercurial-devel mailing list