Diff
Modified: trunk/Tools/ChangeLog (116934 => 116935)
--- trunk/Tools/ChangeLog 2012-05-14 12:08:16 UTC (rev 116934)
+++ trunk/Tools/ChangeLog 2012-05-14 12:31:07 UTC (rev 116935)
@@ -1,3 +1,33 @@
+2012-05-14 Balazs Ankes <[email protected]>
+
+ webkit-patch land should automatically add svn:mime-type for .png files
+ https://bugs.webkit.org/show_bug.cgi?id=75825
+ I refactored the png.py to avoid code duplication.
+
+ Reviewed by Dirk Pranke.
+
+ * Scripts/webkitpy/common/checksvnconfigfile.py: Added.
+ (check):
+ (_config_file_path):
+ (errorstr_autoprop):
+ (errorstr_png):
+ * Scripts/webkitpy/style/checkers/png.py:
+ (PNGChecker.check):
+ * Scripts/webkitpy/tool/commands/download.py:
+ (Land):
+ * Scripts/webkitpy/tool/steps/__init__.py:
+ * Scripts/webkitpy/tool/steps/addsvnmimetypeforpng.py: Added.
+ (AddSvnMimetypeForPng):
+ (AddSvnMimetypeForPng.__init__):
+ (AddSvnMimetypeForPng.run):
+ (AddSvnMimetypeForPng._check_pngs):
+ * Scripts/webkitpy/tool/steps/addsvnmimetypeforpng_unittest.py: Added.
+ (MockSCMDetector):
+ (MockSCMDetector.__init__):
+ (MockSCMDetector.display_name):
+ (AddSvnMimetypeForPngTest):
+ (AddSvnMimetypeForPngTest.test_run):
+
2012-05-14 David Kilzer <[email protected]>
webkit-patch apply-attachment is very slow for big patches
Added: trunk/Tools/Scripts/webkitpy/common/checksvnconfigfile.py (0 => 116935)
--- trunk/Tools/Scripts/webkitpy/common/checksvnconfigfile.py (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/checksvnconfigfile.py 2012-05-14 12:31:07 UTC (rev 116935)
@@ -0,0 +1,83 @@
+# Copyright (C) 2012 Balazs Ankes ([email protected]) University of Szeged
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. 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.
+#
+# 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.
+
+# This file is used by:
+# webkitpy/tool/steps/addsvnmimetypeforpng.py
+# webkitpy/style/checkers/png.py
+
+import os
+import re
+
+
+def check(self, host, fs):
+ """
+ check the svn config file
+ return with three logical value:
+ was the file read successful, is there enable the auto-props, is there enable the svn:mime-type for png
+ """
+
+ config_file_path = _config_file_path(self, host, fs)
+ there_is_enable_line = False
+ there_is_png_line = False
+
+ try:
+ config_file = fs.read_text_file(config_file_path)
+ except IOError:
+ return (True, True, True)
+
+ errorcode_autoprop = True
+ errorcode_png = True
+
+ for line in config_file.split('\n'):
+ if not there_is_enable_line:
+ match = re.search("^\s*enable-auto-props\s*=\s*yes", line)
+ if match:
+ there_is_enable_line = True
+ errorcode_autoprop = False
+ continue
+
+ if not there_is_png_line:
+ match = re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", line)
+ if match:
+ there_is_png_line = True
+ errorcode_png = False
+ continue
+
+ return (False, errorcode_autoprop, errorcode_png)
+
+
+def _config_file_path(self, host, fs):
+ config_file = ""
+ if host.platform.is_win():
+ config_file_path = fs.join(os.environ['APPDATA'], "Subversion\config")
+ else:
+ config_file_path = fs.join(fs.expanduser("~"), ".subversion/config")
+ return config_file_path
+
+
+def errorstr_autoprop(config_file_path):
+ return "Have to enable auto props in the subversion config file (" + config_file_path + " \"enable-auto-props = yes\"). "
+
+
+def errorstr_png(config_file_path):
+ return "Have to set the svn:mime-type in the subversion config file (" + config_file_path + " \"*.png = svn:mime-type=image/png\")."
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/png.py (116934 => 116935)
--- trunk/Tools/Scripts/webkitpy/style/checkers/png.py 2012-05-14 12:08:16 UTC (rev 116934)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/png.py 2012-05-14 12:31:07 UTC (rev 116935)
@@ -27,6 +27,7 @@
import os
import re
+from webkitpy.common import checksvnconfigfile
from webkitpy.common.system.systemhost import SystemHost
from webkitpy.common.checkout.scm.detection import SCMDetector
@@ -44,54 +45,24 @@
self._detector = scm or SCMDetector(self._fs, self._host.executive).detect_scm_system(self._fs.getcwd())
def check(self, inline=None):
- errorstr = ""
config_file_path = ""
detection = self._detector.display_name()
if detection == "git":
- config_file_path = self._config_file_path()
- there_is_enable_line = False
- there_is_png_line = False
+ (file_read, autoprop, png) = checksvnconfigfile.check(self, self._host, self._fs)
+ config_file_path = checksvnconfigfile._config_file_path(self, self._host, self._fs)
- try:
- config_file = self._fs.read_text_file(config_file_path)
- except IOError:
- errorstr = "There is no " + config_file_path
- self._handle_style_error(0, 'image/png', 5, errorstr)
- return
+ if file_read:
+ self._handle_style_error(0, 'image/png', 5, "There is no SVN config file. (" + config_file_path + ")")
+ elif autoprop and png:
+ self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file_path))
+ elif autoprop:
+ self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path))
+ elif png:
+ self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_png(config_file_path))
- errorstr_autoprop = "Have to enable auto props in the subversion config file (" + config_file_path + " \"enable-auto-props = yes\"). "
- errorstr_png = "Have to set the svn:mime-type in the subversion config file (" + config_file_path + " \"*.png = svn:mime-type=image/png\")."
-
- for line in config_file.split('\n'):
- if not there_is_enable_line:
- match = re.search("^\s*enable-auto-props\s*=\s*yes", line)
- if match:
- there_is_enable_line = True
- errorstr_autoprop = ""
- continue
-
- if not there_is_png_line:
- match = re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", line)
- if match:
- there_is_png_line = True
- errorstr_png = ""
- continue
-
- errorstr = errorstr_autoprop + errorstr_png
- if errorstr:
- self._handle_style_error(0, 'image/png', 5, errorstr)
-
elif detection == "svn":
prop_get = self._detector.propget("svn:mime-type", self._file_path)
if prop_get != "image/png":
errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png " + self._file_path + ")."
self._handle_style_error(0, 'image/png', 5, errorstr)
-
- def _config_file_path(self):
- config_file = ""
- if self._host.platform.is_win():
- config_file_path = self._fs.join(os.environ['APPDATA'], "Subversion\config")
- else:
- config_file_path = self._fs.join(self._fs.expanduser("~"), ".subversion/config")
- return config_file_path
Modified: trunk/Tools/Scripts/webkitpy/tool/commands/download.py (116934 => 116935)
--- trunk/Tools/Scripts/webkitpy/tool/commands/download.py 2012-05-14 12:08:16 UTC (rev 116934)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/download.py 2012-05-14 12:31:07 UTC (rev 116935)
@@ -90,6 +90,7 @@
argument_names = "[BUGID]"
show_in_main_help = True
steps = [
+ steps.AddSvnMimetypeForPng,
steps.UpdateChangeLogsWithReviewer,
steps.ValidateReviewer,
steps.ValidateChangeLogs, # We do this after UpdateChangeLogsWithReviewer to avoid not having to cache the diff twice.
Modified: trunk/Tools/Scripts/webkitpy/tool/steps/__init__.py (116934 => 116935)
--- trunk/Tools/Scripts/webkitpy/tool/steps/__init__.py 2012-05-14 12:08:16 UTC (rev 116934)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/__init__.py 2012-05-14 12:31:07 UTC (rev 116935)
@@ -27,6 +27,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# FIXME: Is this the right way to do this?
+from webkitpy.tool.steps.addsvnmimetypeforpng import AddSvnMimetypeForPng
from webkitpy.tool.steps.applypatch import ApplyPatch
from webkitpy.tool.steps.applypatchwithlocalcommit import ApplyPatchWithLocalCommit
from webkitpy.tool.steps.applywatchlist import ApplyWatchList
Added: trunk/Tools/Scripts/webkitpy/tool/steps/addsvnmimetypeforpng.py (0 => 116935)
--- trunk/Tools/Scripts/webkitpy/tool/steps/addsvnmimetypeforpng.py (rev 0)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/addsvnmimetypeforpng.py 2012-05-14 12:31:07 UTC (rev 116935)
@@ -0,0 +1,77 @@
+# Copyright (C) 2012 Balazs Ankes ([email protected]) University of Szeged
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. 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.
+#
+# 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.
+
+from webkitpy.tool.steps.abstractstep import AbstractStep
+from webkitpy.common import checksvnconfigfile
+from webkitpy.common.system.deprecated_logging import log
+from webkitpy.common.checkout.scm.detection import SCMDetector
+from webkitpy.common.system.systemhost import SystemHost
+
+
+class AddSvnMimetypeForPng(AbstractStep):
+ def __init__(self, tool, options, host=None, scm=None):
+ self._tool = tool
+ self._options = options
+ self._host = host or SystemHost()
+ self._fs = self._host.filesystem
+ self._detector = scm or SCMDetector(self._fs, self._host.executive).detect_scm_system(self._fs.getcwd())
+
+ def run(self, state):
+ png_files = self._check_pngs(self._changed_files(state))
+
+ if len(png_files) > 0:
+ detection = self._detector.display_name()
+
+ if detection == "git":
+ (file_read, autoprop, png) = checksvnconfigfile.check(self, self._host, self._fs)
+ config_file_path = checksvnconfigfile._config_file_path(self, self._host, self._fs)
+
+ if file_read:
+ log("There is no SVN config file. The svn:mime-type of pngs won't set.")
+ if not self._tool.user.confirm("Are you sure you want to continue?", default="n"):
+ self._exit(1)
+ elif autoprop and png:
+ log(checksvnconfigfile.errorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file_path))
+ if not self._tool.user.confirm("Do you want to continue?", default="n"):
+ self._exit(1)
+ elif autoprop:
+ log(checksvnconfigfile.errorstr_autoprop(config_file_path))
+ if not self._tool.user.confirm("Do you want to continue?", default="n"):
+ self._exit(1)
+ elif png:
+ log(checksvnconfigfile.errorstr_png(config_file_path))
+ if not self._tool.user.confirm("Do you want to continue?", default="n"):
+ self._exit(1)
+
+ elif detection == "svn":
+ for filename in png_files:
+ if filename.endswith('.png') and detector.exists(filename) and detector.propget('svn:mime-type', filename) == "":
+ print "Adding image/png mime-type to %s" % filename
+ detector.propset('svn:mime-type', 'image/png', filename)
+
+ def _check_pngs(self, changed_files):
+ png_files = []
+ for filename in changed_files:
+ if filename.endswith('.png'):
+ png_files.append(filename)
+ return png_files
Added: trunk/Tools/Scripts/webkitpy/tool/steps/addsvnmimetypeforpng_unittest.py (0 => 116935)
--- trunk/Tools/Scripts/webkitpy/tool/steps/addsvnmimetypeforpng_unittest.py (rev 0)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/addsvnmimetypeforpng_unittest.py 2012-05-14 12:31:07 UTC (rev 116935)
@@ -0,0 +1,60 @@
+# Copyright (C) 2012 Balazs Ankes ([email protected]) University of Szeged
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. 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.
+#
+# 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.
+
+import unittest
+
+from webkitpy.tool.steps.addsvnmimetypeforpng import AddSvnMimetypeForPng
+from webkitpy.common.system.filesystem_mock import MockFileSystem
+from webkitpy.tool.mocktool import MockOptions, MockTool
+from webkitpy.common.system.systemhost_mock import MockSystemHost
+from webkitpy.common.system.outputcapture import OutputCapture
+
+
+class MockSCMDetector(object):
+
+ def __init__(self, scm):
+ self._scm = scm
+
+ def display_name(self):
+ return self._scm
+
+
+class AddSvnMimetypeForPngTest(unittest.TestCase):
+ def test_run(self):
+ capture = OutputCapture()
+ options = MockOptions()
+ options.git_commit = 'MOCK git commit'
+
+ files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.png = svn:mime-type=image/png'}
+ fs = MockFileSystem(files)
+ scm = MockSCMDetector('git')
+
+ step = AddSvnMimetypeForPng(MockTool(), options, MockSystemHost(os_name='linux', filesystem=fs), scm)
+ state = {
+ "changed_files": ["test.png"],
+ }
+ try:
+ capture.assert_outputs(self, step.run, [state])
+ except SystemExit, e:
+ self.assertEquals(type(e), type(SystemExit()))
+ self.assertEquals(e.code, 1)