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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if url in svn_refs: | 195 if url in svn_refs: |
196 svn_branch = svn_refs[url] | 196 svn_branch = svn_refs[url] |
197 proc.stdout.close() # Cut pipe. | 197 proc.stdout.close() # Cut pipe. |
198 break | 198 break |
199 return svn_branch | 199 return svn_branch |
200 | 200 |
201 @staticmethod | 201 @staticmethod |
202 def FetchUpstreamTuple(cwd): | 202 def FetchUpstreamTuple(cwd): |
203 """Returns a tuple containg remote and remote ref, | 203 """Returns a tuple containg remote and remote ref, |
204 e.g. 'origin', 'refs/heads/master' | 204 e.g. 'origin', 'refs/heads/master' |
| 205 Tries to be intelligent and understand git-svn. |
205 """ | 206 """ |
206 remote = '.' | 207 remote = '.' |
207 branch = GIT.GetBranch(cwd) | 208 branch = GIT.GetBranch(cwd) |
208 upstream_branch = None | 209 upstream_branch = None |
209 upstream_branch = GIT.Capture( | 210 upstream_branch = GIT.Capture( |
210 ['config', 'branch.%s.merge' % branch], in_directory=cwd, | 211 ['config', 'branch.%s.merge' % branch], in_directory=cwd, |
211 error_ok=True)[0].strip() | 212 error_ok=True)[0].strip() |
212 if upstream_branch: | 213 if upstream_branch: |
213 remote = GIT.Capture( | 214 remote = GIT.Capture( |
214 ['config', 'branch.%s.remote' % branch], | 215 ['config', 'branch.%s.remote' % branch], |
215 in_directory=cwd, error_ok=True)[0].strip() | 216 in_directory=cwd, error_ok=True)[0].strip() |
216 else: | 217 else: |
217 # Fall back on trying a git-svn upstream branch. | 218 # Fall back on trying a git-svn upstream branch. |
218 if GIT.IsGitSvn(cwd): | 219 if GIT.IsGitSvn(cwd): |
219 upstream_branch = GIT.GetSVNBranch(cwd) | 220 upstream_branch = GIT.GetSVNBranch(cwd) |
| 221 # Fall back on origin/master if it exits. |
| 222 elif GIT.Capture(['branch', '-r'], in_directory=cwd |
| 223 )[0].split().count('origin/master'): |
| 224 remote = 'origin' |
| 225 upstream_branch = 'refs/heads/master' |
| 226 else: |
| 227 remote = None |
| 228 upstream_branch = None |
220 return remote, upstream_branch | 229 return remote, upstream_branch |
221 | 230 |
222 @staticmethod | 231 @staticmethod |
223 def GetUpstream(cwd): | 232 def GetUpstreamBranch(cwd): |
224 """Gets the current branch's upstream branch.""" | 233 """Gets the current branch's upstream branch.""" |
225 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) | 234 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) |
226 if remote != '.': | 235 if remote != '.': |
227 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) | 236 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) |
228 return upstream_branch | 237 return upstream_branch |
229 | 238 |
230 @staticmethod | 239 @staticmethod |
231 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, | 240 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, |
232 files=None): | 241 files=None): |
233 """Diffs against the upstream branch or optionally another branch. | 242 """Diffs against the upstream branch or optionally another branch. |
234 | 243 |
235 full_move means that move or copy operations should completely recreate the | 244 full_move means that move or copy operations should completely recreate the |
236 files, usually in the prospect to apply the patch for a try job.""" | 245 files, usually in the prospect to apply the patch for a try job.""" |
237 if not branch: | 246 if not branch: |
238 branch = GIT.GetUpstream(cwd) | 247 branch = GIT.GetUpstreamBranch(cwd) |
239 command = ['diff', '-p', '--no-prefix', branch + "..." + branch_head] | 248 command = ['diff', '-p', '--no-prefix', branch + "..." + branch_head] |
240 if not full_move: | 249 if not full_move: |
241 command.append('-C') | 250 command.append('-C') |
242 # TODO(maruel): --binary support. | 251 # TODO(maruel): --binary support. |
243 if files: | 252 if files: |
244 command.append('--') | 253 command.append('--') |
245 command.extend(files) | 254 command.extend(files) |
246 diff = GIT.Capture(command, cwd)[0].splitlines(True) | 255 diff = GIT.Capture(command, cwd)[0].splitlines(True) |
247 for i in range(len(diff)): | 256 for i in range(len(diff)): |
248 # In the case of added files, replace /dev/null with the path to the | 257 # In the case of added files, replace /dev/null with the path to the |
249 # file being added. | 258 # file being added. |
250 if diff[i].startswith('--- /dev/null'): | 259 if diff[i].startswith('--- /dev/null'): |
251 diff[i] = '--- %s' % diff[i+1][4:] | 260 diff[i] = '--- %s' % diff[i+1][4:] |
252 return ''.join(diff) | 261 return ''.join(diff) |
253 | 262 |
254 @staticmethod | 263 @staticmethod |
255 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): | 264 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): |
256 """Returns the list of modified files between two branches.""" | 265 """Returns the list of modified files between two branches.""" |
257 if not branch: | 266 if not branch: |
258 branch = GIT.GetUpstream(cwd) | 267 branch = GIT.GetUpstreamBranch(cwd) |
259 command = ['diff', '--name-only', branch + "..." + branch_head] | 268 command = ['diff', '--name-only', branch + "..." + branch_head] |
260 return GIT.Capture(command, cwd)[0].splitlines(False) | 269 return GIT.Capture(command, cwd)[0].splitlines(False) |
261 | 270 |
262 @staticmethod | 271 @staticmethod |
263 def GetPatchName(cwd): | 272 def GetPatchName(cwd): |
264 """Constructs a name for this patch.""" | 273 """Constructs a name for this patch.""" |
265 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd)[0].strip() | 274 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd)[0].strip() |
266 return "%s-%s" % (GIT.GetBranch(cwd), short_sha) | 275 return "%s-%s" % (GIT.GetBranch(cwd), short_sha) |
267 | 276 |
268 @staticmethod | 277 @staticmethod |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 if not SVN.current_version: | 787 if not SVN.current_version: |
779 SVN.current_version = SVN.Capture(['--version']).split()[2] | 788 SVN.current_version = SVN.Capture(['--version']).split()[2] |
780 current_version_list = map(only_int, SVN.current_version.split('.')) | 789 current_version_list = map(only_int, SVN.current_version.split('.')) |
781 for min_ver in map(int, min_version.split('.')): | 790 for min_ver in map(int, min_version.split('.')): |
782 ver = current_version_list.pop(0) | 791 ver = current_version_list.pop(0) |
783 if ver < min_ver: | 792 if ver < min_ver: |
784 return (False, SVN.current_version) | 793 return (False, SVN.current_version) |
785 elif ver > min_ver: | 794 elif ver > min_ver: |
786 return (True, SVN.current_version) | 795 return (True, SVN.current_version) |
787 return (True, SVN.current_version) | 796 return (True, SVN.current_version) |
OLD | NEW |