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

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: 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
« git_cl/git_cl.py ('K') | « git_cl/test/upstream.sh ('k') | no next file » | 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 data.write("@@ -0,0 +1,%d @@\n" % nb_lines) 58 data.write("@@ -0,0 +1,%d @@\n" % nb_lines)
59 # Prepend '+' to every lines. 59 # Prepend '+' to every lines.
60 for line in file_content: 60 for line in file_content:
61 data.write('+') 61 data.write('+')
62 data.write(line) 62 data.write(line)
63 result = data.getvalue() 63 result = data.getvalue()
64 data.close() 64 data.close()
65 return result 65 return result
66 66
67 67
68 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
69 """Return the corresponding git ref if |base_url| together with |glob_spec|
70 matches the full |url|.
71
72 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below).
73 """
74 glob_spec = glob_spec.split(':')
75 if allow_wildcards:
76 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', glob_spec[0])
77 if glob_match:
78 # Parse specs like "branches/*/src:refs/remotes/svn/*" or
79 # "branches/{472,597,648}/src:refs/remotes/svn/*".
80 branch_re = re.escape(base_url)
81 if glob_match.group(1):
82 branch_re += '/' + re.escape(glob_match.group(1))
83 wildcard = glob_match.group(2)
84 if wildcard == '*':
85 branch_re += '([^/]*)'
86 else:
87 # Escape and replace surrounding braces with parentheses and commas
88 # with pipe symbols.
89 wildcard = re.escape(wildcard)
90 wildcard = re.sub('^\\\\{', '(', wildcard)
91 wildcard = re.sub('\\\\,', '|', wildcard)
92 wildcard = re.sub('\\\\}$', ')', wildcard)
93 branch_re += wildcard
94 if glob_match.group(3):
95 branch_re += re.escape(glob_match.group(3))
96 match = re.match(branch_re, url)
97 if match:
98 return re.sub('\*$', match.group(1), glob_spec[1])
99
100 # Parse specs like "trunk/src:refs/remotes/origin/trunk".
101 if glob_spec[0]:
102 full_url = base_url + '/' + glob_spec[0]
103 else:
104 full_url = base_url
105 if full_url == url:
106 return glob_spec[1]
107 return None
108
109
68 class GIT(object): 110 class GIT(object):
69 @staticmethod 111 @staticmethod
70 def Capture(args, **kwargs): 112 def Capture(args, **kwargs):
71 return gclient_utils.CheckCall(['git'] + args, print_error=False, 113 return gclient_utils.CheckCall(['git'] + args, print_error=False,
72 **kwargs)[0] 114 **kwargs)[0]
73 115
74 @staticmethod 116 @staticmethod
75 def CaptureStatus(files, upstream_branch=None): 117 def CaptureStatus(files, upstream_branch=None):
76 """Returns git status. 118 """Returns git status.
77 119
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = 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 = 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 = 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
« git_cl/git_cl.py ('K') | « git_cl/test/upstream.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698