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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. | 255 # 'git number' should only be used on bots. |
256 if os.getenv('CHROME_HEADLESS') != '1': | 256 if os.getenv('CHROME_HEADLESS') != '1': |
257 logging.error("'git-number' is an infrastructure tool that is only " | 257 logging.error("'git-number' is an infrastructure tool that is only " |
258 "intended to be used internally by bots. Developers should " | 258 "intended to be used internally by bots. Developers should " |
259 "use the 'Cr-Commit-Position' value in the commit's message.") | 259 "use the 'Cr-Commit-Position' value in the commit's message.") |
260 return 1 | 260 return 1 |
261 | 261 |
| 262 if opts.reset: |
| 263 clear_caches(on_disk=True) |
| 264 return |
| 265 |
262 try: | 266 try: |
263 if opts.reset: | 267 targets = git.parse_commitrefs(*(args or ['HEAD'])) |
264 clear_caches(on_disk=True) | 268 except git.BadCommitRefException as e: |
265 return | 269 parser.error(e) |
266 | 270 |
267 try: | 271 load_generation_numbers(targets) |
268 targets = git.parse_commitrefs(*(args or ['HEAD'])) | 272 if not opts.no_cache: |
269 except git.BadCommitRefException as e: | 273 finalize(targets) |
270 parser.error(e) | |
271 | 274 |
272 load_generation_numbers(targets) | 275 print '\n'.join(map(str, map(get_num, targets))) |
273 if not opts.no_cache: | 276 return 0 |
274 finalize(targets) | |
275 | |
276 print '\n'.join(map(str, map(get_num, targets))) | |
277 return 0 | |
278 except KeyboardInterrupt: | |
279 return 1 | |
280 | 277 |
281 | 278 |
282 if __name__ == '__main__': # pragma: no cover | 279 if __name__ == '__main__': # pragma: no cover |
283 sys.exit(main()) | 280 try: |
| 281 sys.exit(main()) |
| 282 except KeyboardInterrupt: |
| 283 sys.stderr.write('interrupted\n') |
| 284 sys.exit(1) |
OLD | NEW |