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

Side by Side Diff: git_cl/git_cl.py

Issue 6598068: Add support for wildcards in svn remote configuration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 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
« no previous file with comments | « no previous file | scm.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/python 1 #!/usr/bin/python
2 # git-cl -- a git-command for integrating reviews on Rietveld 2 # git-cl -- a git-command for integrating reviews on Rietveld
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> 3 # Copyright (C) 2008 Evan Martin <martine@danga.com>
4 4
5 import errno 5 import errno
6 import logging 6 import logging
7 import optparse 7 import optparse
8 import os 8 import os
9 import re 9 import re
10 import subprocess 10 import subprocess
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return hook 89 return hook
90 90
91 91
92 def FixUrl(server): 92 def FixUrl(server):
93 """Fix a server url to defaults protocol to http:// if none is specified.""" 93 """Fix a server url to defaults protocol to http:// if none is specified."""
94 if not server: 94 if not server:
95 return server 95 return server
96 if not re.match(r'[a-z]+\://.*', server): 96 if not re.match(r'[a-z]+\://.*', server):
97 return 'http://' + server 97 return 'http://' + server
98 return server 98 return server
99 99
M-A Ruel 2011/03/02 14:24:59 Two empty lines between file level symbols.
Bernhard Bauer 2011/03/02 14:36:06 Done.
100 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
101 """Return the corresponding git ref if |base_url| together with |glob_spec|
102 matches the full |url|.
103
104 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below).
105 """
106 glob_spec = glob_spec.split(':')
107 if allow_wildcards:
108 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', glob_spec[0])
M-A Ruel 2011/03/02 14:24:59 Otherwise you could use fnmatch.fnmatch(). It won'
Bernhard Bauer 2011/03/02 14:36:06 The thing is I have to support whatever git-svn is
109 if glob_match:
110 # Parse specs like "branches/*/src:refs/remotes/svn/*" or
111 # "branches/{472,597,648}/src:refs/remotes/svn/*".
112 branch_re = re.escape(base_url)
113 if glob_match.group(1):
114 branch_re += '/' + re.escape(glob_match.group(1))
115 wildcard = glob_match.group(2)
116 if wildcard == '*':
117 branch_re += '([^/]*)'
118 else:
119 # Escape and replace surrounding braces with parentheses and commas
120 # with pipe symbols.
121 wildcard = re.escape(wildcard)
122 wildcard = re.sub('^\\\\{', '(', wildcard)
123 wildcard = re.sub('\\\\,', '|', wildcard)
124 wildcard = re.sub('\\\\}$', ')', wildcard)
125 branch_re += wildcard
126 if glob_match.group(3):
127 branch_re += re.escape(glob_match.group(3))
128 match = re.match(branch_re, url)
129 if match:
130 return re.sub('\*$', match.group(1), glob_spec[1])
131
132 # Parse specs like "trunk/src:refs/remotes/origin/trunk".
133 if glob_spec[0]:
134 full_url = base_url + '/' + glob_spec[0]
135 else:
136 full_url = base_url
137 if full_url == url:
138 return glob_spec[1]
139 return None
100 140
101 class Settings(object): 141 class Settings(object):
102 def __init__(self): 142 def __init__(self):
103 self.default_server = None 143 self.default_server = None
104 self.cc = None 144 self.cc = None
105 self.root = None 145 self.root = None
106 self.is_git_svn = None 146 self.is_git_svn = None
107 self.svn_branch = None 147 self.svn_branch = None
108 self.tree_status_url = None 148 self.tree_status_url = None
109 self.viewvc_url = None 149 self.viewvc_url = None
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if url: 223 if url:
184 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$') 224 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$')
185 remotes = RunGit(['config', '--get-regexp', 225 remotes = RunGit(['config', '--get-regexp',
186 r'^svn-remote\..*\.url']).splitlines() 226 r'^svn-remote\..*\.url']).splitlines()
187 for remote in remotes: 227 for remote in remotes:
188 match = svn_remote_re.match(remote) 228 match = svn_remote_re.match(remote)
189 if match: 229 if match:
190 remote = match.group(1) 230 remote = match.group(1)
191 base_url = match.group(2) 231 base_url = match.group(2)
192 fetch_spec = RunGit( 232 fetch_spec = RunGit(
193 ['config', 'svn-remote.'+remote+'.fetch']).strip().split(':') 233 ['config', 'svn-remote.%s.fetch' % remote],
194 if fetch_spec[0]: 234 error_ok=True).strip()
195 full_url = base_url + '/' + fetch_spec[0] 235 if fetch_spec:
196 else: 236 self.svn_branch = MatchSvnGlob(url, base_url, fetch_spec, False)
197 full_url = base_url 237 if self.svn_branch:
198 if full_url == url: 238 break
199 self.svn_branch = fetch_spec[1] 239 branch_spec = RunGit(
200 break 240 ['config', 'svn-remote.%s.branches' % remote],
241 error_ok=True).strip()
242 if branch_spec:
243 self.svn_branch = MatchSvnGlob(url, base_url, branch_spec, True)
244 if self.svn_branch:
245 break
246 tag_spec = RunGit(
247 ['config', 'svn-remote.%s.tags' % remote],
248 error_ok=True).strip()
249 if tag_spec:
250 self.svn_branch = MatchSvnGlob(url, base_url, tag_spec, True)
251 if self.svn_branch:
252 break
201 253
202 if not self.svn_branch: 254 if not self.svn_branch:
203 DieWithError('Can\'t guess svn branch -- try specifying it on the ' 255 DieWithError('Can\'t guess svn branch -- try specifying it on the '
204 'command line') 256 'command line')
205 257
206 return self.svn_branch 258 return self.svn_branch
207 259
208 def GetTreeStatusUrl(self, error_ok=False): 260 def GetTreeStatusUrl(self, error_ok=False):
209 if not self.tree_status_url: 261 if not self.tree_status_url:
210 error_message = ('You must configure your tree status URL by running ' 262 error_message = ('You must configure your tree status URL by running '
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 1330 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
1279 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1331 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1280 1332
1281 # Not a known command. Default to help. 1333 # Not a known command. Default to help.
1282 GenUsage(parser, 'help') 1334 GenUsage(parser, 'help')
1283 return CMDhelp(parser, argv) 1335 return CMDhelp(parser, argv)
1284 1336
1285 1337
1286 if __name__ == '__main__': 1338 if __name__ == '__main__':
1287 sys.exit(main(sys.argv[1:])) 1339 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | scm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698