--- a/autoland/autoland/transplant.py
+++ b/autoland/autoland/transplant.py
@@ -6,16 +6,26 @@ import os
import re
import tempfile
REPO_CONFIG = {}
logger = logging.getLogger('autoland')
+class HgCommandError(Exception):
+ def __init__(self, hg_args, out):
+ # we want to strip out any sensitive --config options
+ hg_args = map(lambda x: x if not x.startswith('bugzilla') else 'xxx',
+ hg_args)
+ message = 'hg error in cmd: hg %s: %s' % (' '.join(hg_args),
+ out.getvalue())
+ super(self.__class__, self).__init__(message)
+
+
def transplant(tree, destination, rev, trysyntax=None,
push_bookmark=False, commit_descriptions=None):
"""Transplant a specified revision and ancestors to the specified tree.
If ``trysyntax`` is specified, a Try commit will be created using the
syntax specified.
"""
# These values can appear in command arguments. Don't let unicode leak
@@ -75,39 +85,33 @@ def _transplant(hg_repo, tree, destinati
return False, str(e)
def get_repo_path(tree):
return config.get('repos').get(tree,
os.path.join(os.path.sep, 'repos', tree))
-def formulate_hg_error(cmd, output):
- # we want to strip out any sensitive --config options
- cmd = map(lambda x: x if not x.startswith('bugzilla') else 'xxx', cmd)
- return 'hg error in cmd: ' + ' '.join(cmd) + ': ' + output
-
-
def run_hg(hg_repo, rev, args):
logger.info('rev: %s: executing: %s' % (rev, args))
out = hglib.util.BytesIO()
out_channels = {b'o': out.write, b'e': out.write}
ret = hg_repo.runcommand(args, {}, out_channels)
if ret:
raise hglib.error.CommandError(args, ret, out, None)
return out.getvalue()
def run_hg_cmds(hg_repo, rev, cmds):
last_result = ''
for cmd in cmds:
try:
last_result = run_hg(hg_repo, rev, cmd)
except hglib.error.CommandError as e:
- raise Exception(formulate_hg_error(['hg'] + cmd, e.out.getvalue()))
+ raise HgCommandError(cmd, e.out)
return last_result
def strip_drafts(hg_repo, rev):
# Strip any lingering draft changesets.
try:
run_hg(hg_repo, rev, ['strip', '--no-backup', '-r', 'not public()'])
except hglib.error.CommandError:
@@ -142,18 +146,17 @@ def update_repo(hg_repo, rev, tree, remo
output = e.out.getvalue()
if 'no changes found' in output:
# we've already pulled this revision
continue
elif 'abort: no rebase in progress' in output:
# there was no rebase in progress, nothing to see here
continue
else:
- raise Exception(formulate_hg_error(['hg'] + cmd,
- e.out.getvalue()))
+ raise HgCommandError(cmd, e.out)
def rewrite_commit_descriptions(hg_repo, rev, commit_descriptions):
# Rewrite commit descriptions as per the mapping provided. Returns the
# revision of the base commit.
assert commit_descriptions, 'commit_descriptions requires for transplant'
with tempfile.NamedTemporaryFile() as f:
@@ -179,19 +182,18 @@ def rewrite_commit_descriptions(hg_repo,
def rebase(hg_repo, rev, base_revision, remote_tip):
# Perform rebase if necessary. Returns tip revision.
cmd = ['rebase', '-s', base_revision, '-d', remote_tip]
try:
run_hg(hg_repo, rev, cmd)
except hglib.error.CommandError as e:
- output = e.out.getvalue()
- if 'nothing to rebase' not in output:
- raise Exception(formulate_hg_error(['hg'] + cmd, output))
+ if 'nothing to rebase' not in e.out.getvalue():
+ raise HgCommandError(cmd, e.out)
return run_hg_cmds(hg_repo, rev, [
['log', '-r', 'tip', '-T', '{node|short}']
])
def validate_descriptions(hg_repo, destination, commit_descriptions):
# Match outgoing commit descriptions against incoming commit