changeset 3159:90515d0bfb08

push: add a --publish flag The new flag turns all element in the push to public changeset. This will help experiment with diverse publishing workflow.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 01 Nov 2017 16:23:13 +0100
parents 678a9802c56b
children f42a87cc864d ade7a21ab324
files CHANGELOG hgext3rd/topic/__init__.py hgext3rd/topic/flow.py tests/test-topic-flow-publish-flag.t
diffstat 4 files changed, 331 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Wed Nov 01 16:26:33 2017 +0100
+++ b/CHANGELOG	Wed Nov 01 16:23:13 2017 +0100
@@ -16,6 +16,7 @@
     (off by default, see 'hg help -e topic' for details)
   * add an experimental flag to have changesets without topic published on push,
     (off by default, see 'hg help -e topic' for details)
+  * add a '--publish' flag to `hg push` (4.4+ only),
 
 6.8.0 -- 2017-10-23
 -------------------
--- a/hgext3rd/topic/__init__.py	Wed Nov 01 16:26:33 2017 +0100
+++ b/hgext3rd/topic/__init__.py	Wed Nov 01 16:23:13 2017 +0100
@@ -93,6 +93,10 @@
     publish = no
     [experimental]
     topic.publish-bare-branch = yes
+
+In addition, the topic extension adds a ``--publish`` flag on :hg:`push`. When
+used, the pushed revisions are published if the push succeeds. It also applies
+to common revisions selected by the push.
 """
 
 from __future__ import absolute_import
@@ -282,6 +286,8 @@
 
     extensions.afterloaded('rebase', _fixrebase)
 
+    flow.installpushflag(ui)
+
     entry = extensions.wrapcommand(commands.table, 'commit', commitwrap)
     entry[1].append(('t', 'topic', '',
                      _("use specified topic"), _('TOPIC')))
--- a/hgext3rd/topic/flow.py	Wed Nov 01 16:26:33 2017 +0100
+++ b/hgext3rd/topic/flow.py	Wed Nov 01 16:23:13 2017 +0100
@@ -1,9 +1,13 @@
 from __future__ import absolute_import
 
 from mercurial import (
+    commands,
     error,
+    exchange,
+    extensions,
     node,
     phases,
+    util,
 )
 
 from mercurial.i18n import _
@@ -25,3 +29,41 @@
         cl = repo.changelog
         nodes = [cl.node(r) for r in topublish]
         repo._phasecache.advanceboundary(repo, tr, phases.public, nodes)
+
+def wrappush(orig, repo, remote, *args, **kwargs):
+    """interpret the --publish flag and pass it to the push operation"""
+    newargs = kwargs.copy()
+    if kwargs.pop('publish', False):
+        opargs = kwargs.get('opargs')
+        if opargs is None:
+            opargs = {}
+        newargs['opargs'] = opargs.copy()
+        newargs['opargs']['publish'] = True
+    return orig(repo, remote, *args, **newargs)
+
+def extendpushoperation(orig, *args, **kwargs):
+    publish = kwargs.pop('publish', False)
+    op = orig(*args, **kwargs)
+    op.publish = publish
+    return op
+
+def wrapphasediscovery(orig, pushop):
+    orig(pushop)
+    if pushop.publish:
+        if not util.safehasattr(pushop, 'remotephases'):
+            msg = _('--publish flag only supported from Mercurial 4.4 and higher')
+            raise error.Abort(msg)
+        if not pushop.remotephases.publishing:
+            unfi = pushop.repo.unfiltered()
+            droots = pushop.remotephases.draftroots
+            revset = '%ln and (not public() or %ln::)'
+            future = list(unfi.set(revset, pushop.futureheads, droots))
+            pushop.outdatedphases = future
+
+def installpushflag(ui):
+    entry = extensions.wrapcommand(commands.table, 'push', wrappush)
+    entry[1].append(('', 'publish', False,
+                    _('push the changeset as public')))
+    extensions.wrapfunction(exchange, 'pushoperation', extendpushoperation)
+    extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery)
+    exchange.pushdiscoverymapping['phase'] = exchange._pushdiscoveryphase
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-topic-flow-publish-flag.t	Wed Nov 01 16:23:13 2017 +0100
@@ -0,0 +1,282 @@
+=====================
+Test workflow options
+=====================
+
+  $ . "$TESTDIR/testlib/topic_setup.sh"
+  $ . "$TESTDIR/testlib/common.sh"
+
+testing hg push --publish flag
+==============================
+
+  $ hg init bare-branch-server
+  $ cd bare-branch-server
+  $ cat <<EOF >> .hg/hgrc
+  > [phases]
+  > publish = no
+  > EOF
+  $ mkcommit ROOT
+  $ mkcommit c_dA0
+  $ hg phase --public -r 'all()'
+  $ cd ..
+
+  $ hg clone bare-branch-server bare-client
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd bare-client
+
+Pushing a 1 new changeset
+-------------------------
+
+  $ mkcommit c_dB0
+  $ hg push --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+
+Pushing a 2 new changeset (same branch)
+---------------------------------------
+
+  $ mkcommit c_dC0
+  $ mkcommit c_dD0
+  $ hg push --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+
+Pushing a 2 new changeset two head
+----------------------------------
+
+  $ mkcommit c_dE0
+  $ hg update 'desc("c_dD0")'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg branch other
+  marked working directory as branch other
+  (branches are permanent and global, did you want a bookmark?)
+  $ mkcommit c_oF0
+  $ hg push -f --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files (+1 heads)
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  6:45b23c834b6a c_oF0 public other
+  |
+  | o  5:5576ae39eaee c_dE0 public default
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+
+Publishing 1 common changeset
+-----------------------------
+  $ mkcommit c_oG0
+  $ hg push
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  7:d293f74a1233 c_oG0 draft other
+  |
+  o  6:45b23c834b6a c_oF0 public other
+  |
+  | o  5:5576ae39eaee c_dE0 public default
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+  $ hg push --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  no changes found
+  [1]
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  7:d293f74a1233 c_oG0 public other
+  |
+  o  6:45b23c834b6a c_oF0 public other
+  |
+  | o  5:5576ae39eaee c_dE0 public default
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+
+Selectively publishing 1 changeset
+----------------------------------
+
+  $ mkcommit c_oH0
+  $ hg update default
+  1 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ mkcommit c_dI0
+  $ hg push -r default --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  9:fbf2be276221 c_dI0 public default
+  |
+  o  5:5576ae39eaee c_dE0 public default
+  |
+  | o  8:8e85646c135f c_oH0 draft other
+  | |
+  | o  7:d293f74a1233 c_oG0 public other
+  | |
+  | o  6:45b23c834b6a c_oF0 public other
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+
+Selectively publishing 1 common changeset
+-----------------------------------------
+
+  $ mkcommit c_dJ0
+  $ hg push
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  10:ac4cf59f2aac c_dJ0 draft default
+  |
+  o  9:fbf2be276221 c_dI0 public default
+  |
+  o  5:5576ae39eaee c_dE0 public default
+  |
+  | o  8:8e85646c135f c_oH0 draft other
+  | |
+  | o  7:d293f74a1233 c_oG0 public other
+  | |
+  | o  6:45b23c834b6a c_oF0 public other
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+  $ hg push --rev default --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  no changes found
+  [1]
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  10:ac4cf59f2aac c_dJ0 public default
+  |
+  o  9:fbf2be276221 c_dI0 public default
+  |
+  o  5:5576ae39eaee c_dE0 public default
+  |
+  | o  8:8e85646c135f c_oH0 draft other
+  | |
+  | o  7:d293f74a1233 c_oG0 public other
+  | |
+  | o  6:45b23c834b6a c_oF0 public other
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+  
+
+Selectively publishing no changeset
+-----------------------------------
+
+  $ hg push --rev default --publish
+  pushing to $TESTTMP/bare-branch-server
+  searching for changes
+  no changes found
+  [1]
+  $ hg log --rev 'sort(all(), "topo")' -GT '{rev}:{node|short} {desc} {phase} {branch} {topics}'
+  @  10:ac4cf59f2aac c_dJ0 public default
+  |
+  o  9:fbf2be276221 c_dI0 public default
+  |
+  o  5:5576ae39eaee c_dE0 public default
+  |
+  | o  8:8e85646c135f c_oH0 draft other
+  | |
+  | o  7:d293f74a1233 c_oG0 public other
+  | |
+  | o  6:45b23c834b6a c_oF0 public other
+  |/
+  o  4:c63e7dd93a91 c_dD0 public default
+  |
+  o  3:7d56a56d2547 c_dC0 public default
+  |
+  o  2:286d02a6e2a2 c_dB0 public default
+  |
+  o  1:134bc3852ad2 c_dA0 public default
+  |
+  o  0:ea207398892e ROOT public default
+