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

Side by Side Diff: scm.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 | « git_cl/test/upstream.sh ('k') | tests/scm_unittest.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 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """SCM-specific utility classes.""" 5 """SCM-specific utility classes."""
6 6
7 import cStringIO 7 import cStringIO
8 import glob 8 import glob
9 import logging 9 import logging
10 import os 10 import os
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 def IsGitSvn(cwd): 133 def IsGitSvn(cwd):
134 """Returns true if this repo looks like it's using git-svn.""" 134 """Returns true if this repo looks like it's using git-svn."""
135 # If you have any "svn-remote.*" config keys, we think you're using svn. 135 # If you have any "svn-remote.*" config keys, we think you're using svn.
136 try: 136 try:
137 GIT.Capture(['config', '--get-regexp', r'^svn-remote\.'], cwd=cwd) 137 GIT.Capture(['config', '--get-regexp', r'^svn-remote\.'], cwd=cwd)
138 return True 138 return True
139 except gclient_utils.CheckCallError: 139 except gclient_utils.CheckCallError:
140 return False 140 return False
141 141
142 @staticmethod 142 @staticmethod
143 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
144 """Return the corresponding git ref if |base_url| together with |glob_spec|
145 matches the full |url|.
146
147 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below).
148 """
149 fetch_suburl, as_ref = glob_spec.split(':')
150 if allow_wildcards:
151 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl)
152 if glob_match:
153 # Parse specs like "branches/*/src:refs/remotes/svn/*" or
154 # "branches/{472,597,648}/src:refs/remotes/svn/*".
155 branch_re = re.escape(base_url)
156 if glob_match.group(1):
157 branch_re += '/' + re.escape(glob_match.group(1))
158 wildcard = glob_match.group(2)
159 if wildcard == '*':
160 branch_re += '([^/]*)'
161 else:
162 # Escape and replace surrounding braces with parentheses and commas
163 # with pipe symbols.
164 wildcard = re.escape(wildcard)
165 wildcard = re.sub('^\\\\{', '(', wildcard)
166 wildcard = re.sub('\\\\,', '|', wildcard)
167 wildcard = re.sub('\\\\}$', ')', wildcard)
168 branch_re += wildcard
169 if glob_match.group(3):
170 branch_re += re.escape(glob_match.group(3))
171 match = re.match(branch_re, url)
172 if match:
173 return re.sub('\*$', match.group(1), as_ref)
174
175 # Parse specs like "trunk/src:refs/remotes/origin/trunk".
176 if fetch_suburl:
177 full_url = base_url + '/' + fetch_suburl
178 else:
179 full_url = base_url
180 if full_url == url:
181 return as_ref
182 return None
183
184 @staticmethod
143 def GetSVNBranch(cwd): 185 def GetSVNBranch(cwd):
144 """Returns the svn branch name if found.""" 186 """Returns the svn branch name if found."""
145 # Try to figure out which remote branch we're based on. 187 # Try to figure out which remote branch we're based on.
146 # Strategy: 188 # Strategy:
147 # 1) iterate through our branch history and find the svn URL. 189 # 1) iterate through our branch history and find the svn URL.
148 # 2) find the svn-remote that fetches from the URL. 190 # 2) find the svn-remote that fetches from the URL.
149 191
150 # regexp matching the git-svn line that contains the URL. 192 # regexp matching the git-svn line that contains the URL.
151 git_svn_re = re.compile(r'^\s*git-svn-id: (\S+)@', re.MULTILINE) 193 git_svn_re = re.compile(r'^\s*git-svn-id: (\S+)@', re.MULTILINE)
152 194
(...skipping 11 matching lines...) Expand all
164 206
165 if url: 207 if url:
166 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$') 208 svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$')
167 remotes = GIT.Capture(['config', '--get-regexp', 209 remotes = GIT.Capture(['config', '--get-regexp',
168 r'^svn-remote\..*\.url'], cwd=cwd).splitlines() 210 r'^svn-remote\..*\.url'], cwd=cwd).splitlines()
169 for remote in remotes: 211 for remote in remotes:
170 match = svn_remote_re.match(remote) 212 match = svn_remote_re.match(remote)
171 if match: 213 if match:
172 remote = match.group(1) 214 remote = match.group(1)
173 base_url = match.group(2) 215 base_url = match.group(2)
174 fetch_spec = GIT.Capture( 216 try:
175 ['config', 'svn-remote.%s.fetch' % remote], 217 fetch_spec = GIT.Capture(
176 cwd=cwd).strip().split(':') 218 ['config', 'svn-remote.%s.fetch' % remote],
177 if fetch_spec[0]: 219 cwd=cwd).strip()
178 full_url = base_url + '/' + fetch_spec[0] 220 branch = GIT.MatchSvnGlob(url, base_url, fetch_spec, False)
179 else: 221 except gclient_utils.CheckCallError:
180 full_url = base_url 222 branch = None
181 if full_url == url: 223 if branch:
182 return fetch_spec[1] 224 return branch
225 try:
226 branch_spec = GIT.Capture(
227 ['config', 'svn-remote.%s.branches' % remote],
228 cwd=cwd).strip()
229 branch = GIT.MatchSvnGlob(url, base_url, branch_spec, True)
230 except gclient_utils.CheckCallError:
231 branch = None
232 if branch:
233 return branch
234 try:
235 tag_spec = GIT.Capture(
236 ['config', 'svn-remote.%s.tags' % remote],
237 cwd=cwd).strip()
238 branch = GIT.MatchSvnGlob(url, base_url, tag_spec, True)
239 except gclient_utils.CheckCallError:
240 branch = None
241 if branch:
242 return branch
183 243
184 @staticmethod 244 @staticmethod
185 def FetchUpstreamTuple(cwd): 245 def FetchUpstreamTuple(cwd):
186 """Returns a tuple containg remote and remote ref, 246 """Returns a tuple containg remote and remote ref,
187 e.g. 'origin', 'refs/heads/master' 247 e.g. 'origin', 'refs/heads/master'
188 Tries to be intelligent and understand git-svn. 248 Tries to be intelligent and understand git-svn.
189 """ 249 """
190 remote = '.' 250 remote = '.'
191 branch = GIT.GetBranch(cwd) 251 branch = GIT.GetBranch(cwd)
192 try: 252 try:
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 if os.path.isfile(file_path) or os.path.islink(file_path): 954 if os.path.isfile(file_path) or os.path.islink(file_path):
895 logging.info('os.remove(%s)' % file_path) 955 logging.info('os.remove(%s)' % file_path)
896 os.remove(file_path) 956 os.remove(file_path)
897 elif os.path.isdir(file_path): 957 elif os.path.isdir(file_path):
898 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) 958 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
899 gclient_utils.RemoveDirectory(file_path) 959 gclient_utils.RemoveDirectory(file_path)
900 else: 960 else:
901 logging.critical( 961 logging.critical(
902 ('No idea what is %s.\nYou just found a bug in gclient' 962 ('No idea what is %s.\nYou just found a bug in gclient'
903 ', please ping maruel@chromium.org ASAP!') % file_path) 963 ', please ping maruel@chromium.org ASAP!') % file_path)
OLDNEW
« no previous file with comments | « git_cl/test/upstream.sh ('k') | tests/scm_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698