Chromium Code Reviews| 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). | |
|
iannucci
2014/09/06 20:01:29
one thing we should /seriously/ consider in gclien
| |
| 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/)?heads/', ref or '') | |
| 372 if m: | |
| 373 return ('refs/remotes/%s/' % remote, | |
| 374 ref.replace(m.group(0), '')) | |
| 375 return None | |
| 376 | |
| 377 @staticmethod | |
| 356 def GetUpstreamBranch(cwd): | 378 def GetUpstreamBranch(cwd): |
| 357 """Gets the current branch's upstream branch.""" | 379 """Gets the current branch's upstream branch.""" |
| 358 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) | 380 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) |
| 359 if remote != '.' and upstream_branch: | 381 if remote != '.' and upstream_branch: |
| 360 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) | 382 remote_ref = GIT.RefToRemoteRef(upstream_branch, remote) |
| 383 if remote_ref: | |
| 384 upstream_branch = ''.join(remote_ref) | |
| 361 return upstream_branch | 385 return upstream_branch |
| 362 | 386 |
| 363 @staticmethod | 387 @staticmethod |
| 364 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, | 388 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, |
| 365 files=None): | 389 files=None): |
| 366 """Diffs against the upstream branch or optionally another branch. | 390 """Diffs against the upstream branch or optionally another branch. |
| 367 | 391 |
| 368 full_move means that move or copy operations should completely recreate the | 392 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.""" | 393 files, usually in the prospect to apply the patch for a try job.""" |
| 370 if not branch: | 394 if not branch: |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1137 # revert, like for properties. | 1161 # revert, like for properties. |
| 1138 if not os.path.isdir(cwd): | 1162 if not os.path.isdir(cwd): |
| 1139 # '.' was deleted. It's not worth continuing. | 1163 # '.' was deleted. It's not worth continuing. |
| 1140 return | 1164 return |
| 1141 try: | 1165 try: |
| 1142 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1166 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
| 1143 except subprocess2.CalledProcessError: | 1167 except subprocess2.CalledProcessError: |
| 1144 if not os.path.exists(file_path): | 1168 if not os.path.exists(file_path): |
| 1145 continue | 1169 continue |
| 1146 raise | 1170 raise |
| OLD | NEW |