OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 """Usage: %prog [options] [<commitref>]* | 6 """Usage: %prog [options] [<commitref>]* |
7 | 7 |
8 If no <commitref>'s are supplied, it defaults to HEAD. | 8 If no <commitref>'s are supplied, it defaults to HEAD. |
9 | 9 |
10 Calculates the generation number for one or more commits in a git repo. | 10 Calculates the generation number for one or more commits in a git repo. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 help='Do not actually cache anything we calculate.') | 245 help='Do not actually cache anything we calculate.') |
246 parser.add_option('--reset', action='store_true', | 246 parser.add_option('--reset', action='store_true', |
247 help='Reset the generation number cache and quit.') | 247 help='Reset the generation number cache and quit.') |
248 parser.add_option('-v', '--verbose', action='count', default=0, | 248 parser.add_option('-v', '--verbose', action='count', default=0, |
249 help='Be verbose. Use more times for more verbosity.') | 249 help='Be verbose. Use more times for more verbosity.') |
250 opts, args = parser.parse_args() | 250 opts, args = parser.parse_args() |
251 | 251 |
252 levels = [logging.ERROR, logging.INFO, logging.DEBUG] | 252 levels = [logging.ERROR, logging.INFO, logging.DEBUG] |
253 logging.basicConfig(level=levels[min(opts.verbose, len(levels) - 1)]) | 253 logging.basicConfig(level=levels[min(opts.verbose, len(levels) - 1)]) |
254 | 254 |
| 255 # 'git number' should only be used on bots. |
| 256 if os.getenv('CHROME_HEADLESS') != '1': |
| 257 logging.error("'git-number' is an infrastructure tool that is only " |
| 258 "intended to be used internally by bots. Developers should " |
| 259 "use the 'Cr-Commit-Position' value in the commit's message.") |
| 260 return 1 |
| 261 |
255 try: | 262 try: |
256 if opts.reset: | 263 if opts.reset: |
257 clear_caches(on_disk=True) | 264 clear_caches(on_disk=True) |
258 return | 265 return |
259 | 266 |
260 try: | 267 try: |
261 targets = git.parse_commitrefs(*(args or ['HEAD'])) | 268 targets = git.parse_commitrefs(*(args or ['HEAD'])) |
262 except git.BadCommitRefException as e: | 269 except git.BadCommitRefException as e: |
263 parser.error(e) | 270 parser.error(e) |
264 | 271 |
265 load_generation_numbers(targets) | 272 load_generation_numbers(targets) |
266 if not opts.no_cache: | 273 if not opts.no_cache: |
267 finalize(targets) | 274 finalize(targets) |
268 | 275 |
269 print '\n'.join(map(str, map(get_num, targets))) | 276 print '\n'.join(map(str, map(get_num, targets))) |
270 return 0 | 277 return 0 |
271 except KeyboardInterrupt: | 278 except KeyboardInterrupt: |
272 return 1 | 279 return 1 |
273 | 280 |
274 | 281 |
275 if __name__ == '__main__': # pragma: no cover | 282 if __name__ == '__main__': # pragma: no cover |
276 sys.exit(main()) | 283 sys.exit(main()) |
OLD | NEW |