Chromium Code Reviews| Index: git_cl/git_cl.py |
| diff --git a/git_cl/git_cl.py b/git_cl/git_cl.py |
| index 4e282c1323676be1a50ac23c4925566ca8f4e5c6..a749f0107db8eba3f103001be2318ddfa962dafe 100644 |
| --- a/git_cl/git_cl.py |
| +++ b/git_cl/git_cl.py |
| @@ -97,6 +97,46 @@ def FixUrl(server): |
| return 'http://' + server |
| return server |
|
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.
|
| +def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
| + """Return the corresponding git ref if |base_url| together with |glob_spec| |
| + matches the full |url|. |
| + |
| + If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). |
| + """ |
| + glob_spec = glob_spec.split(':') |
| + if allow_wildcards: |
| + 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
|
| + if glob_match: |
| + # Parse specs like "branches/*/src:refs/remotes/svn/*" or |
| + # "branches/{472,597,648}/src:refs/remotes/svn/*". |
| + branch_re = re.escape(base_url) |
| + if glob_match.group(1): |
| + branch_re += '/' + re.escape(glob_match.group(1)) |
| + wildcard = glob_match.group(2) |
| + if wildcard == '*': |
| + branch_re += '([^/]*)' |
| + else: |
| + # Escape and replace surrounding braces with parentheses and commas |
| + # with pipe symbols. |
| + wildcard = re.escape(wildcard) |
| + wildcard = re.sub('^\\\\{', '(', wildcard) |
| + wildcard = re.sub('\\\\,', '|', wildcard) |
| + wildcard = re.sub('\\\\}$', ')', wildcard) |
| + branch_re += wildcard |
| + if glob_match.group(3): |
| + branch_re += re.escape(glob_match.group(3)) |
| + match = re.match(branch_re, url) |
| + if match: |
| + return re.sub('\*$', match.group(1), glob_spec[1]) |
| + |
| + # Parse specs like "trunk/src:refs/remotes/origin/trunk". |
| + if glob_spec[0]: |
| + full_url = base_url + '/' + glob_spec[0] |
| + else: |
| + full_url = base_url |
| + if full_url == url: |
| + return glob_spec[1] |
| + return None |
| class Settings(object): |
| def __init__(self): |
| @@ -190,14 +230,26 @@ class Settings(object): |
| remote = match.group(1) |
| base_url = match.group(2) |
| fetch_spec = RunGit( |
| - ['config', 'svn-remote.'+remote+'.fetch']).strip().split(':') |
| - if fetch_spec[0]: |
| - full_url = base_url + '/' + fetch_spec[0] |
| - else: |
| - full_url = base_url |
| - if full_url == url: |
| - self.svn_branch = fetch_spec[1] |
| - break |
| + ['config', 'svn-remote.%s.fetch' % remote], |
| + error_ok=True).strip() |
| + if fetch_spec: |
| + self.svn_branch = MatchSvnGlob(url, base_url, fetch_spec, False) |
| + if self.svn_branch: |
| + break |
| + branch_spec = RunGit( |
| + ['config', 'svn-remote.%s.branches' % remote], |
| + error_ok=True).strip() |
| + if branch_spec: |
| + self.svn_branch = MatchSvnGlob(url, base_url, branch_spec, True) |
| + if self.svn_branch: |
| + break |
| + tag_spec = RunGit( |
| + ['config', 'svn-remote.%s.tags' % remote], |
| + error_ok=True).strip() |
| + if tag_spec: |
| + self.svn_branch = MatchSvnGlob(url, base_url, tag_spec, True) |
| + if self.svn_branch: |
| + break |
| if not self.svn_branch: |
| DieWithError('Can\'t guess svn branch -- try specifying it on the ' |