OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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.6.1' | 9 __version__ = '1.6.1' |
10 | 10 |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 | 551 |
552 class SvnAffectedFile(AffectedFile): | 552 class SvnAffectedFile(AffectedFile): |
553 """Representation of a file in a change out of a Subversion checkout.""" | 553 """Representation of a file in a change out of a Subversion checkout.""" |
554 # Method 'NNN' is abstract in class 'NNN' but is not overridden | 554 # Method 'NNN' is abstract in class 'NNN' but is not overridden |
555 # pylint: disable=W0223 | 555 # pylint: disable=W0223 |
556 | 556 |
557 def __init__(self, *args, **kwargs): | 557 def __init__(self, *args, **kwargs): |
558 AffectedFile.__init__(self, *args, **kwargs) | 558 AffectedFile.__init__(self, *args, **kwargs) |
559 self._server_path = None | 559 self._server_path = None |
560 self._is_text_file = None | 560 self._is_text_file = None |
| 561 self._diff = None |
561 | 562 |
562 def ServerPath(self): | 563 def ServerPath(self): |
563 if self._server_path is None: | 564 if self._server_path is None: |
564 self._server_path = scm.SVN.CaptureLocalInfo( | 565 self._server_path = scm.SVN.CaptureLocalInfo( |
565 [self.LocalPath()], self._local_root).get('URL', '') | 566 [self.LocalPath()], self._local_root).get('URL', '') |
566 return self._server_path | 567 return self._server_path |
567 | 568 |
568 def IsDirectory(self): | 569 def IsDirectory(self): |
569 if self._is_directory is None: | 570 if self._is_directory is None: |
570 path = self.AbsoluteLocalPath() | 571 path = self.AbsoluteLocalPath() |
(...skipping 20 matching lines...) Expand all Loading... |
591 self._is_text_file = False | 592 self._is_text_file = False |
592 elif self.IsDirectory(): | 593 elif self.IsDirectory(): |
593 self._is_text_file = False | 594 self._is_text_file = False |
594 else: | 595 else: |
595 mime_type = scm.SVN.GetFileProperty( | 596 mime_type = scm.SVN.GetFileProperty( |
596 self.LocalPath(), 'svn:mime-type', self._local_root) | 597 self.LocalPath(), 'svn:mime-type', self._local_root) |
597 self._is_text_file = (not mime_type or mime_type.startswith('text/')) | 598 self._is_text_file = (not mime_type or mime_type.startswith('text/')) |
598 return self._is_text_file | 599 return self._is_text_file |
599 | 600 |
600 def GenerateScmDiff(self): | 601 def GenerateScmDiff(self): |
601 return scm.SVN.GenerateDiff( | 602 if self._diff is None: |
602 [self.LocalPath()], self._local_root, False, None) | 603 self._diff = scm.SVN.GenerateDiff( |
| 604 [self.LocalPath()], self._local_root, False, None) |
| 605 return self._diff |
603 | 606 |
604 | 607 |
605 class GitAffectedFile(AffectedFile): | 608 class GitAffectedFile(AffectedFile): |
606 """Representation of a file in a change out of a git checkout.""" | 609 """Representation of a file in a change out of a git checkout.""" |
607 # Method 'NNN' is abstract in class 'NNN' but is not overridden | 610 # Method 'NNN' is abstract in class 'NNN' but is not overridden |
608 # pylint: disable=W0223 | 611 # pylint: disable=W0223 |
609 | 612 |
610 def __init__(self, *args, **kwargs): | 613 def __init__(self, *args, **kwargs): |
611 AffectedFile.__init__(self, *args, **kwargs) | 614 AffectedFile.__init__(self, *args, **kwargs) |
612 self._server_path = None | 615 self._server_path = None |
613 self._is_text_file = None | 616 self._is_text_file = None |
| 617 self._diff = None |
614 | 618 |
615 def ServerPath(self): | 619 def ServerPath(self): |
616 if self._server_path is None: | 620 if self._server_path is None: |
617 raise NotImplementedError('TODO(maruel) Implement.') | 621 raise NotImplementedError('TODO(maruel) Implement.') |
618 return self._server_path | 622 return self._server_path |
619 | 623 |
620 def IsDirectory(self): | 624 def IsDirectory(self): |
621 if self._is_directory is None: | 625 if self._is_directory is None: |
622 path = self.AbsoluteLocalPath() | 626 path = self.AbsoluteLocalPath() |
623 if os.path.exists(path): | 627 if os.path.exists(path): |
(...skipping 14 matching lines...) Expand all Loading... |
638 if self.Action() == 'D': | 642 if self.Action() == 'D': |
639 # A deleted file is not a text file. | 643 # A deleted file is not a text file. |
640 self._is_text_file = False | 644 self._is_text_file = False |
641 elif self.IsDirectory(): | 645 elif self.IsDirectory(): |
642 self._is_text_file = False | 646 self._is_text_file = False |
643 else: | 647 else: |
644 self._is_text_file = os.path.isfile(self.AbsoluteLocalPath()) | 648 self._is_text_file = os.path.isfile(self.AbsoluteLocalPath()) |
645 return self._is_text_file | 649 return self._is_text_file |
646 | 650 |
647 def GenerateScmDiff(self): | 651 def GenerateScmDiff(self): |
648 return scm.GIT.GenerateDiff(self._local_root, files=[self.LocalPath(),]) | 652 if self._diff is None: |
| 653 self._diff = scm.GIT.GenerateDiff( |
| 654 self._local_root, files=[self.LocalPath(),]) |
| 655 return self._diff |
649 | 656 |
650 | 657 |
651 class Change(object): | 658 class Change(object): |
652 """Describe a change. | 659 """Describe a change. |
653 | 660 |
654 Used directly by the presubmit scripts to query the current change being | 661 Used directly by the presubmit scripts to query the current change being |
655 tested. | 662 tested. |
656 | 663 |
657 Instance members: | 664 Instance members: |
658 tags: Dictionnary of KEY=VALUE pairs found in the change description. | 665 tags: Dictionnary of KEY=VALUE pairs found in the change description. |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 except PresubmitFailure, e: | 1265 except PresubmitFailure, e: |
1259 print >> sys.stderr, e | 1266 print >> sys.stderr, e |
1260 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1267 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
1261 print >> sys.stderr, 'If all fails, contact maruel@' | 1268 print >> sys.stderr, 'If all fails, contact maruel@' |
1262 return 2 | 1269 return 2 |
1263 | 1270 |
1264 | 1271 |
1265 if __name__ == '__main__': | 1272 if __name__ == '__main__': |
1266 fix_encoding.fix_encoding() | 1273 fix_encoding.fix_encoding() |
1267 sys.exit(Main(None)) | 1274 sys.exit(Main(None)) |
OLD | NEW |