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 os | 7 import os |
8 import re | 8 import re |
9 import shutil | 9 import shutil |
10 import subprocess | 10 import subprocess |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 @staticmethod | 171 @staticmethod |
172 def GetUpstream(cwd): | 172 def GetUpstream(cwd): |
173 """Gets the current branch's upstream branch.""" | 173 """Gets the current branch's upstream branch.""" |
174 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) | 174 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) |
175 if remote is not '.': | 175 if remote is not '.': |
176 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) | 176 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) |
177 return upstream_branch | 177 return upstream_branch |
178 | 178 |
179 @staticmethod | 179 @staticmethod |
180 def GenerateDiff(cwd, branch=None): | 180 def GenerateDiff(cwd, branch=None, full_move=False): |
181 """Diffs against the upstream branch or optionally another branch.""" | 181 """Diffs against the upstream branch or optionally another branch. |
| 182 |
| 183 full_move means that move or copy operations should completely recreate the |
| 184 files, usually in the prospect to apply the patch for a try job.""" |
182 if not branch: | 185 if not branch: |
183 branch = GIT.GetUpstream(cwd) | 186 branch = GIT.GetUpstream(cwd) |
184 diff = GIT.Capture(['diff-tree', '-p', '--no-prefix', branch, 'HEAD'], | 187 command = ['diff-tree', '-p', '--no-prefix', branch, 'HEAD'] |
185 cwd).splitlines(True) | 188 if not full_move: |
| 189 command.append('-C') |
| 190 diff = GIT.Capture(command, cwd).splitlines(True) |
186 for i in range(len(diff)): | 191 for i in range(len(diff)): |
187 # In the case of added files, replace /dev/null with the path to the | 192 # In the case of added files, replace /dev/null with the path to the |
188 # file being added. | 193 # file being added. |
189 if diff[i].startswith('--- /dev/null'): | 194 if diff[i].startswith('--- /dev/null'): |
190 diff[i] = '--- %s' % diff[i+1][4:] | 195 diff[i] = '--- %s' % diff[i+1][4:] |
191 return ''.join(diff) | 196 return ''.join(diff) |
192 | 197 |
193 @staticmethod | 198 @staticmethod |
194 def GetPatchName(cwd): | 199 def GetPatchName(cwd): |
195 """Constructs a name for this patch.""" | 200 """Constructs a name for this patch.""" |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 output.endswith("is not under version control")): | 522 output.endswith("is not under version control")): |
518 return "" | 523 return "" |
519 else: | 524 else: |
520 return output | 525 return output |
521 | 526 |
522 @staticmethod | 527 @staticmethod |
523 def DiffItem(filename, full_move=False): | 528 def DiffItem(filename, full_move=False): |
524 """Diffs a single file. | 529 """Diffs a single file. |
525 | 530 |
526 Be sure to be in the appropriate directory before calling to have the | 531 Be sure to be in the appropriate directory before calling to have the |
527 expected relative path.""" | 532 expected relative path. |
| 533 full_move means that move or copy operations should completely recreate the |
| 534 files, usually in the prospect to apply the patch for a try job.""" |
528 # Use svn info output instead of os.path.isdir because the latter fails | 535 # Use svn info output instead of os.path.isdir because the latter fails |
529 # when the file is deleted. | 536 # when the file is deleted. |
530 if SVN.CaptureInfo(filename).get("Node Kind") == "directory": | 537 if SVN.CaptureInfo(filename).get("Node Kind") == "directory": |
531 return None | 538 return None |
532 # If the user specified a custom diff command in their svn config file, | 539 # If the user specified a custom diff command in their svn config file, |
533 # then it'll be used when we do svn diff, which we don't want to happen | 540 # then it'll be used when we do svn diff, which we don't want to happen |
534 # since we want the unified diff. Using --diff-cmd=diff doesn't always | 541 # since we want the unified diff. Using --diff-cmd=diff doesn't always |
535 # work, since they can have another diff executable in their path that | 542 # work, since they can have another diff executable in their path that |
536 # gives different line endings. So we use a bogus temp directory as the | 543 # gives different line endings. So we use a bogus temp directory as the |
537 # config directory, which gets around these problems. | 544 # config directory, which gets around these problems. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 if not cur_dir_repo_root: | 667 if not cur_dir_repo_root: |
661 return None | 668 return None |
662 | 669 |
663 while True: | 670 while True: |
664 parent = os.path.dirname(directory) | 671 parent = os.path.dirname(directory) |
665 if (SVN.CaptureInfo(parent, print_error=False).get( | 672 if (SVN.CaptureInfo(parent, print_error=False).get( |
666 "Repository Root") != cur_dir_repo_root): | 673 "Repository Root") != cur_dir_repo_root): |
667 break | 674 break |
668 directory = parent | 675 directory = parent |
669 return directory | 676 return directory |
OLD | NEW |