Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Client-side script to send a try job to the try server. It communicates to | 6 """Client-side script to send a try job to the try server. It communicates to |
| 7 the try server by either writting to a svn repository or by directly connecting | 7 the try server by either writting to a svn repository or by directly connecting |
| 8 to the server by HTTP. | 8 to the server by HTTP. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 Use svn to store the try job, specify an alternate email address and use a | 57 Use svn to store the try job, specify an alternate email address and use a |
| 58 premade diff file on the local drive: | 58 premade diff file on the local drive: |
| 59 %(prog)s --email user@example.com | 59 %(prog)s --email user@example.com |
| 60 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff | 60 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff |
| 61 | 61 |
| 62 Running only on a 'mac' slave with revision 123 and clobber first; specify | 62 Running only on a 'mac' slave with revision 123 and clobber first; specify |
| 63 manually the 3 source files to use for the try job: | 63 manually the 3 source files to use for the try job: |
| 64 %(prog)s --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h | 64 %(prog)s --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h |
| 65 -f include/b.h | 65 -f include/b.h |
| 66 """ | 66 """ |
| 67 | 67 |
|
cmp
2012/08/10 23:51:50
nit: insert an empty line before line 67
gavinp
2012/08/12 16:52:16
Done.
| |
| 68 def RunCommand(args, error_ok=False, error_message=None, **kwargs): | |
| 69 try: | |
| 70 return subprocess2.check_output(args, shell=False, **kwargs) | |
| 71 except subprocess2.CalledProcessError, e: | |
| 72 if not error_ok: | |
| 73 DieWithError( | |
| 74 'Command "%s" failed.\n%s' % ( | |
| 75 ' '.join(args), error_message or e.stdout or '')) | |
| 76 return e.stdout | |
| 77 | |
| 78 | |
| 79 def RunGit(args, **kwargs): | |
| 80 """Returns stdout.""" | |
| 81 return RunCommand(['git'] + args, **kwargs) | |
| 82 | |
|
cmp
2012/08/10 23:51:50
nit: insert an empty line before line 82
gavinp
2012/08/12 16:52:16
Done.
| |
| 68 class InvalidScript(Exception): | 83 class InvalidScript(Exception): |
| 69 def __str__(self): | 84 def __str__(self): |
| 70 return self.args[0] + '\n' + HELP_STRING | 85 return self.args[0] + '\n' + HELP_STRING |
| 71 | 86 |
| 72 | 87 |
| 73 class NoTryServerAccess(Exception): | 88 class NoTryServerAccess(Exception): |
| 74 def __str__(self): | 89 def __str__(self): |
| 75 return self.args[0] + '\n' + HELP_STRING | 90 return self.args[0] + '\n' + HELP_STRING |
| 76 | 91 |
| 77 | 92 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 "(via the --track argument to \"git checkout -b ...\"") | 280 "(via the --track argument to \"git checkout -b ...\"") |
| 266 logging.info("GIT(%s)" % self.checkout_root) | 281 logging.info("GIT(%s)" % self.checkout_root) |
| 267 | 282 |
| 268 def CaptureStatus(self): | 283 def CaptureStatus(self): |
| 269 return scm.GIT.CaptureStatus( | 284 return scm.GIT.CaptureStatus( |
| 270 [], | 285 [], |
| 271 self.checkout_root.replace(os.sep, '/'), | 286 self.checkout_root.replace(os.sep, '/'), |
| 272 self.diff_against) | 287 self.diff_against) |
| 273 | 288 |
| 274 def GenerateDiff(self): | 289 def GenerateDiff(self): |
| 290 if RunGit(['diff-index', 'HEAD']): | |
| 291 # TODO(gavinp): Can we just include the index? | |
|
cmp
2012/08/10 23:51:50
safe to remove this line, we can't include the ind
gavinp
2012/08/12 16:52:16
I've removed the comment, and I'll think about thi
| |
| 292 print 'Cannot try with a dirty tree. You must commit locally first.' | |
| 293 return None | |
| 275 return scm.GIT.GenerateDiff( | 294 return scm.GIT.GenerateDiff( |
| 276 self.checkout_root, | 295 self.checkout_root, |
| 277 files=self.files, | 296 files=self.files, |
| 278 full_move=True, | 297 full_move=True, |
| 279 branch=self.diff_against) | 298 branch=self.diff_against) |
| 280 | 299 |
| 281 | 300 |
| 282 def _ParseSendChangeOptions(options): | 301 def _ParseSendChangeOptions(options): |
| 283 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" | 302 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" |
| 284 values = [ | 303 values = [ |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 diff_url = ('%s/download/issue%d_%d.diff' % | 762 diff_url = ('%s/download/issue%d_%d.diff' % |
| 744 (options.rietveld_url, options.issue, options.patchset)) | 763 (options.rietveld_url, options.issue, options.patchset)) |
| 745 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) | 764 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) |
| 746 options.diff = ''.join(diff[0]) | 765 options.diff = ''.join(diff[0]) |
| 747 changed_files = diff[1] | 766 changed_files = diff[1] |
| 748 else: | 767 else: |
| 749 # Use this as the base. | 768 # Use this as the base. |
| 750 root = checkouts[0].checkout_root | 769 root = checkouts[0].checkout_root |
| 751 diffs = [] | 770 diffs = [] |
| 752 for checkout in checkouts: | 771 for checkout in checkouts: |
| 753 diff = checkout.GenerateDiff().splitlines(True) | 772 raw_diff = checkout.GenerateDiff() |
| 773 if not raw_diff: | |
| 774 return 1 | |
| 775 diff = raw_diff.splitlines(True) | |
| 754 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) | 776 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) |
| 755 # Munge it. | 777 # Munge it. |
| 756 diffs.extend(GetMungedDiff(path_diff, diff)[0]) | 778 diffs.extend(GetMungedDiff(path_diff, diff)[0]) |
| 757 options.diff = ''.join(diffs) | 779 options.diff = ''.join(diffs) |
| 758 | 780 |
| 759 if not options.name: | 781 if not options.name: |
| 760 if options.issue: | 782 if options.issue: |
| 761 options.name = 'Issue %s' % options.issue | 783 options.name = 'Issue %s' % options.issue |
| 762 else: | 784 else: |
| 763 options.name = 'Unnamed' | 785 options.name = 'Unnamed' |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 return 1 | 860 return 1 |
| 839 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 861 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 840 print >> sys.stderr, e | 862 print >> sys.stderr, e |
| 841 return 1 | 863 return 1 |
| 842 return 0 | 864 return 0 |
| 843 | 865 |
| 844 | 866 |
| 845 if __name__ == "__main__": | 867 if __name__ == "__main__": |
| 846 fix_encoding.fix_encoding() | 868 fix_encoding.fix_encoding() |
| 847 sys.exit(TryChange(None, None, False)) | 869 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |