OLD | NEW |
---|---|
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 cStringIO | 7 import cStringIO |
8 import glob | 8 import glob |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
854 | 854 |
855 @staticmethod | 855 @staticmethod |
856 def Revert(repo_root, callback=None, ignore_externals=False): | 856 def Revert(repo_root, callback=None, ignore_externals=False): |
857 """Reverts all svn modifications in repo_root, including properties. | 857 """Reverts all svn modifications in repo_root, including properties. |
858 | 858 |
859 Deletes any modified files or directory. | 859 Deletes any modified files or directory. |
860 | 860 |
861 A "svn update --revision BASE" call is required after to revive deleted | 861 A "svn update --revision BASE" call is required after to revive deleted |
862 files. | 862 files. |
863 """ | 863 """ |
864 for file_status in SVN.CaptureStatus(repo_root): | 864 for file_status in SVN.CaptureStatus(repo_root): |
Dirk Pranke
2011/03/14 19:46:05
I wonder if it makes sense at some point to provid
M-A Ruel
2011/03/15 13:42:54
Agreed.
| |
865 file_path = os.path.join(repo_root, file_status[1]) | 865 file_path = os.path.join(repo_root, file_status[1]) |
866 if ignore_externals and file_status[0][0] == 'X': | 866 if (ignore_externals and |
867 file_status[0][0] == 'X' and | |
868 file_status[0][1:].isspace()): | |
867 # Ignore externals. | 869 # Ignore externals. |
868 logging.info('Ignoring external %s' % file_status[1]) | 870 logging.info('Ignoring external %s' % file_status[1]) |
869 continue | 871 continue |
870 | 872 |
871 if callback: | 873 if callback: |
872 callback(file_status) | 874 callback(file_status) |
873 | 875 |
874 if file_status[0].isspace(): | 876 if os.path.exists(file_path): |
875 # Try reverting the file since it's probably a property change. | 877 # svn revert is really stupid. It fails on inconsistent line-endings, |
876 gclient_utils.CheckCall( | 878 # on switched directories, etc. So take no chance and delete everything! |
877 ['svn', 'revert', file_status[1]], cwd=repo_root) | 879 # In theory, it wouldn't be necessary for property-only change but then |
880 # it'd have to look for switched directories, etc so it's not worth | |
881 # optimizing this use case. | |
882 if os.path.isfile(file_path) or os.path.islink(file_path): | |
883 logging.info('os.remove(%s)' % file_path) | |
884 os.remove(file_path) | |
885 elif os.path.isdir(file_path): | |
886 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) | |
887 gclient_utils.RemoveDirectory(file_path) | |
888 else: | |
889 logging.critical( | |
890 ('No idea what is %s.\nYou just found a bug in gclient' | |
891 ', please ping maruel@chromium.org ASAP!') % file_path) | |
878 | 892 |
879 # svn revert is really stupid. It fails on inconsistent line-endings, | 893 if (file_status[0][0] in ('D', 'A', '!') or |
880 # on switched directories, etc. So take no chance and delete everything! | 894 not file_status[0][1:].isspace()): |
881 if file_status[0][0] in ('D', 'A', '!') or file_status[0][2] != ' ': | |
882 # Added, deleted file requires manual intervention and require calling | 895 # Added, deleted file requires manual intervention and require calling |
883 # revert, like for properties. | 896 # revert, like for properties. |
884 try: | 897 try: |
885 SVN.Capture(['revert', file_status[1]], cwd=repo_root) | 898 SVN.Capture(['revert', file_status[1]], cwd=repo_root) |
886 except gclient_utils.CheckCallError: | 899 except gclient_utils.CheckCallError: |
887 if not os.path.exists(file_path): | 900 if not os.path.exists(file_path): |
888 continue | 901 continue |
889 raise | 902 raise |
890 | |
891 if not os.path.exists(file_path): | |
892 continue | |
893 | |
894 if os.path.isfile(file_path) or os.path.islink(file_path): | |
895 logging.info('os.remove(%s)' % file_path) | |
896 os.remove(file_path) | |
897 elif os.path.isdir(file_path): | |
898 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) | |
899 gclient_utils.RemoveDirectory(file_path) | |
900 else: | |
901 logging.critical( | |
902 ('No idea what is %s.\nYou just found a bug in gclient' | |
903 ', please ping maruel@chromium.org ASAP!') % file_path) | |
OLD | NEW |