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 os | 10 import os |
10 import re | 11 import re |
11 import shutil | 12 import shutil |
12 import subprocess | 13 import subprocess |
13 import sys | 14 import sys |
14 import tempfile | 15 import tempfile |
15 import time | 16 import time |
16 import xml.dom.minidom | 17 import xml.dom.minidom |
17 | 18 |
18 import gclient_utils | 19 import gclient_utils |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 if not SVN.current_version: | 822 if not SVN.current_version: |
822 SVN.current_version = SVN.Capture(['--version']).split()[2] | 823 SVN.current_version = SVN.Capture(['--version']).split()[2] |
823 current_version_list = map(only_int, SVN.current_version.split('.')) | 824 current_version_list = map(only_int, SVN.current_version.split('.')) |
824 for min_ver in map(int, min_version.split('.')): | 825 for min_ver in map(int, min_version.split('.')): |
825 ver = current_version_list.pop(0) | 826 ver = current_version_list.pop(0) |
826 if ver < min_ver: | 827 if ver < min_ver: |
827 return (False, SVN.current_version) | 828 return (False, SVN.current_version) |
828 elif ver > min_ver: | 829 elif ver > min_ver: |
829 return (True, SVN.current_version) | 830 return (True, SVN.current_version) |
830 return (True, SVN.current_version) | 831 return (True, SVN.current_version) |
| 832 |
| 833 @staticmethod |
| 834 def Revert(repo_root, callback=None, ignore_externals=False): |
| 835 """Reverts all svn modifications in repo_root, including properties. |
| 836 |
| 837 Deletes any modified files or directory. |
| 838 |
| 839 A "svn update --revision BASE" call is required after to revive deleted |
| 840 files. |
| 841 """ |
| 842 for file_status in SVN.CaptureStatus(repo_root): |
| 843 file_path = os.path.join(repo_root, file_status[1]) |
| 844 if ignore_externals and file_status[0][0] == 'X': |
| 845 # Ignore externals. |
| 846 logging.info('Ignoring external %s' % file_status[1]) |
| 847 continue |
| 848 |
| 849 if callback: |
| 850 callback(file_status) |
| 851 |
| 852 if file_status[0].isspace(): |
| 853 # Try reverting the file since it's probably a property change. |
| 854 gclient_utils.CheckCall( |
| 855 ['svn', 'revert', file_status[1]], cwd=repo_root) |
| 856 |
| 857 # svn revert is really stupid. It fails on inconsistent line-endings, |
| 858 # on switched directories, etc. So take no chance and delete everything! |
| 859 if file_status[0][0] == 'D': |
| 860 # Deleted file requires manual intervention and require calling |
| 861 # revert, like for properties. |
| 862 gclient_utils.CheckCall( |
| 863 ['svn', 'revert', file_status[1]], cwd=repo_root) |
| 864 else: |
| 865 if not os.path.exists(file_path): |
| 866 pass |
| 867 elif os.path.isfile(file_path) or os.path.islink(file_path): |
| 868 logging.info('os.remove(%s)' % file_path) |
| 869 os.remove(file_path) |
| 870 elif os.path.isdir(file_path): |
| 871 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) |
| 872 gclient_utils.RemoveDirectory(file_path) |
| 873 else: |
| 874 logging.critical( |
| 875 ('No idea what is %s.\nYou just found a bug in gclient' |
| 876 ', please ping maruel@chromium.org ASAP!') % file_path) |
OLD | NEW |