mozext: add optional -r REV to push-to-try extension (bug 1242323); r?gps draft
authorNick Alexander <nalexander@mozilla.com>
Sun, 24 Jan 2016 20:56:13 -0800
changeset 6946 c55eeee6897704ebbba3bc2d86c9b96554df5618
parent 6938 5d5a5ea80e992180acf502657a5d91232cb08e62
push id552
push usernalexander@mozilla.com
push dateTue, 26 Jan 2016 00:22:20 +0000
reviewersgps
bugs1242323
mozext: add optional -r REV to push-to-try extension (bug 1242323); r?gps
hgext/push-to-try/__init__.py
--- a/hgext/push-to-try/__init__.py
+++ b/hgext/push-to-try/__init__.py
@@ -1,31 +1,44 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
-from mercurial import commands, context, cmdutil
+from mercurial import (
+    cmdutil,
+    commands,
+    context,
+    scmutil,
+)
 from mercurial.i18n import _
+from mercurial.node import nullid
 
 OUR_DIR = os.path.normpath(os.path.dirname(__file__))
 execfile(os.path.join(OUR_DIR, '..', 'bootstrap.py'))
 
 from mozhg.rewrite import preservefilectx
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
 testedwith = '3.3 3.4 3.5 3.6'
 
 @command('push-to-try', [
     ('m', 'message', '', 'commit message to use', 'MESSAGE'),
     ('s', 'server', 'ssh://hg.mozilla.org/try', 'push destination', 'URL'),
-], '-m MESSAGE -s URL')
-def push_to_try(ui, repo, server, message=None):
+    ('r', 'rev', '.', 'single changeset intended to be pushed to try', 'REV'),
+], '-m MESSAGE -s URL [-r REV]')
+def push_to_try(ui, repo, server, message=None, rev='.'):
+
+    revs = scmutil.revrange(repo, [rev])
+    if len(revs) != 1:
+        ui.status("STOP! A single changest to push to try is required.\n")
+        return
+    parent, = tuple(revs)
 
     nodate = ui.configbool('push-to-try', 'nodate')
 
     if not message or 'try:' not in message:
         ui.status("STOP! A commit message with try syntax is required.\n")
         return
 
     cctx = context.workingctx(repo)
@@ -41,17 +54,17 @@ def push_to_try(ui, repo, server, messag
     def mk_memfilectx(repo, memctx, path):
         if path not in status.removed:
             return preserve_ctx(repo, memctx, path)
         return None
 
     # Invent a temporary commit with our message.
     ui.status("Creating temporary commit for remote...\n")
     mctx = context.memctx(repo,
-                          repo.dirstate.parents(),
+                          [parent, nullid],
                           message,
                           cctx.files(),
                           mk_memfilectx,
                           date="0 0" if nodate else None)
 
     # These messages are expected when we abort our transaction, but aren't
     # helpful to a user and may be misleading so we surpress them here.
     filtered_phrases = {_("transaction abort!\n"),