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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 @staticmethod | 228 @staticmethod |
229 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, | 229 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, |
230 files=None): | 230 files=None): |
231 """Diffs against the upstream branch or optionally another branch. | 231 """Diffs against the upstream branch or optionally another branch. |
232 | 232 |
233 full_move means that move or copy operations should completely recreate the | 233 full_move means that move or copy operations should completely recreate the |
234 files, usually in the prospect to apply the patch for a try job.""" | 234 files, usually in the prospect to apply the patch for a try job.""" |
235 if not branch: | 235 if not branch: |
236 branch = GIT.GetUpstream(cwd) | 236 branch = GIT.GetUpstream(cwd) |
237 command = ['diff-tree', '-p', '--no-prefix', branch, branch_head] | 237 command = ['diff', '-p', '--no-prefix', branch + "..." + branch_head] |
238 if not full_move: | 238 if not full_move: |
239 command.append('-C') | 239 command.append('-C') |
240 # TODO(maruel): --binary support. | 240 # TODO(maruel): --binary support. |
241 if files: | 241 if files: |
242 command.append('--') | 242 command.append('--') |
243 command.extend(files) | 243 command.extend(files) |
244 diff = GIT.Capture(command, cwd)[0].splitlines(True) | 244 diff = GIT.Capture(command, cwd)[0].splitlines(True) |
245 for i in range(len(diff)): | 245 for i in range(len(diff)): |
246 # In the case of added files, replace /dev/null with the path to the | 246 # In the case of added files, replace /dev/null with the path to the |
247 # file being added. | 247 # file being added. |
248 if diff[i].startswith('--- /dev/null'): | 248 if diff[i].startswith('--- /dev/null'): |
249 diff[i] = '--- %s' % diff[i+1][4:] | 249 diff[i] = '--- %s' % diff[i+1][4:] |
250 return ''.join(diff) | 250 return ''.join(diff) |
251 | 251 |
252 @staticmethod | 252 @staticmethod |
253 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): | 253 def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'): |
254 """Returns the list of modified files between two branches.""" | 254 """Returns the list of modified files between two branches.""" |
255 if not branch: | 255 if not branch: |
256 branch = GIT.GetUpstream(cwd) | 256 branch = GIT.GetUpstream(cwd) |
257 command = ['diff', '--name-only', branch, branch_head] | 257 command = ['diff', '--name-only', branch + "..." + branch_head] |
258 return GIT.Capture(command, cwd)[0].splitlines(False) | 258 return GIT.Capture(command, cwd)[0].splitlines(False) |
259 | 259 |
260 @staticmethod | 260 @staticmethod |
261 def GetPatchName(cwd): | 261 def GetPatchName(cwd): |
262 """Constructs a name for this patch.""" | 262 """Constructs a name for this patch.""" |
263 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd)[0].strip() | 263 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd)[0].strip() |
264 return "%s-%s" % (GIT.GetBranch(cwd), short_sha) | 264 return "%s-%s" % (GIT.GetBranch(cwd), short_sha) |
265 | 265 |
266 @staticmethod | 266 @staticmethod |
267 def GetCheckoutRoot(path): | 267 def GetCheckoutRoot(path): |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 if not cur_dir_repo_root: | 756 if not cur_dir_repo_root: |
757 return None | 757 return None |
758 | 758 |
759 while True: | 759 while True: |
760 parent = os.path.dirname(directory) | 760 parent = os.path.dirname(directory) |
761 if (SVN.CaptureInfo(parent, print_error=False).get( | 761 if (SVN.CaptureInfo(parent, print_error=False).get( |
762 "Repository Root") != cur_dir_repo_root): | 762 "Repository Root") != cur_dir_repo_root): |
763 break | 763 break |
764 directory = parent | 764 directory = parent |
765 return GetCasedPath(directory) | 765 return GetCasedPath(directory) |
OLD | NEW |