diff options
Diffstat (limited to 'Tools/Scripts/webkitpy/common/checkout')
-rw-r--r-- | Tools/Scripts/webkitpy/common/checkout/api.py | 4 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/checkout/changelog.py | 21 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/checkout/changelog_unittest.py | 86 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/checkout/deps.py | 61 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/checkout/scm.py | 24 | ||||
-rw-r--r-- | Tools/Scripts/webkitpy/common/checkout/scm_unittest.py | 11 |
6 files changed, 98 insertions, 109 deletions
diff --git a/Tools/Scripts/webkitpy/common/checkout/api.py b/Tools/Scripts/webkitpy/common/checkout/api.py index a87bb5a..170b822 100644 --- a/Tools/Scripts/webkitpy/common/checkout/api.py +++ b/Tools/Scripts/webkitpy/common/checkout/api.py @@ -33,6 +33,7 @@ from webkitpy.common.config import urls from webkitpy.common.checkout.changelog import ChangeLog from webkitpy.common.checkout.commitinfo import CommitInfo from webkitpy.common.checkout.scm import CommitMessage +from webkitpy.common.checkout.deps import DEPS from webkitpy.common.memoized import memoized from webkitpy.common.net.bugzilla import parse_bug_id from webkitpy.common.system.executive import Executive, run_command, ScriptError @@ -148,6 +149,9 @@ class Checkout(object): except ScriptError, e: pass # We might not have ChangeLogs. + def chromium_deps(self): + return DEPS(os.path.join(self._scm.checkout_root, "Source", "WebKit", "chromium", "DEPS")) + def apply_patch(self, patch, force=False): # It's possible that the patch was not made from the root directory. # We should detect and handle that case. diff --git a/Tools/Scripts/webkitpy/common/checkout/changelog.py b/Tools/Scripts/webkitpy/common/checkout/changelog.py index 07f905d..c81318c 100644 --- a/Tools/Scripts/webkitpy/common/checkout/changelog.py +++ b/Tools/Scripts/webkitpy/common/checkout/changelog.py @@ -36,9 +36,7 @@ import textwrap from webkitpy.common.system.deprecated_logging import log from webkitpy.common.config.committers import CommitterList -from webkitpy.common.config import urls from webkitpy.common.net.bugzilla import parse_bug_id -from webkitpy.tool.grammar import join_with_separators class ChangeLogEntry(object): @@ -145,29 +143,14 @@ class ChangeLog(object): lines = [self._wrap_line(line) for line in message.splitlines()] return "\n".join(lines) - # This probably does not belong in changelogs.py - def _message_for_revert(self, revision_list, reason, bug_url): - message = "Unreviewed, rolling out %s.\n" % join_with_separators(['r' + str(revision) for revision in revision_list]) - for revision in revision_list: - message += "%s\n" % urls.view_revision_url(revision) - if bug_url: - message += "%s\n" % bug_url - # Add an extra new line after the rollout links, before any reason. - message += "\n" - if reason: - message += "%s\n\n" % reason - return self._wrap_lines(message) - - def update_for_revert(self, revision_list, reason, bug_url=None): + def update_with_unreviewed_message(self, message): reviewed_by_regexp = re.compile( "%sReviewed by NOBODY \(OOPS!\)\." % self._changelog_indent) removing_boilerplate = False # inplace=1 creates a backup file and re-directs stdout to the file for line in fileinput.FileInput(self.path, inplace=1): if reviewed_by_regexp.search(line): - message_lines = self._message_for_revert(revision_list, - reason, - bug_url) + message_lines = self._wrap_lines(message) print reviewed_by_regexp.sub(message_lines, line), # Remove all the ChangeLog boilerplate between the Reviewed by # line and the first changed file. diff --git a/Tools/Scripts/webkitpy/common/checkout/changelog_unittest.py b/Tools/Scripts/webkitpy/common/checkout/changelog_unittest.py index 20c6cfa..299d509 100644 --- a/Tools/Scripts/webkitpy/common/checkout/changelog_unittest.py +++ b/Tools/Scripts/webkitpy/common/checkout/changelog_unittest.py @@ -142,89 +142,3 @@ class ChangeLogTest(unittest.TestCase): expected_contents = changelog_contents.replace("Need a short description and bug URL (OOPS!)", expected_message) os.remove(changelog_path) self.assertEquals(actual_contents, expected_contents) - - _revert_message = """ Unreviewed, rolling out r12345. - http://trac.webkit.org/changeset/12345 - http://example.com/123 - - This is a very long reason which should be long enough so that - _message_for_revert will need to wrap it. We'll also include - a - https://veryveryveryveryverylongbugurl.com/reallylongbugthingy.cgi?bug_id=12354 - link so that we can make sure we wrap that right too. -""" - - def test_message_for_revert(self): - changelog = ChangeLog("/fake/path") - long_reason = "This is a very long reason which should be long enough so that _message_for_revert will need to wrap it. We'll also include a https://veryveryveryveryverylongbugurl.com/reallylongbugthingy.cgi?bug_id=12354 link so that we can make sure we wrap that right too." - message = changelog._message_for_revert([12345], long_reason, "http://example.com/123") - self.assertEquals(message, self._revert_message) - - _revert_entry_with_bug_url = '''2009-08-19 Eric Seidel <eric@webkit.org> - - Unreviewed, rolling out r12345. - http://trac.webkit.org/changeset/12345 - http://example.com/123 - - Reason - - * Scripts/bugzilla-tool: -''' - - _revert_entry_without_bug_url = '''2009-08-19 Eric Seidel <eric@webkit.org> - - Unreviewed, rolling out r12345. - http://trac.webkit.org/changeset/12345 - - Reason - - * Scripts/bugzilla-tool: -''' - - _multiple_revert_entry_with_bug_url = '''2009-08-19 Eric Seidel <eric@webkit.org> - - Unreviewed, rolling out r12345, r12346, and r12347. - http://trac.webkit.org/changeset/12345 - http://trac.webkit.org/changeset/12346 - http://trac.webkit.org/changeset/12347 - http://example.com/123 - - Reason - - * Scripts/bugzilla-tool: -''' - - _multiple_revert_entry_without_bug_url = '''2009-08-19 Eric Seidel <eric@webkit.org> - - Unreviewed, rolling out r12345, r12346, and r12347. - http://trac.webkit.org/changeset/12345 - http://trac.webkit.org/changeset/12346 - http://trac.webkit.org/changeset/12347 - - Reason - - * Scripts/bugzilla-tool: -''' - - def _assert_update_for_revert_output(self, args, expected_entry): - changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) - changelog_path = self._write_tmp_file_with_contents(changelog_contents.encode("utf-8")) - changelog = ChangeLog(changelog_path) - changelog.update_for_revert(*args) - actual_entry = changelog.latest_entry() - os.remove(changelog_path) - self.assertEquals(actual_entry.contents(), expected_entry) - self.assertEquals(actual_entry.reviewer_text(), None) - # These checks could be removed to allow this to work on other entries: - self.assertEquals(actual_entry.author_name(), "Eric Seidel") - self.assertEquals(actual_entry.author_email(), "eric@webkit.org") - - def test_update_for_revert(self): - self._assert_update_for_revert_output([[12345], "Reason"], self._revert_entry_without_bug_url) - self._assert_update_for_revert_output([[12345], "Reason", "http://example.com/123"], self._revert_entry_with_bug_url) - self._assert_update_for_revert_output([[12345, 12346, 12347], "Reason"], self._multiple_revert_entry_without_bug_url) - self._assert_update_for_revert_output([[12345, 12346, 12347], "Reason", "http://example.com/123"], self._multiple_revert_entry_with_bug_url) - - -if __name__ == '__main__': - unittest.main() diff --git a/Tools/Scripts/webkitpy/common/checkout/deps.py b/Tools/Scripts/webkitpy/common/checkout/deps.py new file mode 100644 index 0000000..6b87ff1 --- /dev/null +++ b/Tools/Scripts/webkitpy/common/checkout/deps.py @@ -0,0 +1,61 @@ +# Copyright (C) 2011, Google Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# WebKit's Python module for parsing and modifying ChangeLog files + +import codecs +import fileinput +import os.path +import re +import textwrap + + +class DEPS(object): + + _variable_regexp = r"\s+'%s':\s+'(?P<value>\d+)'" + + def __init__(self, path): + self._path = path + + def read_variable(self, name): + pattern = re.compile(self._variable_regexp % name) + for line in fileinput.FileInput(self._path): + match = pattern.match(line) + if match: + return int(match.group("value")) + + def write_variable(self, name, value): + pattern = re.compile(self._variable_regexp % name) + replacement_line = " '%s': '%s'" % (name, value) + # inplace=1 creates a backup file and re-directs stdout to the file + for line in fileinput.FileInput(self._path, inplace=1): + if pattern.match(line): + print replacement_line + continue + # Trailing comma suppresses printing newline + print line, diff --git a/Tools/Scripts/webkitpy/common/checkout/scm.py b/Tools/Scripts/webkitpy/common/checkout/scm.py index 421c0dc..3fa2db5 100644 --- a/Tools/Scripts/webkitpy/common/checkout/scm.py +++ b/Tools/Scripts/webkitpy/common/checkout/scm.py @@ -34,10 +34,10 @@ import re import sys import shutil -from webkitpy.common.system.executive import Executive, run_command, ScriptError -from webkitpy.common.system.deprecated_logging import error, log -import webkitpy.common.system.ospath as ospath from webkitpy.common.memoized import memoized +from webkitpy.common.system.deprecated_logging import error, log +from webkitpy.common.system.executive import Executive, run_command, ScriptError +from webkitpy.common.system import ospath def find_checkout_root(): @@ -746,6 +746,22 @@ class Git(SCM): def display_name(self): return "git" + def prepend_svn_revision(self, diff): + revision = None + tries = 0 + while not revision and tries < 10: + # If the git checkout is not tracking an SVN repo, then svn_revision_from_git_commit throws. + try: + revision = self.svn_revision_from_git_commit('HEAD~' + str(tries)) + except: + return diff + tries += 1 + + if not revision: + return diff + + return "Subversion Revision: " + str(revision) + '\n' + diff + def create_patch(self, git_commit=None, changed_files=None): """Returns a byte array (str()) representing the patch file. Patch files are effectively binary since they may contain @@ -753,7 +769,7 @@ class Git(SCM): command = ['git', 'diff', '--binary', "--no-ext-diff", "--full-index", "-M", self.merge_base(git_commit), "--"] if changed_files: command += changed_files - return self.run(command, decode_output=False, cwd=self.checkout_root) + return self.prepend_svn_revision(self.run(command, decode_output=False, cwd=self.checkout_root)) def _run_git_svn_find_rev(self, arg): # git svn find-rev always exits 0, even when the revision or commit is not found. diff --git a/Tools/Scripts/webkitpy/common/checkout/scm_unittest.py b/Tools/Scripts/webkitpy/common/checkout/scm_unittest.py index 64122b4..decfae0 100644 --- a/Tools/Scripts/webkitpy/common/checkout/scm_unittest.py +++ b/Tools/Scripts/webkitpy/common/checkout/scm_unittest.py @@ -810,6 +810,16 @@ class GitTest(SCMTest): run_command(['git', 'config', '--add', 'svn-remote.svn.fetch', 'trunk:remote2']) self.assertEqual(self.tracking_scm.remote_branch_ref(), 'remote1') + def test_create_patch(self): + write_into_file_at_path('test_file_commit1', 'contents') + run_command(['git', 'add', 'test_file_commit1']) + scm = detect_scm_system(self.untracking_checkout_path) + scm.commit_locally_with_message('message') + + patch = scm.create_patch() + self.assertFalse(re.search(r'Subversion Revision:', patch)) + + class GitSVNTest(SCMTest): def _setup_git_checkout(self): @@ -1126,6 +1136,7 @@ class GitSVNTest(SCMTest): patch = scm.create_patch() self.assertTrue(re.search(r'test_file_commit2', patch)) self.assertTrue(re.search(r'test_file_commit1', patch)) + self.assertTrue(re.search(r'Subversion Revision: 5', patch)) def test_create_patch_with_changed_files(self): self._one_local_commit_plus_working_copy_changes() |