Commit c2190cb2 authored by mhm@chromium.org's avatar mhm@chromium.org

Allow git-try to try rietveld changes directly.

Some external contributors need their CL's try'd quickly, but currently its not easy unless we patch locally. This will allow you to submit the rietveld issue number and will do the rest automatically. As well, renable the dry_run option. It was removed. 

BUG=None 
TEST=git try --issue 12345
Review URL: http://codereview.chromium.org/481006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35881 0039d316-1c4b-4281-b951-d872f2087c98
parent fd9cbbb7
......@@ -28,6 +28,11 @@ def GetRietveldPatchsetNumber():
error_ok=True)
def GetRietveldServerUrl():
return GIT.Capture(
['config', 'rietveld.server'], error_ok=True).strip()
if __name__ == '__main__':
args = sys.argv[:]
patchset = GetRietveldPatchsetNumber()
......@@ -36,6 +41,10 @@ if __name__ == '__main__':
'--issue', GetRietveldIssueNumber(),
'--patchset', patchset,
])
else:
rietveld_url = GetRietveldServerUrl()
if rietveld_url:
args.extend(['--rietveld_url', GetRietveldServerUrl()])
# Hack around a limitation in logging.
logging.getLogger().handlers = []
sys.exit(trychange.TryChange(args, [], False, 'git-try'))
......@@ -39,7 +39,7 @@ class TryChangeUnittest(TryChangeTestsBase):
"""General trychange.py tests."""
def testMembersChanged(self):
members = [
'EscapeDot', 'GIT', 'GuessVCS',
'EscapeDot', 'GIT', 'GuessVCS', 'GetMungedDiff',
'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PrintSuccess',
'SCM', 'SVN', 'TryChange', 'USAGE',
'breakpad', 'datetime', 'errno', 'gclient_utils', 'getpass', 'logging',
......
......@@ -393,6 +393,15 @@ def GuessVCS(options, path):
"Are you in a working copy directory?")
def GetMungedDiff(path_diff, diff):
# Munge paths to match svn.
for i in range(len(diff)):
if diff[i].startswith('--- ') or diff[i].startswith('+++ '):
new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/')
diff[i] = diff[i][0:4] + new_file
return diff
def TryChange(argv,
file_list,
swallow_exception,
......@@ -427,6 +436,8 @@ def TryChange(argv,
help="Update rietveld issue try job status")
group.add_option("--dry_run", action='store_true',
help="Just prints the diff and quits")
group.add_option("--rietveld_url",
help="The code review url.")
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Try job options")
......@@ -558,19 +569,27 @@ def TryChange(argv,
if options.files:
parser.error('You cannot specify files and --diff at the same time.')
options.diff = gclient_utils.FileRead(options.diff, 'rb')
elif options.issue:
# Retrieve the patch from rietveld when the diff is not specified.
try:
import simplejson
except ImportError:
parser.error('simplejson library is missing, please install.')
api_url = 'http://%s/api/%d' % (options.rietveld_url, options.issue)
contents = simplejson.loads(urllib.urlopen(api_url).read())
diff_url = ('http://%s/download/issue%d_%d.diff' %
(options.rietveld_url, options.issue, contents['patchsets'][-1]))
diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines())
options.diff = ''.join(diff)
else:
# Use this as the base.
root = checkouts[0].checkout_root
diffs = []
for checkout in checkouts:
diff = checkout.GenerateDiff().splitlines(True)
# Munge it.
path_diff = gclient_utils.PathDifference(root, checkout.checkout_root)
for i in range(len(diff)):
if diff[i].startswith('--- ') or diff[i].startswith('+++ '):
new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/')
diff[i] = diff[i][0:4] + new_file
diffs.extend(diff)
# Munge it.
diffs.extend(GetMungedDiff(path_diff, diff))
options.diff = ''.join(diffs)
if not options.bot:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment