Home | History | Annotate | Download | only in webkitpy
      1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek (at] webkit.org)
      2 #
      3 # Redistribution and use in source and binary forms, with or without
      4 # modification, are permitted provided that the following conditions
      5 # are met:
      6 # 1.  Redistributions of source code must retain the above copyright
      7 #     notice, this list of conditions and the following disclaimer.
      8 # 2.  Redistributions in binary form must reproduce the above copyright
      9 #     notice, this list of conditions and the following disclaimer in the
     10 #     documentation and/or other materials provided with the distribution.
     11 # 
     12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
     13 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     16 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     17 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     18 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     19 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     20 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     21 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     22 
     23 """References to non-style modules used by the style package."""
     24 
     25 # This module is a simple facade to the functionality used by the
     26 # style package that comes from WebKit modules outside the style
     27 # package.
     28 #
     29 # With this module, the only intra-package references (i.e.
     30 # references to webkitpy modules outside the style folder) that
     31 # the style package needs to make are relative references to
     32 # this module. For example--
     33 #
     34 # > from .. style_references import parse_patch
     35 #
     36 # Similarly, people maintaining non-style code are not beholden
     37 # to the contents of the style package when refactoring or
     38 # otherwise changing non-style code. They only have to be aware
     39 # of this module.
     40 
     41 import os
     42 
     43 from diff_parser import DiffParser
     44 from scm import detect_scm_system
     45 
     46 
     47 def parse_patch(patch_string):
     48 
     49     """Parse a patch string and return the affected files."""
     50 
     51     patch = DiffParser(patch_string.splitlines())
     52     return patch.files
     53 
     54 
     55 class SimpleScm(object):
     56 
     57     """Simple facade to SCM for use by style package."""
     58 
     59     def __init__(self):
     60         cwd = os.path.abspath('.')
     61         self._scm = detect_scm_system(cwd)
     62 
     63     def checkout_root(self):
     64         """Return the source control root as an absolute path."""
     65         return self._scm.checkout_root
     66 
     67     def create_patch(self):
     68         return self._scm.create_patch()
     69 
     70     def create_patch_since_local_commit(self, commit):
     71         return self._scm.create_patch_since_local_commit(commit)
     72 
     73