summaryrefslogtreecommitdiffstats
path: root/tools/git
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 14:25:58 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 14:25:58 +0000
commit1590a8e35d7eed5346c9780e9096aae9206ab4b0 (patch)
treeb6e20405549dcb2875c92102e8a0e895a01b68dc /tools/git
parentfc438406c4239b86fb32db87fbc446bd1adc61cd (diff)
downloadchromium_src-1590a8e35d7eed5346c9780e9096aae9206ab4b0.zip
chromium_src-1590a8e35d7eed5346c9780e9096aae9206ab4b0.tar.gz
chromium_src-1590a8e35d7eed5346c9780e9096aae9206ab4b0.tar.bz2
Miscellaneous fixup for mass-rename.py and friends.
- move_source_file.py now has the option to print out a message rather than raise an exception when given a file that is not a source file. mass-rename.py uses this option to avoid dying when a directory is moved that includes a non-source file (e.g., DEPS). - sort-headers.py now has an option to avoid reordering headers in *message_generator.cc files; changing the include orders in these files can break compilation - sort-headers.py now handles the case where the last line of a file is an include; previously it would die in this case. Review URL: https://chromiumcodereview.appspot.com/17389002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/git')
-rwxr-xr-xtools/git/mass-rename.py3
-rwxr-xr-xtools/git/move_source_file.py34
2 files changed, 26 insertions, 11 deletions
diff --git a/tools/git/mass-rename.py b/tools/git/mass-rename.py
index 89171e5..8efec09 100755
--- a/tools/git/mass-rename.py
+++ b/tools/git/mass-rename.py
@@ -34,7 +34,8 @@ def main():
subprocess.check_call([
sys.executable,
os.path.join(BASE_DIR, 'move_source_file.py'),
- '--already-moved',
+ '--already_moved',
+ '--no_error_for_non_source_file',
fro, to])
else:
print "Skipping: %s -- not a rename?" % fro
diff --git a/tools/git/move_source_file.py b/tools/git/move_source_file.py
index eacdccd..1a953f3 100755
--- a/tools/git/move_source_file.py
+++ b/tools/git/move_source_file.py
@@ -19,6 +19,7 @@ find files that reference the moved file.
"""
+import optparse
import os
import re
import subprocess
@@ -36,6 +37,9 @@ sort_headers = __import__('sort-headers')
HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh']
+def IsHandledFile(path):
+ return os.path.splitext(path)[1] in HANDLED_EXTENSIONS
+
def MakeDestinationPath(from_path, to_path):
"""Given the from and to paths, return a correct destination path.
@@ -43,7 +47,7 @@ def MakeDestinationPath(from_path, to_path):
in which case the path must end with /. Also does basic sanity
checks.
"""
- if os.path.splitext(from_path)[1] not in HANDLED_EXTENSIONS:
+ if not IsHandledFile(from_path):
raise Exception('Only intended to move individual source files. (%s)' %
from_path)
dest_extension = os.path.splitext(to_path)[1]
@@ -84,7 +88,7 @@ def UpdatePostMove(from_path, to_path):
# Reorder headers in files that changed.
for changed_file in files_with_changed_includes:
def AlwaysConfirm(a, b): return True
- sort_headers.FixFileWithConfirmFunction(changed_file, AlwaysConfirm)
+ sort_headers.FixFileWithConfirmFunction(changed_file, AlwaysConfirm, True)
# Update comments; only supports // comments, which are primarily
# used in our code.
@@ -149,25 +153,35 @@ def main():
if not os.path.isdir('.git'):
print 'Fatal: You must run from the root of a git checkout.'
return 1
- args = sys.argv[1:]
- already_moved = False
- if len(args) > 0 and args[0] == '--already-moved':
- args = args[1:]
- already_moved = True
+ parser = optparse.OptionParser(usage='%prog FROM_PATH... TO_PATH')
+ parser.add_option('--already_moved', action='store_true',
+ dest='already_moved',
+ help='Causes the script to skip moving the file.')
+ parser.add_option('--no_error_for_non_source_file', action='store_false',
+ default='True',
+ dest='error_for_non_source_file',
+ help='Causes the script to simply print a warning on '
+ 'encountering a non-source file rather than raising an '
+ 'error.')
+ opts, args = parser.parse_args()
if len(args) < 2:
- print ('Usage: move_source_file.py [--already-moved] FROM_PATH... TO_PATH'
- '\n\n%s' % __doc__)
+ parser.print_help()
return 1
if len(args) > 2 and not args[-1].endswith('/'):
print 'Target %s is not a directory.' % args[-1]
+ print
+ parser.print_help()
return 1
for from_path in args[:len(args)-1]:
+ if not opts.error_for_non_source_file and not IsHandledFile(from_path):
+ print '%s does not appear to be a source file, skipping' % (from_path)
+ continue
to_path = MakeDestinationPath(from_path, args[-1])
- if not already_moved:
+ if not opts.already_moved:
MoveFile(from_path, to_path)
UpdatePostMove(from_path, to_path)
return 0