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

Side by Side Diff: git_auto_svn.py

Issue 1135563005: Improve "dcommit in git repo" error message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: also improve 'land' warning Created 5 years, 6 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
« no previous file with comments | « no previous file | git_cl.py » ('j') | git_cl.py » ('J')
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 cmd = (SVN_EXE,) + cmd 43 cmd = (SVN_EXE,) + cmd
44 proc = subprocess2.Popen(cmd, **kwargs) 44 proc = subprocess2.Popen(cmd, **kwargs)
45 ret, err = proc.communicate() 45 ret, err = proc.communicate()
46 retcode = proc.wait() 46 retcode = proc.wait()
47 if retcode != 0: 47 if retcode != 0:
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 get_footer_svn_id(branch=None):
54 if not branch:
55 branch = root()
56 svn_id = None
57 message = run_git('log', '-1', '--format=%B', branch)
58 footers = parse_footers(message)
59 git_svn_id = get_unique(footers, 'git-svn-id')
60 match = GIT_SVN_ID_PATTERN.match(git_svn_id)
61 if match:
62 svn_id = match.group(1)
63 return svn_id
64
65
53 def main(argv): 66 def main(argv):
54 # No command line flags. Just use the parser to prevent people from trying 67 # 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'. 68 # to pass flags that don't do anything, and to provide 'usage'.
56 parser = argparse.ArgumentParser( 69 parser = argparse.ArgumentParser(
57 description='Automatically set up git-svn for a repo mirrored from svn.') 70 description='Automatically set up git-svn for a repo mirrored from svn.')
58 parser.parse_args(argv) 71 parser.parse_args(argv)
59 72
60 upstream = root() 73 upstream = root()
61 message = run_git('log', '-1', '--format=%B', upstream) 74 svn_id = get_footer_svn_id(upstream)
62 footers = parse_footers(message) 75 assert svn_id, 'No valid git-svn-id footer found on %s.' % upstream
63 git_svn_id = get_unique(footers, 'git-svn-id') 76 print 'Found git-svn-id footer %s on %s' % (svn_id, upstream)
64 match = GIT_SVN_ID_PATTERN.match(git_svn_id)
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)
67 77
68 parsed_svn = urlparse.urlparse(match.group(1)) 78 parsed_svn = urlparse.urlparse(svn_id)
69 path_components = parsed_svn.path.split('/') 79 path_components = parsed_svn.path.split('/')
70 svn_repo = None 80 svn_repo = None
71 svn_path = None 81 svn_path = None
72 for i in xrange(len(path_components)): 82 for i in xrange(len(path_components)):
73 try: 83 try:
74 maybe_repo = '%s://%s%s' % ( 84 maybe_repo = '%s://%s%s' % (
75 parsed_svn.scheme, parsed_svn.netloc, '/'.join(path_components[:i+1])) 85 parsed_svn.scheme, parsed_svn.netloc, '/'.join(path_components[:i+1]))
76 print 'Checking ', maybe_repo 86 print 'Checking ', maybe_repo
77 run_svn('info', maybe_repo) 87 run_svn('info', maybe_repo)
78 svn_repo = maybe_repo 88 svn_repo = maybe_repo
79 svn_path = '/'.join(path_components[i+1:]) 89 svn_path = '/'.join(path_components[i+1:])
80 break 90 break
81 except subprocess2.CalledProcessError, e: 91 except subprocess2.CalledProcessError, e:
82 if 'E170001' in str(e): 92 if 'E170001' in str(e):
83 print 'Authentication failed:' 93 print 'Authentication failed:'
84 print e 94 print e
85 print ('Try running "svn ls %s" with the password' 95 print ('Try running "svn ls %s" with the password'
86 ' from https://chromium-access.appspot.com' % maybe_repo) 96 ' from https://chromium-access.appspot.com' % maybe_repo)
87 print 97 print
88 continue 98 continue
89 assert svn_repo is not None, 'Unable to find svn repo for %s' % match.group(1) 99 assert svn_repo is not None, 'Unable to find svn repo for %s' % svn_id
90 print 'Found upstream svn repo %s and path %s' % (svn_repo, svn_path) 100 print 'Found upstream svn repo %s and path %s' % (svn_repo, svn_path)
91 101
92 set_config('svn-remote.svn.url', svn_repo) 102 set_config('svn-remote.svn.url', svn_repo)
93 set_config('svn-remote.svn.fetch', 103 set_config('svn-remote.svn.fetch',
94 '%s:refs/remotes/%s' % (svn_path, upstream)) 104 '%s:refs/remotes/%s' % (svn_path, upstream))
95 print 'Configured metadata, running "git svn fetch". This may take some time.' 105 print 'Configured metadata, running "git svn fetch". This may take some time.'
96 for line in run_git_stream('svn', 'fetch').xreadlines(): 106 for line in run_git_stream('svn', 'fetch').xreadlines():
97 print line.strip() 107 print line.strip()
98 return 0 108 return 0
99 109
100 110
101 if __name__ == '__main__': 111 if __name__ == '__main__':
102 try: 112 try:
103 sys.exit(main(sys.argv[1:])) 113 sys.exit(main(sys.argv[1:]))
104 except KeyboardInterrupt: 114 except KeyboardInterrupt:
105 sys.stderr.write('interrupted\n') 115 sys.stderr.write('interrupted\n')
106 sys.exit(1) 116 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | git_cl.py » ('j') | git_cl.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698