Commit aa3dd476 authored by maruel@chromium.org's avatar maruel@chromium.org

Use svn update --revision BASE instead of svn revert.

svn revert is broken in too many ways to work around it. I just discovered --revision BASE and it does everything I need.

BUG=none
TEST=gclient revert ignores externals, work with switched directories, work with files with inconsistent line endings (sigh)

Review URL: http://codereview.chromium.org/209052

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@26707 0039d316-1c4b-4281-b951-d872f2087c98
parent 754960e9
...@@ -219,50 +219,41 @@ class SCMWrapper(object): ...@@ -219,50 +219,41 @@ class SCMWrapper(object):
# Don't reuse the args. # Don't reuse the args.
return self.update(options, [], file_list) return self.update(options, [], file_list)
# Batch the command.
files_to_revert = []
for file in CaptureSVNStatus(path): for file in CaptureSVNStatus(path):
file_path = os.path.join(path, file[1]) file_path = os.path.join(path, file[1])
if file_path[0][0] == 'X': if file[0][0] == 'X':
# Ignore externals. # Ignore externals.
logging.info('Ignoring external %s' % file_path)
continue continue
print(file_path) if logging.getLogger().isEnabledFor(logging.INFO):
# Unversioned file, unexpected unversioned files, switched directories logging.info('%s%s' % (file[0], file[1]))
# or conflicted trees. else:
if file[0][0] in ('?', '~') or file[0][4] == 'S' or file[0][6] == 'C': print(file_path)
# Remove then since svn revert won't touch them. if file[0].isspace():
try: logging.error('No idea what is the status of %s.\n'
# TODO(maruel): Look if it is a file or a directory. 'You just found a bug in gclient, please ping '
'maruel@chromium.org ASAP!' % file_path)
# svn revert is really stupid. It fails on inconsistent line-endings,
# on switched directories, etc. So take no chance and delete everything!
try:
if not os.path.exists(file_path):
pass
elif os.path.isfile(file_path):
logging.info('os.remove(%s)' % file_path) logging.info('os.remove(%s)' % file_path)
os.remove(file_path) os.remove(file_path)
except EnvironmentError: elif os.path.isdir(file_path):
logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
gclient_utils.RemoveDirectory(file_path) gclient_utils.RemoveDirectory(file_path)
if file[0][0] != '?':
# For any other status, svn revert will work.
file_list.append(file_path)
files_to_revert.append(file[1])
# Revert them all at once.
if files_to_revert:
accumulated_paths = []
accumulated_length = 0
command = ['revert']
for p in files_to_revert:
# Some shell have issues with command lines too long.
if accumulated_length and accumulated_length + len(p) > 3072:
RunSVN(command + accumulated_paths,
os.path.join(self._root_dir, self.relpath))
accumulated_paths = [p]
accumulated_length = len(p)
else: else:
accumulated_paths.append(p) logging.error('no idea what is %s.\nYou just found a bug in gclient'
accumulated_length += len(p) ', please ping maruel@chromium.org ASAP!' % file_path)
if accumulated_paths: except EnvironmentError:
RunSVN(command + accumulated_paths, logging.error('Failed to remove %s.' % file_path)
os.path.join(self._root_dir, self.relpath))
# svn revert is so broken we don't even use it. Using
# "svn up --revision BASE" achieve the same effect.
RunSVNAndGetFileList(['update', '--revision', 'BASE'], path, file_list)
def status(self, options, args, file_list): def status(self, options, args, file_list):
"""Display status information.""" """Display status information."""
...@@ -578,6 +569,10 @@ def CaptureSVNStatus(files): ...@@ -578,6 +569,10 @@ def CaptureSVNStatus(files):
# Col 3 # Col 3
if wc_status[0].getAttribute('copied') == 'true': if wc_status[0].getAttribute('copied') == 'true':
statuses[3] = '+' statuses[3] = '+'
# Col 4
if wc_status[0].getAttribute('switched') == 'true':
statuses[4] = 'S'
# TODO(maruel): Col 5 and 6
item = (''.join(statuses), file) item = (''.join(statuses), file)
results.append(item) results.append(item)
return results return results
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment