| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 @staticmethod | 224 @staticmethod |
| 225 def GetUpstream(cwd): | 225 def GetUpstream(cwd): |
| 226 """Gets the current branch's upstream branch.""" | 226 """Gets the current branch's upstream branch.""" |
| 227 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) | 227 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) |
| 228 if remote is not '.': | 228 if remote is not '.': |
| 229 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) | 229 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) |
| 230 return upstream_branch | 230 return upstream_branch |
| 231 | 231 |
| 232 @staticmethod | 232 @staticmethod |
| 233 def GenerateDiff(cwd, branch=None, full_move=False): | 233 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, |
| 234 files=None): |
| 234 """Diffs against the upstream branch or optionally another branch. | 235 """Diffs against the upstream branch or optionally another branch. |
| 235 | 236 |
| 236 full_move means that move or copy operations should completely recreate the | 237 full_move means that move or copy operations should completely recreate the |
| 237 files, usually in the prospect to apply the patch for a try job.""" | 238 files, usually in the prospect to apply the patch for a try job.""" |
| 238 if not branch: | 239 if not branch: |
| 239 branch = GIT.GetUpstream(cwd) | 240 branch = GIT.GetUpstream(cwd) |
| 240 command = ['diff-tree', '-p', '--no-prefix', branch, 'HEAD'] | 241 command = ['diff-tree', '-p', '--no-prefix', branch, branch_head] |
| 241 if not full_move: | 242 if not full_move: |
| 242 command.append('-C') | 243 command.append('-C') |
| 244 # TODO(maruel): --binary support. |
| 245 if files: |
| 246 command.append('--') |
| 247 command.extend(files) |
| 243 diff = GIT.Capture(command, cwd).splitlines(True) | 248 diff = GIT.Capture(command, cwd).splitlines(True) |
| 244 for i in range(len(diff)): | 249 for i in range(len(diff)): |
| 245 # In the case of added files, replace /dev/null with the path to the | 250 # In the case of added files, replace /dev/null with the path to the |
| 246 # file being added. | 251 # file being added. |
| 247 if diff[i].startswith('--- /dev/null'): | 252 if diff[i].startswith('--- /dev/null'): |
| 248 diff[i] = '--- %s' % diff[i+1][4:] | 253 diff[i] = '--- %s' % diff[i+1][4:] |
| 249 return ''.join(diff) | 254 return ''.join(diff) |
| 250 | 255 |
| 251 @staticmethod | 256 @staticmethod |
| 257 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): |
| 258 """Returns the list of modified files between two branches.""" |
| 259 if not branch: |
| 260 branch = GIT.GetUpstream(cwd) |
| 261 command = ['diff', '--name-only', branch, branch_head] |
| 262 return GIT.Capture(command, cwd).splitlines(False) |
| 263 |
| 264 @staticmethod |
| 252 def GetPatchName(cwd): | 265 def GetPatchName(cwd): |
| 253 """Constructs a name for this patch.""" | 266 """Constructs a name for this patch.""" |
| 254 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd).strip() | 267 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd).strip() |
| 255 return "%s-%s" % (GIT.GetBranch(cwd), short_sha) | 268 return "%s-%s" % (GIT.GetBranch(cwd), short_sha) |
| 256 | 269 |
| 257 @staticmethod | 270 @staticmethod |
| 258 def GetCheckoutRoot(path): | 271 def GetCheckoutRoot(path): |
| 259 """Returns the top level directory of a git checkout as an absolute path. | 272 """Returns the top level directory of a git checkout as an absolute path. |
| 260 """ | 273 """ |
| 261 root = GIT.Capture(['rev-parse', '--show-cdup'], path).strip() | 274 root = GIT.Capture(['rev-parse', '--show-cdup'], path).strip() |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 if not cur_dir_repo_root: | 735 if not cur_dir_repo_root: |
| 723 return None | 736 return None |
| 724 | 737 |
| 725 while True: | 738 while True: |
| 726 parent = os.path.dirname(directory) | 739 parent = os.path.dirname(directory) |
| 727 if (SVN.CaptureInfo(parent, print_error=False).get( | 740 if (SVN.CaptureInfo(parent, print_error=False).get( |
| 728 "Repository Root") != cur_dir_repo_root): | 741 "Repository Root") != cur_dir_repo_root): |
| 729 break | 742 break |
| 730 directory = parent | 743 directory = parent |
| 731 return GetCasedPath(directory) | 744 return GetCasedPath(directory) |
| OLD | NEW |