OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 # git-svn clone | 346 # git-svn clone |
347 remote = 'origin' | 347 remote = 'origin' |
348 upstream_branch = 'refs/heads/trunk' | 348 upstream_branch = 'refs/heads/trunk' |
349 else: | 349 else: |
350 # Give up. | 350 # Give up. |
351 remote = None | 351 remote = None |
352 upstream_branch = None | 352 upstream_branch = None |
353 return remote, upstream_branch | 353 return remote, upstream_branch |
354 | 354 |
355 @staticmethod | 355 @staticmethod |
| 356 def RefToRemoteRef(ref, remote=None): |
| 357 """Convert a checkout ref to the equivalent remote ref. |
| 358 |
| 359 Returns: |
| 360 A tuple of the remote ref's (common prefix, unique suffix), or None if it |
| 361 doesn't appear to refer to a remote ref (e.g. it's a commit hash). |
| 362 """ |
| 363 # TODO(mmoss): This is just a brute-force mapping based of the expected git |
| 364 # config. It's a bit better than the even more brute-force replace('heads', |
| 365 # ...), but could still be smarter (like maybe actually using values gleaned |
| 366 # from the git config). |
| 367 m = re.match('^(refs/(remotes/)?)?branch-heads/', ref or '') |
| 368 if m: |
| 369 return ('refs/remotes/branch-heads/', ref.replace(m.group(0), '')) |
| 370 if remote: |
| 371 m = re.match('^((refs/)?remotes/)?%s/|(refs/)?heads/' % remote, ref or '') |
| 372 if m: |
| 373 return ('refs/remotes/%s/' % remote, ref.replace(m.group(0), '')) |
| 374 return None |
| 375 |
| 376 @staticmethod |
356 def GetUpstreamBranch(cwd): | 377 def GetUpstreamBranch(cwd): |
357 """Gets the current branch's upstream branch.""" | 378 """Gets the current branch's upstream branch.""" |
358 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) | 379 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) |
359 if remote != '.' and upstream_branch: | 380 if remote != '.' and upstream_branch: |
360 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) | 381 remote_ref = GIT.RefToRemoteRef(upstream_branch, remote) |
| 382 if remote_ref: |
| 383 upstream_branch = ''.join(remote_ref) |
361 return upstream_branch | 384 return upstream_branch |
362 | 385 |
363 @staticmethod | 386 @staticmethod |
364 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, | 387 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, |
365 files=None): | 388 files=None): |
366 """Diffs against the upstream branch or optionally another branch. | 389 """Diffs against the upstream branch or optionally another branch. |
367 | 390 |
368 full_move means that move or copy operations should completely recreate the | 391 full_move means that move or copy operations should completely recreate the |
369 files, usually in the prospect to apply the patch for a try job.""" | 392 files, usually in the prospect to apply the patch for a try job.""" |
370 if not branch: | 393 if not branch: |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 # revert, like for properties. | 1160 # revert, like for properties. |
1138 if not os.path.isdir(cwd): | 1161 if not os.path.isdir(cwd): |
1139 # '.' was deleted. It's not worth continuing. | 1162 # '.' was deleted. It's not worth continuing. |
1140 return | 1163 return |
1141 try: | 1164 try: |
1142 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1165 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
1143 except subprocess2.CalledProcessError: | 1166 except subprocess2.CalledProcessError: |
1144 if not os.path.exists(file_path): | 1167 if not os.path.exists(file_path): |
1145 continue | 1168 continue |
1146 raise | 1169 raise |
OLD | NEW |