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

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: presubmit fix 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') | 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:
11 git clone https://chromium.googlesource.com/chromium/tools/depot_tools 11 git clone https://chromium.googlesource.com/chromium/tools/depot_tools
12 cd depot_tools 12 cd depot_tools
13 git auto-svn 13 git auto-svn
14 """ 14 """
15 15
16 import argparse 16 import argparse
17 import os 17 import os
18 import sys 18 import sys
19 import urlparse 19 import urlparse
20 20
21 import subprocess2 21 import subprocess2
22 22
23 from git_common import run as run_git 23 from git_common import run as run_git
24 from git_common import run_stream as run_git_stream 24 from git_common import run_stream as run_git_stream
25 from git_common import set_config, root, ROOT 25 from git_common import set_config, root, ROOT
26 from git_footers import parse_footers, get_unique, GIT_SVN_ID_PATTERN 26 from git_footers import get_footer_svn_id
27 27
28 28
29 SVN_EXE = ROOT+'\\svn.bat' if sys.platform.startswith('win') else 'svn' 29 SVN_EXE = ROOT+'\\svn.bat' if sys.platform.startswith('win') else 'svn'
30 30
31 31
32 def run_svn(*cmd, **kwargs): 32 def run_svn(*cmd, **kwargs):
33 """Runs an svn command. 33 """Runs an svn command.
34 34
35 Returns (stdout, stderr) as a pair of strings. 35 Returns (stdout, stderr) as a pair of strings.
36 36
(...skipping 14 matching lines...) Expand all
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) 58 parser.parse_args(argv)
59 59
60 upstream = root() 60 upstream = root()
61 message = run_git('log', '-1', '--format=%B', upstream) 61 svn_id = get_footer_svn_id(upstream)
62 footers = parse_footers(message) 62 assert svn_id, 'No valid git-svn-id footer found on %s.' % upstream
63 git_svn_id = get_unique(footers, 'git-svn-id') 63 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 64
68 parsed_svn = urlparse.urlparse(match.group(1)) 65 parsed_svn = urlparse.urlparse(svn_id)
69 path_components = parsed_svn.path.split('/') 66 path_components = parsed_svn.path.split('/')
70 svn_repo = None 67 svn_repo = None
71 svn_path = None 68 svn_path = None
72 for i in xrange(len(path_components)): 69 for i in xrange(len(path_components)):
73 try: 70 try:
74 maybe_repo = '%s://%s%s' % ( 71 maybe_repo = '%s://%s%s' % (
75 parsed_svn.scheme, parsed_svn.netloc, '/'.join(path_components[:i+1])) 72 parsed_svn.scheme, parsed_svn.netloc, '/'.join(path_components[:i+1]))
76 print 'Checking ', maybe_repo 73 print 'Checking ', maybe_repo
77 run_svn('info', maybe_repo) 74 run_svn('info', maybe_repo)
78 svn_repo = maybe_repo 75 svn_repo = maybe_repo
79 svn_path = '/'.join(path_components[i+1:]) 76 svn_path = '/'.join(path_components[i+1:])
80 break 77 break
81 except subprocess2.CalledProcessError, e: 78 except subprocess2.CalledProcessError, e:
82 if 'E170001' in str(e): 79 if 'E170001' in str(e):
83 print 'Authentication failed:' 80 print 'Authentication failed:'
84 print e 81 print e
85 print ('Try running "svn ls %s" with the password' 82 print ('Try running "svn ls %s" with the password'
86 ' from https://chromium-access.appspot.com' % maybe_repo) 83 ' from https://chromium-access.appspot.com' % maybe_repo)
87 print 84 print
88 continue 85 continue
89 assert svn_repo is not None, 'Unable to find svn repo for %s' % match.group(1) 86 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) 87 print 'Found upstream svn repo %s and path %s' % (svn_repo, svn_path)
91 88
92 set_config('svn-remote.svn.url', svn_repo) 89 set_config('svn-remote.svn.url', svn_repo)
93 set_config('svn-remote.svn.fetch', 90 set_config('svn-remote.svn.fetch',
94 '%s:refs/remotes/%s' % (svn_path, upstream)) 91 '%s:refs/remotes/%s' % (svn_path, upstream))
95 print 'Configured metadata, running "git svn fetch". This may take some time.' 92 print 'Configured metadata, running "git svn fetch". This may take some time.'
96 for line in run_git_stream('svn', 'fetch').xreadlines(): 93 for line in run_git_stream('svn', 'fetch').xreadlines():
97 print line.strip() 94 print line.strip()
98 return 0 95 return 0
99 96
100 97
101 if __name__ == '__main__': 98 if __name__ == '__main__':
102 try: 99 try:
103 sys.exit(main(sys.argv[1:])) 100 sys.exit(main(sys.argv[1:]))
104 except KeyboardInterrupt: 101 except KeyboardInterrupt:
105 sys.stderr.write('interrupted\n') 102 sys.stderr.write('interrupted\n')
106 sys.exit(1) 103 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698