Factor out PathDifference into gclient_utils for a later reuse.

Make lack of email address an error.

TEST=none
BUG=none

Review URL: http://codereview.chromium.org/507072

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35167 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 15 years ago
parent 6f6a801ef9
commit 3ccbf7e6b7

@ -819,18 +819,6 @@ def TryChange(change_info, args, swallow_exception):
return
ErrorExit("You need to install trychange.py to use the try server.")
def PathDifference(root, subpath):
"""Returns the difference subpath minus root."""
root = os.path.realpath(root)
subpath = os.path.realpath(subpath)
if not subpath.startswith(root):
return None
# If the root does not have a trailing \ or /, we add it so the returned
# path starts immediately after the seperator regardless of whether it is
# provided.
root = os.path.join(root, '')
return subpath[len(root):]
trychange_args = []
settings = {
'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'),
@ -846,8 +834,9 @@ def TryChange(change_info, args, swallow_exception):
gclient_root = gclient_utils.FindGclientRoot(GetRepositoryRoot())
if gclient_root:
trychange_args.extend(['--root', PathDifference(gclient_root,
GetRepositoryRoot())])
trychange_args.extend(['--root',
gclient_utils.PathDifference(gclient_root,
GetRepositoryRoot())])
if change_info:
trychange_args.extend(['--name', change_info.name])
if change_info.issue:

@ -317,3 +317,15 @@ def FindGclientRoot(from_dir):
return None
path = next[0]
return path
def PathDifference(root, subpath):
"""Returns the difference subpath minus root."""
root = os.path.realpath(root)
subpath = os.path.realpath(subpath)
if not subpath.startswith(root):
return None
# If the root does not have a trailing \ or /, we add it so the returned
# path starts immediately after the seperator regardless of whether it is
# provided.
root = os.path.join(root, '')
return subpath[len(root):]

@ -17,8 +17,8 @@ class GclientUtilsUnittest(SuperMoxTestBase):
'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite',
'FindGclientRoot',
'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText',
'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML',
'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',
'GetNodeNamedAttributeText', 'IsUsingGit', 'PathDifference',
'ParseXML', 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',
'SubprocessCall', 'SubprocessCallAndFilter', 'errno', 'os', 're',
'stat', 'subprocess', 'sys', 'time', 'xml',
]

@ -427,6 +427,8 @@ def TryChange(argv,
parser.add_option_group(group)
options, args = parser.parse_args(argv)
if len(args) == 1 and args[0] == 'help':
parser.print_help()
# Switch the default accordingly if there was no default send_patch.
if not options.send_patch:
@ -437,19 +439,15 @@ def TryChange(argv,
else:
parser.error('Please specify an access method.')
if len(args) == 1 and args[0] == 'help':
parser.print_help()
if (not options.files and (not options.issue and options.patchset) and
not options.diff and not options.url):
# TODO(maruel): It should just try the modified files showing up in a
# svn status.
parser.error('Nothing to try, changelist is empty.')
try:
# Convert options.diff into the content of the diff.
if options.url:
if options.files:
parser.error('You cannot specify files and --url at the same time.')
options.diff = urllib.urlopen(options.url).read()
elif options.diff:
if options.files:
parser.error('You cannot specify files and --diff at the same time.')
options.diff = gclient_utils.FileRead(options.diff, 'rb')
# Process the VCS in any case at least to retrieve the email address.
try:
@ -486,8 +484,8 @@ def TryChange(argv,
options.name = 'Unnamed'
print('Note: use --name NAME to change the try job name.')
if not options.email:
print('Warning: TRYBOT_RESULTS_EMAIL_ADDRESS is not set. Try server '
'results might\ngo to: %s@google.com.\n' % options.user)
parser.error('Using an anonymous checkout. Please use --email or set '
'the TRYBOT_RESULTS_EMAIL_ADDRESS environment variable.')
else:
print('Results will be emailed to: ' + options.email)

Loading…
Cancel
Save