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

Side by Side Diff: git_auto_svn.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, 9 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
« clang_format.py ('K') | « gclient.py ('k') | git_cache.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 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 """Performs all git-svn setup steps necessary for 'git svn dcommit' to work. 6 """Performs all git-svn setup steps necessary for 'git svn dcommit' to work.
7 7
8 Assumes that trunk of the svn remote maps to master of the git remote. 8 Assumes that trunk of the svn remote maps to master of the git remote.
9 9
10 Example: 10 Example:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, err) 48 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, err)
49 49
50 return ret, err 50 return ret, err
51 51
52 52
53 def main(argv): 53 def main(argv):
54 # No command line flags. Just use the parser to prevent people from trying 54 # No command line flags. Just use the parser to prevent people from trying
55 # to pass flags that don't do anything, and to provide 'usage'. 55 # to pass flags that don't do anything, and to provide 'usage'.
56 parser = argparse.ArgumentParser( 56 parser = argparse.ArgumentParser(
57 description='Automatically set up git-svn for a repo mirrored from svn.') 57 description='Automatically set up git-svn for a repo mirrored from svn.')
58 parser.parse_args(argv[1:]) 58 parser.parse_args(argv)
59 59
60 upstream = root() 60 upstream = root()
61 message = run_git('log', '-1', '--format=%B', upstream) 61 message = run_git('log', '-1', '--format=%B', upstream)
62 footers = parse_footers(message) 62 footers = parse_footers(message)
63 git_svn_id = get_unique(footers, 'git-svn-id') 63 git_svn_id = get_unique(footers, 'git-svn-id')
64 match = GIT_SVN_ID_PATTERN.match(git_svn_id) 64 match = GIT_SVN_ID_PATTERN.match(git_svn_id)
65 assert match, 'No valid git-svn-id footer found on %s.' % upstream 65 assert match, 'No valid git-svn-id footer found on %s.' % upstream
66 print 'Found git-svn-id footer %s on %s' % (match.group(1), upstream) 66 print 'Found git-svn-id footer %s on %s' % (match.group(1), upstream)
67 67
68 parsed_svn = urlparse.urlparse(match.group(1)) 68 parsed_svn = urlparse.urlparse(match.group(1))
(...skipping 19 matching lines...) Expand all
88 continue 88 continue
89 assert svn_repo is not None, 'Unable to find svn repo for %s' % match.group(1) 89 assert svn_repo is not None, 'Unable to find svn repo for %s' % match.group(1)
90 print 'Found upstream svn repo %s and path %s' % (svn_repo, svn_path) 90 print 'Found upstream svn repo %s and path %s' % (svn_repo, svn_path)
91 91
92 set_config('svn-remote.svn.url', svn_repo) 92 set_config('svn-remote.svn.url', svn_repo)
93 set_config('svn-remote.svn.fetch', 93 set_config('svn-remote.svn.fetch',
94 '%s:refs/remotes/%s' % (svn_path, upstream)) 94 '%s:refs/remotes/%s' % (svn_path, upstream))
95 print 'Configured metadata, running "git svn fetch". This may take some time.' 95 print 'Configured metadata, running "git svn fetch". This may take some time.'
96 for line in run_git_stream('svn', 'fetch').xreadlines(): 96 for line in run_git_stream('svn', 'fetch').xreadlines():
97 print line.strip() 97 print line.strip()
98 return 0
98 99
99 100
100 if __name__ == '__main__': 101 if __name__ == '__main__':
101 sys.exit(main(sys.argv)) 102 try:
103 sys.exit(main(sys.argv[1:]))
104 except KeyboardInterrupt:
105 sys.stderr.write('interrupted\n')
106 sys.exit(1)
OLDNEW
« clang_format.py ('K') | « gclient.py ('k') | git_cache.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698