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

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: add test 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 | git_cl/test/test-lib.sh » ('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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
100 100
101 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
102 """Return the corresponding git ref if |base_url| together with |glob_spec|
103 matches the full |url|.
104
105 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below).
106 """
107 glob_spec = glob_spec.split(':')
M-A Ruel 2011/03/08 18:42:51 Do you mind putting something like: fetch_suburl,
Bernhard Bauer 2011/03/08 18:47:45 Nice! Done.
108 if allow_wildcards:
109 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', glob_spec[0])
110 if glob_match:
111 # Parse specs like "branches/*/src:refs/remotes/svn/*" or
112 # "branches/{472,597,648}/src:refs/remotes/svn/*".
113 branch_re = re.escape(base_url)
114 if glob_match.group(1):
115 branch_re += '/' + re.escape(glob_match.group(1))
116 wildcard = glob_match.group(2)
117 if wildcard == '*':
118 branch_re += '([^/]*)'
119 else:
120 # Escape and replace surrounding braces with parentheses and commas
121 # with pipe symbols.
122 wildcard = re.escape(wildcard)
123 wildcard = re.sub('^\\\\{', '(', wildcard)
124 wildcard = re.sub('\\\\,', '|', wildcard)
125 wildcard = re.sub('\\\\}$', ')', wildcard)
126 branch_re += wildcard
127 if glob_match.group(3):
128 branch_re += re.escape(glob_match.group(3))
129 match = re.match(branch_re, url)
130 if match:
131 return re.sub('\*$', match.group(1), glob_spec[1])
132
133 # Parse specs like "trunk/src:refs/remotes/origin/trunk".
134 if glob_spec[0]:
135 full_url = base_url + '/' + glob_spec[0]
136 else:
137 full_url = base_url
138 if full_url == url:
139 return glob_spec[1]
140 return None
141
101 class Settings(object): 142 class Settings(object):
102 def __init__(self): 143 def __init__(self):
103 self.default_server = None 144 self.default_server = None
104 self.cc = None 145 self.cc = None
105 self.root = None 146 self.root = None
106 self.is_git_svn = None 147 self.is_git_svn = None
107 self.svn_branch = None 148 self.svn_branch = None
108 self.tree_status_url = None 149 self.tree_status_url = None
109 self.viewvc_url = None 150 self.viewvc_url = None
110 self.updated = False 151 self.updated = False
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if url: 224 if url:
184 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$') 225 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$')
185 remotes = RunGit(['config', '--get-regexp', 226 remotes = RunGit(['config', '--get-regexp',
186 r'^svn-remote\..*\.url']).splitlines() 227 r'^svn-remote\..*\.url']).splitlines()
187 for remote in remotes: 228 for remote in remotes:
188 match = svn_remote_re.match(remote) 229 match = svn_remote_re.match(remote)
189 if match: 230 if match:
190 remote = match.group(1) 231 remote = match.group(1)
191 base_url = match.group(2) 232 base_url = match.group(2)
192 fetch_spec = RunGit( 233 fetch_spec = RunGit(
193 ['config', 'svn-remote.'+remote+'.fetch']).strip().split(':') 234 ['config', 'svn-remote.%s.fetch' % remote],
194 if fetch_spec[0]: 235 error_ok=True).strip()
195 full_url = base_url + '/' + fetch_spec[0] 236 if fetch_spec:
196 else: 237 self.svn_branch = MatchSvnGlob(url, base_url, fetch_spec, False)
197 full_url = base_url 238 if self.svn_branch:
198 if full_url == url: 239 break
199 self.svn_branch = fetch_spec[1] 240 branch_spec = RunGit(
200 break 241 ['config', 'svn-remote.%s.branches' % remote],
242 error_ok=True).strip()
243 if branch_spec:
244 self.svn_branch = MatchSvnGlob(url, base_url, branch_spec, True)
245 if self.svn_branch:
246 break
247 tag_spec = RunGit(
248 ['config', 'svn-remote.%s.tags' % remote],
249 error_ok=True).strip()
250 if tag_spec:
251 self.svn_branch = MatchSvnGlob(url, base_url, tag_spec, True)
252 if self.svn_branch:
253 break
201 254
202 if not self.svn_branch: 255 if not self.svn_branch:
203 DieWithError('Can\'t guess svn branch -- try specifying it on the ' 256 DieWithError('Can\'t guess svn branch -- try specifying it on the '
204 'command line') 257 'command line')
205 258
206 return self.svn_branch 259 return self.svn_branch
207 260
208 def GetTreeStatusUrl(self, error_ok=False): 261 def GetTreeStatusUrl(self, error_ok=False):
209 if not self.tree_status_url: 262 if not self.tree_status_url:
210 error_message = ('You must configure your tree status URL by running ' 263 error_message = ('You must configure your tree status URL by running '
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 1332 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
1280 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1333 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1281 1334
1282 # Not a known command. Default to help. 1335 # Not a known command. Default to help.
1283 GenUsage(parser, 'help') 1336 GenUsage(parser, 'help')
1284 return CMDhelp(parser, argv) 1337 return CMDhelp(parser, argv)
1285 1338
1286 1339
1287 if __name__ == '__main__': 1340 if __name__ == '__main__':
1288 sys.exit(main(sys.argv[1:])) 1341 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | git_cl/test/test-lib.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698