Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: scm.py

Issue 6250177: Move reverting code from gclient_scm to scm to be able to reuse the code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix presubmit check Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scm.py
diff --git a/scm.py b/scm.py
index ea91c7b699cf45c933acdde1c590e67acf8db0b0..872b3fe05c5b9c114c783527c319706ae8c8caff 100644
--- a/scm.py
+++ b/scm.py
@@ -6,6 +6,7 @@
import cStringIO
import glob
+import logging
import os
import re
import shutil
@@ -828,3 +829,48 @@ class SVN(object):
elif ver > min_ver:
return (True, SVN.current_version)
return (True, SVN.current_version)
+
+ @staticmethod
+ def Revert(repo_root, callback=None, ignore_externals=False):
+ """Reverts all svn modifications in repo_root, including properties.
+
+ Deletes any modified files or directory.
+
+ A "svn update --revision BASE" call is required after to revive deleted
+ files.
+ """
+ for file_status in SVN.CaptureStatus(repo_root):
+ file_path = os.path.join(repo_root, file_status[1])
+ if ignore_externals and file_status[0][0] == 'X':
+ # Ignore externals.
+ logging.info('Ignoring external %s' % file_status[1])
+ continue
+
+ if callback:
+ callback(file_status)
+
+ if file_status[0].isspace():
+ # Try reverting the file since it's probably a property change.
+ gclient_utils.CheckCall(
+ ['svn', 'revert', file_status[1]], cwd=repo_root)
+
+ # svn revert is really stupid. It fails on inconsistent line-endings,
+ # on switched directories, etc. So take no chance and delete everything!
+ if file_status[0][0] == 'D':
+ # Deleted file requires manual intervention and require calling
+ # revert, like for properties.
+ gclient_utils.CheckCall(
+ ['svn', 'revert', file_status[1]], cwd=repo_root)
+ else:
+ if not os.path.exists(file_path):
+ pass
+ elif os.path.isfile(file_path) or os.path.islink(file_path):
+ logging.info('os.remove(%s)' % file_path)
+ os.remove(file_path)
+ elif os.path.isdir(file_path):
+ logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
+ gclient_utils.RemoveDirectory(file_path)
+ else:
+ logging.critical(
+ ('No idea what is %s.\nYou just found a bug in gclient'
+ ', please ping maruel@chromium.org ASAP!') % file_path)
« no previous file with comments | « presubmit_canned_checks.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698