OLD | NEW |
1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
6 | 6 |
7 import glob | 7 import glob |
8 import os | 8 import os |
9 import re | 9 import re |
10 import shutil | 10 import shutil |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 # since we want the unified diff. Using --diff-cmd=diff doesn't always | 604 # since we want the unified diff. Using --diff-cmd=diff doesn't always |
605 # work, since they can have another diff executable in their path that | 605 # work, since they can have another diff executable in their path that |
606 # gives different line endings. So we use a bogus temp directory as the | 606 # gives different line endings. So we use a bogus temp directory as the |
607 # config directory, which gets around these problems. | 607 # config directory, which gets around these problems. |
608 bogus_dir = tempfile.mkdtemp() | 608 bogus_dir = tempfile.mkdtemp() |
609 try: | 609 try: |
610 # Grabs the diff data. | 610 # Grabs the diff data. |
611 command = ["diff", "--config-dir", bogus_dir, filename] | 611 command = ["diff", "--config-dir", bogus_dir, filename] |
612 if revision: | 612 if revision: |
613 command.extend(['--revision', revision]) | 613 command.extend(['--revision', revision]) |
614 data = SVN.Capture(command, None) | 614 if SVN.IsMoved(filename): |
615 if data: | |
616 pass | |
617 elif SVN.IsMoved(filename): | |
618 if full_move: | 615 if full_move: |
619 file_content = gclient_utils.FileRead(filename, 'rb') | 616 file_content = gclient_utils.FileRead(filename, 'rb') |
620 # Prepend '+' to every lines. | 617 # Prepend '+' to every lines. |
621 file_content = ['+' + i for i in file_content.splitlines(True)] | 618 file_content = ['+' + i for i in file_content.splitlines(True)] |
622 nb_lines = len(file_content) | 619 nb_lines = len(file_content) |
623 # We need to use / since patch on unix will fail otherwise. | 620 # We need to use / since patch on unix will fail otherwise. |
624 data = "Index: %s\n" % filename | 621 data = "Index: %s\n" % filename |
625 data += '=' * 67 + '\n' | 622 data += '=' * 67 + '\n' |
626 # Note: Should we use /dev/null instead? | 623 # Note: Should we use /dev/null instead? |
627 data += "--- %s\n" % filename | 624 data += "--- %s\n" % filename |
628 data += "+++ %s\n" % filename | 625 data += "+++ %s\n" % filename |
629 data += "@@ -0,0 +1,%d @@\n" % nb_lines | 626 data += "@@ -0,0 +1,%d @@\n" % nb_lines |
630 data += ''.join(file_content) | 627 data += ''.join(file_content) |
631 else: | 628 else: |
632 # svn diff on a mv/cp'd file outputs nothing. | 629 # svn diff on a mv/cp'd file outputs nothing if there was no change. |
633 # We put in an empty Index entry so upload.py knows about them. | 630 data = SVN.Capture(command, None) |
634 data = "Index: %s\n" % filename | 631 if not data: |
| 632 # We put in an empty Index entry so upload.py knows about them. |
| 633 data = "Index: %s\n" % filename |
635 else: | 634 else: |
636 # The file is not modified anymore. It should be removed from the set. | 635 data = SVN.Capture(command, None) |
637 pass | |
638 finally: | 636 finally: |
639 shutil.rmtree(bogus_dir) | 637 shutil.rmtree(bogus_dir) |
640 return data | 638 return data |
641 | 639 |
642 @staticmethod | 640 @staticmethod |
643 def GenerateDiff(filenames, root=None, full_move=False, revision=None): | 641 def GenerateDiff(filenames, root=None, full_move=False, revision=None): |
644 """Returns a string containing the diff for the given file list. | 642 """Returns a string containing the diff for the given file list. |
645 | 643 |
646 The files in the list should either be absolute paths or relative to the | 644 The files in the list should either be absolute paths or relative to the |
647 given root. If no root directory is provided, the repository root will be | 645 given root. If no root directory is provided, the repository root will be |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 if not cur_dir_repo_root: | 733 if not cur_dir_repo_root: |
736 return None | 734 return None |
737 | 735 |
738 while True: | 736 while True: |
739 parent = os.path.dirname(directory) | 737 parent = os.path.dirname(directory) |
740 if (SVN.CaptureInfo(parent, print_error=False).get( | 738 if (SVN.CaptureInfo(parent, print_error=False).get( |
741 "Repository Root") != cur_dir_repo_root): | 739 "Repository Root") != cur_dir_repo_root): |
742 break | 740 break |
743 directory = parent | 741 directory = parent |
744 return GetCasedPath(directory) | 742 return GetCasedPath(directory) |
OLD | NEW |