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

Side by Side Diff: git_mark_merge_base.py

Issue 955993006: Handle KeyboardInterrupt consistently in python scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: tweek test expectations 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 Explicitly set/remove/print the merge-base for the current branch. 7 Explicitly set/remove/print the merge-base for the current branch.
8 8
9 This manually set merge base will be a stand-in for `git merge-base` for the 9 This manually set merge base will be a stand-in for `git merge-base` for the
10 purposes of the chromium depot_tools git extensions. Passing no arguments will 10 purposes of the chromium depot_tools git extensions. Passing no arguments will
(...skipping 21 matching lines...) Expand all
32 g.add_argument('--delete', '-d', action='store_true', 32 g.add_argument('--delete', '-d', action='store_true',
33 help='Remove the set mark.') 33 help='Remove the set mark.')
34 opts = parser.parse_args(argv) 34 opts = parser.parse_args(argv)
35 35
36 cur = current_branch() 36 cur = current_branch()
37 37
38 if opts.delete: 38 if opts.delete:
39 try: 39 try:
40 remove_merge_base(cur) 40 remove_merge_base(cur)
41 except CalledProcessError: 41 except CalledProcessError:
42 print "No merge base currently exists for %s." % cur 42 print 'No merge base currently exists for %s.' % cur
43 return 0 43 return 0
44 44
45 if opts.merge_base: 45 if opts.merge_base:
46 try: 46 try:
47 opts.merge_base = hash_one(opts.merge_base) 47 opts.merge_base = hash_one(opts.merge_base)
48 except CalledProcessError: 48 except CalledProcessError:
49 print >> sys.stderr, ( 49 print >> sys.stderr, (
50 'fatal: could not resolve %s as a commit' % (opts.merge_base) 50 'fatal: could not resolve %s as a commit' % (opts.merge_base)
51 ) 51 )
52 return 1 52 return 1
53 53
54 manual_merge_base(cur, opts.merge_base, upstream(cur)) 54 manual_merge_base(cur, opts.merge_base, upstream(cur))
55 55
56 ret = 0 56 ret = 0
57 actual = get_or_create_merge_base(cur) 57 actual = get_or_create_merge_base(cur)
58 if opts.merge_base and opts.merge_base != actual: 58 if opts.merge_base and opts.merge_base != actual:
59 ret = 1 59 ret = 1
60 print "Invalid merge_base %s" % opts.merge_base 60 print "Invalid merge_base %s" % opts.merge_base
61 61
62 print "merge_base(%s): %s" % (cur, actual) 62 print "merge_base(%s): %s" % (cur, actual)
63
64 return ret 63 return ret
65 64
66 65
67 if __name__ == '__main__': 66 if __name__ == '__main__':
68 sys.exit(main(sys.argv[1:])) 67 try:
68 sys.exit(main(sys.argv[1:]))
69 except KeyboardInterrupt:
70 sys.stderr.write('interrupted\n')
71 sys.exit(1)
OLDNEW
« clang_format.py ('K') | « git_map_branches.py ('k') | git_nav_downstream.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698