OLD | NEW |
---|---|
1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 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 glob | 7 import glob |
8 import os | 8 import os |
9 import re | 9 import re |
10 import shutil | 10 import shutil |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 git_svn_re = re.compile(r'^\s*git-svn-id: (\S+)@', re.MULTILINE) | 165 git_svn_re = re.compile(r'^\s*git-svn-id: (\S+)@', re.MULTILINE) |
166 | 166 |
167 # Get the refname and svn url for all refs/remotes/*. | 167 # Get the refname and svn url for all refs/remotes/*. |
168 remotes = GIT.Capture( | 168 remotes = GIT.Capture( |
169 ['for-each-ref', '--format=%(refname)', 'refs/remotes'], | 169 ['for-each-ref', '--format=%(refname)', 'refs/remotes'], |
170 cwd)[0].splitlines() | 170 cwd)[0].splitlines() |
171 svn_refs = {} | 171 svn_refs = {} |
172 for ref in remotes: | 172 for ref in remotes: |
173 match = git_svn_re.search( | 173 match = git_svn_re.search( |
174 GIT.Capture(['cat-file', '-p', ref], cwd)[0]) | 174 GIT.Capture(['cat-file', '-p', ref], cwd)[0]) |
175 if match: | 175 if match and match.group(1) not in svn_refs: |
M-A Ruel
2010/04/08 16:36:38
nit: you could do instead
if match:
# To prefer
| |
176 # To prefer local refs over remote ones we only set the first occurence. | |
177 # The assumption being local refs are usually first. | |
176 svn_refs[match.group(1)] = ref | 178 svn_refs[match.group(1)] = ref |
177 | 179 |
178 svn_branch = '' | 180 svn_branch = '' |
179 if len(svn_refs) == 1: | 181 if len(svn_refs) == 1: |
180 # Only one svn branch exists -- seems like a good candidate. | 182 # Only one svn branch exists -- seems like a good candidate. |
181 svn_branch = svn_refs.values()[0] | 183 svn_branch = svn_refs.values()[0] |
182 elif len(svn_refs) > 1: | 184 elif len(svn_refs) > 1: |
183 # We have more than one remote branch available. We don't | 185 # We have more than one remote branch available. We don't |
184 # want to go through all of history, so read a line from the | 186 # want to go through all of history, so read a line from the |
185 # pipe at a time. | 187 # pipe at a time. |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 if not cur_dir_repo_root: | 758 if not cur_dir_repo_root: |
757 return None | 759 return None |
758 | 760 |
759 while True: | 761 while True: |
760 parent = os.path.dirname(directory) | 762 parent = os.path.dirname(directory) |
761 if (SVN.CaptureInfo(parent, print_error=False).get( | 763 if (SVN.CaptureInfo(parent, print_error=False).get( |
762 "Repository Root") != cur_dir_repo_root): | 764 "Repository Root") != cur_dir_repo_root): |
763 break | 765 break |
764 directory = parent | 766 directory = parent |
765 return GetCasedPath(directory) | 767 return GetCasedPath(directory) |
OLD | NEW |