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

Side by Side Diff: tools/git/for-all-touched-files.py

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « tools/clang/scripts/update.sh ('k') | tools/git/move_source_file.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Invokes the specified (quoted) command for all files modified 7 Invokes the specified (quoted) command for all files modified
8 between the current git branch and the specified branch or commit. 8 between the current git branch and the specified branch or commit.
9 9
10 The special token [[FILENAME]] (or whatever you choose using the -t 10 The special token [[FILENAME]] (or whatever you choose using the -t
11 flag) is replaced with each of the filenames of new or modified files. 11 flag) is replaced with each of the filenames of new or modified files.
12 12
13 Deleted files are not included. Neither are untracked files. 13 Deleted files are not included. Neither are untracked files.
14 14
15 Synopsis: 15 Synopsis:
16 %prog [-b BRANCH] [-d] [-x EXTENSIONS|-c] [-t TOKEN] QUOTED_COMMAND 16 %prog [-b BRANCH] [-d] [-x EXTENSIONS|-c|-g] [-t TOKEN] QUOTED_COMMAND
17 17
18 Examples: 18 Examples:
19 %prog -x gyp,gypi "tools/format_xml.py [[FILENAME]]" 19 %prog -x gyp,gypi "tools/format_xml.py [[FILENAME]]"
20 %prog -c "tools/sort-headers.py [[FILENAME]]" 20 %prog -c "tools/sort-headers.py [[FILENAME]]"
21 %prog -g "tools/sort_sources.py [[FILENAME]]"
21 %prog -t "~~BINGO~~" "echo I modified ~~BINGO~~" 22 %prog -t "~~BINGO~~" "echo I modified ~~BINGO~~"
22 """ 23 """
23 24
24 import optparse 25 import optparse
25 import os 26 import os
26 import subprocess 27 import subprocess
27 import sys 28 import sys
28 29
29 30
30 # List of C++-like source file extensions. 31 # List of C++-like source file extensions.
31 _CPP_EXTENSIONS = ('h', 'hh', 'hpp', 'c', 'cc', 'cpp', 'cxx', 'mm',) 32 _CPP_EXTENSIONS = ('h', 'hh', 'hpp', 'c', 'cc', 'cpp', 'cxx', 'mm',)
33 # List of build file extensions.
34 _BUILD_EXTENSIONS = ('gyp', 'gypi', 'gn',)
32 35
33 36
34 def GitShell(args, ignore_return=False): 37 def GitShell(args, ignore_return=False):
35 """A shell invocation suitable for communicating with git. Returns 38 """A shell invocation suitable for communicating with git. Returns
36 output as list of lines, raises exception on error. 39 output as list of lines, raises exception on error.
37 """ 40 """
38 job = subprocess.Popen(args, 41 job = subprocess.Popen(args,
39 shell=True, 42 shell=True,
40 stdout=subprocess.PIPE, 43 stdout=subprocess.PIPE,
41 stderr=subprocess.STDOUT) 44 stderr=subprocess.STDOUT)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 87
85 88
86 def main(): 89 def main():
87 parser = optparse.OptionParser(usage=__doc__) 90 parser = optparse.OptionParser(usage=__doc__)
88 parser.add_option('-x', '--extensions', default='', dest='extensions', 91 parser.add_option('-x', '--extensions', default='', dest='extensions',
89 help='Limits to files with given extensions ' 92 help='Limits to files with given extensions '
90 '(comma-separated).') 93 '(comma-separated).')
91 parser.add_option('-c', '--cpp', default=False, action='store_true', 94 parser.add_option('-c', '--cpp', default=False, action='store_true',
92 dest='cpp_only', 95 dest='cpp_only',
93 help='Runs your command only on C++-like source files.') 96 help='Runs your command only on C++-like source files.')
97 # -g stands for GYP and GN.
98 parser.add_option('-g', '--build', default=False, action='store_true',
99 dest='build_only',
100 help='Runs your command only on build files.')
94 parser.add_option('-t', '--token', default='[[FILENAME]]', dest='token', 101 parser.add_option('-t', '--token', default='[[FILENAME]]', dest='token',
95 help='Sets the token to be replaced for each file ' 102 help='Sets the token to be replaced for each file '
96 'in your command (default [[FILENAME]]).') 103 'in your command (default [[FILENAME]]).')
97 parser.add_option('-b', '--branch', default='origin/master', dest='branch', 104 parser.add_option('-b', '--branch', default='origin/master', dest='branch',
98 help='Sets what to diff to (default origin/master). Set ' 105 help='Sets what to diff to (default origin/master). Set '
99 'to empty to diff workspace against HEAD.') 106 'to empty to diff workspace against HEAD.')
100 opts, args = parser.parse_args() 107 opts, args = parser.parse_args()
101 108
102 if not args: 109 if not args:
103 parser.print_help() 110 parser.print_help()
104 sys.exit(1) 111 sys.exit(1)
105 112
113 if opts.cpp_only and opts.build_only:
114 parser.error("--cpp and --build are mutually exclusive")
115
106 extensions = opts.extensions 116 extensions = opts.extensions
107 if opts.cpp_only: 117 if opts.cpp_only:
108 extensions = _CPP_EXTENSIONS 118 extensions = _CPP_EXTENSIONS
119 if opts.build_only:
120 extensions = _BUILD_EXTENSIONS
109 121
110 ForAllTouchedFiles(opts.branch, extensions, opts.token, args[0]) 122 ForAllTouchedFiles(opts.branch, extensions, opts.token, args[0])
111 123
112 124
113 if __name__ == '__main__': 125 if __name__ == '__main__':
114 main() 126 main()
OLDNEW
« no previous file with comments | « tools/clang/scripts/update.sh ('k') | tools/git/move_source_file.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698