@ -8,6 +8,8 @@ import tempfile
import traceback
import traceback
import urllib
import urllib
import sys
import sys
import re
import trychange
def Backquote(cmd):
def Backquote(cmd):
@ -93,54 +95,24 @@ def GetMungedDiff(branch):
return munged_diff
return munged_diff
def ValidEmail(email):
return re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email)
def GetEmail():
def GetEmail():
# TODO: check for errors here?
email = Backquote(['git', 'config', 'user.email'])
return Backquote(['git', 'config', 'user.email'])
runmsg = "Try: git config user.email <EMAIL>"
assert ValidEmail(email), "Email '%s' is not valid. %s" % (email, runmsg)
return email
def TryChange(args):
def TryChange(args):
"""Put a patch on the try server using SVN ."""
"""Put a patch on the try server."""
root_dir = Backquote(['git', 'rev-parse', '--show-cdup'])
root_dir = Backquote(['git', 'rev-parse', '--show-cdup'])
script_path = os.path.dirname(sys.argv[0])
sys.path.append(script_path)
try:
import trychange
except ImportError, e:
print "Error trying to import trychange from", script_path
print "git-try expects to live at depot_tools/git-try"
raise e
trychange.checkout_root = os.path.abspath(root_dir)
trychange.checkout_root = os.path.abspath(root_dir)
trychange.TryChange(args, None, False)
trychange.TryChange(args, None, False)
def WriteTryDiffHTTP(config, patch_name, diff, options):
"""Put a patch on the try server."""
params = {
'user': getpass.getuser(),
'name': patch_name,
'patch': diff
}
if GetRietveldPatchsetNumber():
params['issue'] = GetRietveldIssueNumber()
params['patchset'] = GetRietveldPatchsetNumber()
if options.bot:
params['bot'] = options.bot
if options.clobber:
params['clobber'] = 'true'
url = 'http://%s:%s/send_try_patch' % (config['try_server_http_host'],
config['try_server_http_port'])
connection = urllib.urlopen(url, urllib.urlencode(params))
response = connection.read()
if (response != 'OK'):
print "Error posting to", url
print response
assert False
if __name__ == '__main__':
if __name__ == '__main__':
parser = optparse.OptionParser(
parser = optparse.OptionParser(
usage='git try [options] [branch]',
usage='git try [options] [branch]',
@ -161,44 +133,53 @@ if __name__ == '__main__':
patch_name = GetPatchName()
patch_name = GetPatchName()
diff = GetMungedDiff(branch)
diff = GetMungedDiff(branch)
# Send directly to try server if we can parse the config, otherwise
# Write the diff out to a temporary file
diff_file = tempfile.NamedTemporaryFile()
diff_file.write(diff)
diff_file.flush()
email = GetEmail()
user = email.partition('@')[0]
args = [
'-u', user,
'-e', email,
'-n', patch_name,
'--diff', diff_file.name,
]
# Send to try server via HTTP if we can parse the config, otherwise
# upload via SVN.
# upload via SVN.
config = GetTryServerConfig()
config = GetTryServerConfig()
if config is not None:
if config is not None:
print "Sending %s using HTTP..." % patch_name
sendmsg = "Sending %s using HTTP..." % patch_name
WriteTryDiffHTTP(config=config, patch_name=patch_name, diff=diff,
args.extend(['--use_http'])
options=options)
if config['try_server_http_host'] is not None:
args.extend(['--host', config['try_server_http_host']])
if config['try_server_http_port'] is not None:
args.extend(['--port', config['try_server_http_port']])
else:
else:
print "Could not get server config -- if you're within Google, "
print "Could not get server config -- if you're within Google, "
print "do you have have src-internal checked out?"
print "do you have have src-internal checked out?"
print "Sending %s using SVN..." % patch_name
sendmsg = "Sending %s using SVN..." % patch_name
args.extend([
# Write the diff out to a temporary file
'--use_svn', '--svn_repo',
diff_file = tempfile.NamedTemporaryFile()
'svn://svn.chromium.org/chrome-try/try',
diff_file.write(diff)
])
diff_file.flush()
if options.bot:
email = GetEmail()
args.extend(['--bot', options.bot])
user = email.partition('@')[0]
if options.clobber:
args = [
args.append('--clobber')
'--use_svn',
if options.revision:
'--svn_repo', 'svn://svn.chromium.org/chrome-try/try',
args.extend(['-r', options.revision])
'-u', user,
else:
'-e', email,
args.extend(['-r', GetRevision()])
'-n', patch_name,
if GetRietveldPatchsetNumber():
'--diff', diff_file.name,
args.extend([
]
'--issue', GetRietveldIssueNumber(),
if options.bot:
'--patchset', GetRietveldPatchsetNumber(),
args.extend(['--bot', options.bot])
])
if options.clobber:
args.append('--clobber')
print sendmsg
if options.revision:
TryChange(args=args)
args.extend(['-r', options.revision])
else:
args.extend(['-r', GetRevision()])
if GetRietveldPatchsetNumber():
args.extend([
'--issue', GetRietveldIssueNumber(),
'--patchset', GetRietveldPatchsetNumber(),
])
TryChange(args=args)