From 5953f3f4239ee35527bcbafb6e03da3218826aab Mon Sep 17 00:00:00 2001 From: "ilevy@chromium.org" Date: Mon, 18 Mar 2013 19:35:10 +0000 Subject: [PATCH] Extend drover so it can revert any chrome revision. * Use base chrome svn url for reverts to work with branches and tools repos. * Add heuristic to drover so it can search multiple svn repos for the likely revision to revert. Each of chrome, chrome-internal, native_client are separated by more than 20k revisions, so we can programmatically determine which repo the user wants to revert with high confidence. TESTS= - pylint (part of presubmit) - tried recent tools/build chrome revision - tried NaCl revision - tried NaCl revision with --no-alt-urls (got rev from chrome) - tried NaCl without valid svn credentials (got rev from chrome) Review URL: https://chromiumcodereview.appspot.com/12670008 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@188792 0039d316-1c4b-4281-b951-d872f2087c98 --- drover.py | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/drover.py b/drover.py index 22e9b7d79..945b97e0b 100755 --- a/drover.py +++ b/drover.py @@ -3,6 +3,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import datetime import optparse import os import re @@ -72,15 +73,13 @@ def gclUpload(revision, author): def getSVNInfo(url, revision): info = {} - try: - svn_info = subprocess2.check_output( - ['svn', 'info', '%s@%s' % (url, revision)]).splitlines() - for line in svn_info: - match = re.search(r"(.*?):(.*)", line) - if match: - info[match.group(1).strip()] = match.group(2).strip() - except subprocess2.CalledProcessError: - pass + svn_info = subprocess2.capture( + ['svn', 'info', '--non-interactive', '%s@%s' % (url, revision)], + stderr=subprocess2.VOID).splitlines() + for line in svn_info: + match = re.search(r"(.*?):(.*)", line) + if match: + info[match.group(1).strip()] = match.group(2).strip() return info def isSVNDirty(): @@ -491,6 +490,8 @@ def drover(options, args): # Initialize some variables used below. They can be overwritten by # the drover.properties file. BASE_URL = "svn://svn.chromium.org/chrome" + REVERT_ALT_URLS = ['svn://svn.chromium.org/chrome-internal', + 'svn://svn.chromium.org/native_client'] TRUNK_URL = BASE_URL + "/trunk/src" BRANCH_URL = BASE_URL + "/branches/$branch/src" SKIP_CHECK_WORKING = True @@ -521,11 +522,12 @@ def drover(options, args): file_pattern_ = FILE_PATTERN if options.revert and options.branch: + print 'Note: --branch is usually not needed for reverts.' url = BRANCH_URL.replace("$branch", options.branch) elif options.merge and options.sbranch: url = BRANCH_URL.replace("$branch", options.sbranch) - elif options.revert and options.url: - url = options.url + elif options.revert: + url = options.url or BASE_URL file_pattern_ = r"[ ]+([MADUC])[ ]+((/.*)/(.*))" else: url = TRUNK_URL @@ -541,6 +543,20 @@ def drover(options, args): prompt("Working copy contains uncommitted files. Continue?")): return 1 + if options.revert and not options.no_alt_urls: + for cur_url in [url] + REVERT_ALT_URLS: + try: + commit_date_str = getSVNInfo( + cur_url, options.revert).get('Last Changed Date', 'x').split()[0] + commit_date = datetime.datetime.strptime(commit_date_str, '%Y-%m-%d') + if (datetime.datetime.now() - commit_date).days < 120: + if cur_url != url: + print 'Guessing svn repo: %s.' % cur_url, + print 'Use --no-alt-urls to disable heuristic.' + url = cur_url + break + except ValueError: + pass command = 'svn log ' + url + " -r "+str(revision) + " -v" os.system(command) @@ -572,8 +588,6 @@ def drover(options, args): deleteRevision(url, revision) elif options.revert: action = "Revert" - if options.branch: - url = BRANCH_URL.replace("$branch", options.branch) pop_em = not options.url checkoutRevision(url, revision, url, True, pop_em) revertRevision(url, revision) @@ -672,11 +686,13 @@ def main(): help='svn url to use for the revert') option_parser.add_option('-a', '--auditor', help='overrides the author for reviewer') - option_parser.add_option('', '--revertbot', action='store_true', + option_parser.add_option('--revertbot', action='store_true', default=False) - option_parser.add_option('', '--revertbot-commit', action='store_true', + option_parser.add_option('--no-alt-urls', action='store_true', + help='Disable heuristics used to determine svn url') + option_parser.add_option('--revertbot-commit', action='store_true', default=False) - option_parser.add_option('', '--revertbot-reviewers') + option_parser.add_option('--revertbot-reviewers') options, args = option_parser.parse_args() if not options.merge and not options.revert: