Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 __version__ = '1.8.0' | 9 __version__ = '1.8.0' |
| 10 | 10 |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 as an absolute path. | 862 as an absolute path. |
| 863 """ | 863 """ |
| 864 return self._local_root | 864 return self._local_root |
| 865 | 865 |
| 866 def __getattr__(self, attr): | 866 def __getattr__(self, attr): |
| 867 """Return tags directly as attributes on the object.""" | 867 """Return tags directly as attributes on the object.""" |
| 868 if not re.match(r"^[A-Z_]*$", attr): | 868 if not re.match(r"^[A-Z_]*$", attr): |
| 869 raise AttributeError(self, attr) | 869 raise AttributeError(self, attr) |
| 870 return self.tags.get(attr) | 870 return self.tags.get(attr) |
| 871 | 871 |
| 872 def AllFiles(self, root=None): | |
| 873 """List all files under source control in the repo.""" | |
| 874 raise NotImplementedError | |
|
M-A Ruel
2014/05/15 01:45:41
raise NotImplementedError()
otherwise you raise th
agable
2014/05/15 01:57:42
Done.
| |
| 875 | |
| 872 def AffectedFiles(self, include_dirs=False, include_deletes=True, | 876 def AffectedFiles(self, include_dirs=False, include_deletes=True, |
| 873 file_filter=None): | 877 file_filter=None): |
| 874 """Returns a list of AffectedFile instances for all files in the change. | 878 """Returns a list of AffectedFile instances for all files in the change. |
| 875 | 879 |
| 876 Args: | 880 Args: |
| 877 include_deletes: If false, deleted files will be filtered out. | 881 include_deletes: If false, deleted files will be filtered out. |
| 878 include_dirs: True to include directories in the list | 882 include_dirs: True to include directories in the list |
| 879 file_filter: An additional filter to apply. | 883 file_filter: An additional filter to apply. |
| 880 | 884 |
| 881 Returns: | 885 Returns: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 all_modified_files.extend( | 962 all_modified_files.extend( |
| 959 [os.path.join(self.RepositoryRoot(), f[1]) for f in cl]) | 963 [os.path.join(self.RepositoryRoot(), f[1]) for f in cl]) |
| 960 return all_modified_files | 964 return all_modified_files |
| 961 | 965 |
| 962 def GetModifiedFiles(self): | 966 def GetModifiedFiles(self): |
| 963 """Get modified files in the current CL.""" | 967 """Get modified files in the current CL.""" |
| 964 changelists = self._GetChangeLists() | 968 changelists = self._GetChangeLists() |
| 965 return [os.path.join(self.RepositoryRoot(), f[1]) | 969 return [os.path.join(self.RepositoryRoot(), f[1]) |
| 966 for f in changelists[self.Name()]] | 970 for f in changelists[self.Name()]] |
| 967 | 971 |
| 972 def AllFiles(self, root=None): | |
| 973 """List all files under source control in the repo.""" | |
|
M-A Ruel
2014/05/15 01:45:41
Lists
agable
2014/05/15 01:56:31
PEP-257: The docstring is a phrase ending in a per
| |
| 974 root = root or self.RepositoryRoot() | |
| 975 return subprocess.check_output( | |
| 976 ['svn', 'ls', '-R', '.'], cwd=root).splitlines() | |
| 977 | |
| 968 | 978 |
| 969 class GitChange(Change): | 979 class GitChange(Change): |
| 970 _AFFECTED_FILES = GitAffectedFile | 980 _AFFECTED_FILES = GitAffectedFile |
| 971 scm = 'git' | 981 scm = 'git' |
| 972 | 982 |
| 983 def AllFiles(self, root=None): | |
| 984 """List all files under source control in the repo.""" | |
|
M-A Ruel
2014/05/15 01:45:41
Lists
agable
2014/05/15 01:56:31
See above.
| |
| 985 root = root or self.RepositoryRoot() | |
| 986 return subprocess.check_output( | |
| 987 ['git', 'ls-files', '--', '.'], cwd=root).splitlines() | |
| 988 | |
| 973 | 989 |
| 974 def ListRelevantPresubmitFiles(files, root): | 990 def ListRelevantPresubmitFiles(files, root): |
| 975 """Finds all presubmit files that apply to a given set of source files. | 991 """Finds all presubmit files that apply to a given set of source files. |
| 976 | 992 |
| 977 If inherit-review-settings-ok is present right under root, looks for | 993 If inherit-review-settings-ok is present right under root, looks for |
| 978 PRESUBMIT.py in directories enclosing root. | 994 PRESUBMIT.py in directories enclosing root. |
| 979 | 995 |
| 980 Args: | 996 Args: |
| 981 files: An iterable container containing file paths. | 997 files: An iterable container containing file paths. |
| 982 root: Path where to stop searching. | 998 root: Path where to stop searching. |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 except PresubmitFailure, e: | 1668 except PresubmitFailure, e: |
| 1653 print >> sys.stderr, e | 1669 print >> sys.stderr, e |
| 1654 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1670 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
| 1655 print >> sys.stderr, 'If all fails, contact maruel@' | 1671 print >> sys.stderr, 'If all fails, contact maruel@' |
| 1656 return 2 | 1672 return 2 |
| 1657 | 1673 |
| 1658 | 1674 |
| 1659 if __name__ == '__main__': | 1675 if __name__ == '__main__': |
| 1660 fix_encoding.fix_encoding() | 1676 fix_encoding.fix_encoding() |
| 1661 sys.exit(Main(None)) | 1677 sys.exit(Main(None)) |
| OLD | NEW |