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

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: sync 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 StringIO 10 import StringIO
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 def FixUrl(server): 95 def FixUrl(server):
96 """Fix a server url to defaults protocol to http:// if none is specified.""" 96 """Fix a server url to defaults protocol to http:// if none is specified."""
97 if not server: 97 if not server:
98 return server 98 return server
99 if not re.match(r'[a-z]+\://.*', server): 99 if not re.match(r'[a-z]+\://.*', server):
100 return 'http://' + server 100 return 'http://' + server
101 return server 101 return server
102 102
103 103
104 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
105 """Return the corresponding git ref if |base_url| together with |glob_spec|
106 matches the full |url|.
107
108 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below).
109 """
110 fetch_suburl, as_ref = glob_spec.split(':')
111 if allow_wildcards:
112 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl)
113 if glob_match:
114 # Parse specs like "branches/*/src:refs/remotes/svn/*" or
115 # "branches/{472,597,648}/src:refs/remotes/svn/*".
116 branch_re = re.escape(base_url)
117 if glob_match.group(1):
118 branch_re += '/' + re.escape(glob_match.group(1))
119 wildcard = glob_match.group(2)
120 if wildcard == '*':
121 branch_re += '([^/]*)'
122 else:
123 # Escape and replace surrounding braces with parentheses and commas
124 # with pipe symbols.
125 wildcard = re.escape(wildcard)
126 wildcard = re.sub('^\\\\{', '(', wildcard)
127 wildcard = re.sub('\\\\,', '|', wildcard)
128 wildcard = re.sub('\\\\}$', ')', wildcard)
129 branch_re += wildcard
130 if glob_match.group(3):
131 branch_re += re.escape(glob_match.group(3))
132 match = re.match(branch_re, url)
133 if match:
134 return re.sub('\*$', match.group(1), as_ref)
135
136 # Parse specs like "trunk/src:refs/remotes/origin/trunk".
137 if fetch_suburl:
138 full_url = base_url + '/' + fetch_suburl
139 else:
140 full_url = base_url
141 if full_url == url:
142 return as_ref
143 return None
144
104 class Settings(object): 145 class Settings(object):
105 def __init__(self): 146 def __init__(self):
106 self.default_server = None 147 self.default_server = None
107 self.cc = None 148 self.cc = None
108 self.root = None 149 self.root = None
109 self.is_git_svn = None 150 self.is_git_svn = None
110 self.svn_branch = None 151 self.svn_branch = None
111 self.tree_status_url = None 152 self.tree_status_url = None
112 self.viewvc_url = None 153 self.viewvc_url = None
113 self.updated = False 154 self.updated = False
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if url: 227 if url:
187 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$') 228 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$')
188 remotes = RunGit(['config', '--get-regexp', 229 remotes = RunGit(['config', '--get-regexp',
189 r'^svn-remote\..*\.url']).splitlines() 230 r'^svn-remote\..*\.url']).splitlines()
190 for remote in remotes: 231 for remote in remotes:
191 match = svn_remote_re.match(remote) 232 match = svn_remote_re.match(remote)
192 if match: 233 if match:
193 remote = match.group(1) 234 remote = match.group(1)
194 base_url = match.group(2) 235 base_url = match.group(2)
195 fetch_spec = RunGit( 236 fetch_spec = RunGit(
196 ['config', 'svn-remote.'+remote+'.fetch']).strip().split(':') 237 ['config', 'svn-remote.%s.fetch' % remote],
197 if fetch_spec[0]: 238 error_ok=True).strip()
198 full_url = base_url + '/' + fetch_spec[0] 239 if fetch_spec:
199 else: 240 self.svn_branch = MatchSvnGlob(url, base_url, fetch_spec, False)
200 full_url = base_url 241 if self.svn_branch:
201 if full_url == url: 242 break
202 self.svn_branch = fetch_spec[1] 243 branch_spec = RunGit(
203 break 244 ['config', 'svn-remote.%s.branches' % remote],
245 error_ok=True).strip()
246 if branch_spec:
247 self.svn_branch = MatchSvnGlob(url, base_url, branch_spec, True)
248 if self.svn_branch:
249 break
250 tag_spec = RunGit(
251 ['config', 'svn-remote.%s.tags' % remote],
252 error_ok=True).strip()
253 if tag_spec:
254 self.svn_branch = MatchSvnGlob(url, base_url, tag_spec, True)
255 if self.svn_branch:
256 break
204 257
205 if not self.svn_branch: 258 if not self.svn_branch:
206 DieWithError('Can\'t guess svn branch -- try specifying it on the ' 259 DieWithError('Can\'t guess svn branch -- try specifying it on the '
207 'command line') 260 'command line')
208 261
209 return self.svn_branch 262 return self.svn_branch
210 263
211 def GetTreeStatusUrl(self, error_ok=False): 264 def GetTreeStatusUrl(self, error_ok=False):
212 if not self.tree_status_url: 265 if not self.tree_status_url:
213 error_message = ('You must configure your tree status URL by running ' 266 error_message = ('You must configure your tree status URL by running '
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 1466 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
1414 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1467 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1415 1468
1416 # Not a known command. Default to help. 1469 # Not a known command. Default to help.
1417 GenUsage(parser, 'help') 1470 GenUsage(parser, 'help')
1418 return CMDhelp(parser, argv) 1471 return CMDhelp(parser, argv)
1419 1472
1420 1473
1421 if __name__ == '__main__': 1474 if __name__ == '__main__':
1422 sys.exit(main(sys.argv[1:])) 1475 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