Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: git_cl.py

Issue 10907229: Running git cl patch sets the rietveld patchset. (Closed) Base URL: https://git.chromium.org/chromium/tools/depot_tools.git@master
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 import json 10 import json
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 502
503 def SetPatchset(self, patchset): 503 def SetPatchset(self, patchset):
504 """Set this branch's patchset. If patchset=0, clears the patchset.""" 504 """Set this branch's patchset. If patchset=0, clears the patchset."""
505 if patchset: 505 if patchset:
506 RunGit(['config', self._PatchsetSetting(), str(patchset)]) 506 RunGit(['config', self._PatchsetSetting(), str(patchset)])
507 else: 507 else:
508 RunGit(['config', '--unset', self._PatchsetSetting()], 508 RunGit(['config', '--unset', self._PatchsetSetting()],
509 stderr=subprocess2.PIPE, error_ok=True) 509 stderr=subprocess2.PIPE, error_ok=True)
510 self.has_patchset = False 510 self.has_patchset = False
511 511
512 def GetPatchSetDiff(self, issue): 512 def GetMostRecentPatchset(self, issue):
513 patchset = self.RpcServer().get_issue_properties( 513 return self.RpcServer().get_issue_properties(
514 int(issue), False)['patchsets'][-1] 514 int(issue), False)['patchsets'][-1]
515
516 def GetPatchSetDiff(self, issue, patchset):
515 return self.RpcServer().get( 517 return self.RpcServer().get(
516 '/download/issue%s_%s.diff' % (issue, patchset)) 518 '/download/issue%s_%s.diff' % (issue, patchset))
517 519
518 def SetIssue(self, issue): 520 def SetIssue(self, issue):
519 """Set this branch's issue. If issue=0, clears the issue.""" 521 """Set this branch's issue. If issue=0, clears the issue."""
520 if issue: 522 if issue:
521 RunGit(['config', self._IssueSetting(), str(issue)]) 523 RunGit(['config', self._IssueSetting(), str(issue)])
522 if self.rietveld_server: 524 if self.rietveld_server:
523 RunGit(['config', self._RietveldServer(), self.rietveld_server]) 525 RunGit(['config', self._RietveldServer(), self.rietveld_server])
524 else: 526 else:
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 if len(args) != 1: 1398 if len(args) != 1:
1397 parser.print_help() 1399 parser.print_help()
1398 return 1 1400 return 1
1399 issue_arg = args[0] 1401 issue_arg = args[0]
1400 1402
1401 # TODO(maruel): Use apply_issue.py 1403 # TODO(maruel): Use apply_issue.py
1402 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? 1404 # TODO(ukai): use gerrit-cherry-pick for gerrit repository?
1403 1405
1404 if issue_arg.isdigit(): 1406 if issue_arg.isdigit():
1405 # Input is an issue id. Figure out the URL. 1407 # Input is an issue id. Figure out the URL.
1408 cl = Changelist()
1406 issue = int(issue_arg) 1409 issue = int(issue_arg)
1407 patch_data = Changelist().GetPatchSetDiff(issue) 1410 patchset = cl.GetMostRecentPatchset(issue)
1411 patch_data = cl.GetPatchSetDiff(issue, patchset)
1408 else: 1412 else:
1409 # Assume it's a URL to the patch. Default to https. 1413 # Assume it's a URL to the patch. Default to https.
1410 issue_url = gclient_utils.UpgradeToHttps(issue_arg) 1414 issue_url = gclient_utils.UpgradeToHttps(issue_arg)
1411 match = re.match(r'.*?/issue(\d+)_\d+.diff', issue_url) 1415 match = re.match(r'.*?/issue(\d+)_(\d+).diff', issue_url)
1412 if not match: 1416 if not match:
1413 DieWithError('Must pass an issue ID or full URL for ' 1417 DieWithError('Must pass an issue ID or full URL for '
1414 '\'Download raw patch set\'') 1418 '\'Download raw patch set\'')
1415 issue = int(match.group(1)) 1419 issue = int(match.group(1))
1420 patchset = int(match.group(2))
1416 patch_data = urllib2.urlopen(issue_arg).read() 1421 patch_data = urllib2.urlopen(issue_arg).read()
1417 1422
1418 if options.newbranch: 1423 if options.newbranch:
1419 if options.force: 1424 if options.force:
1420 RunGit(['branch', '-D', options.newbranch], 1425 RunGit(['branch', '-D', options.newbranch],
1421 stderr=subprocess2.PIPE, error_ok=True) 1426 stderr=subprocess2.PIPE, error_ok=True)
1422 RunGit(['checkout', '-b', options.newbranch, 1427 RunGit(['checkout', '-b', options.newbranch,
1423 Changelist().GetUpstreamBranch()]) 1428 Changelist().GetUpstreamBranch()])
1424 1429
1425 # Switch up to the top-level directory, if necessary, in preparation for 1430 # Switch up to the top-level directory, if necessary, in preparation for
(...skipping 21 matching lines...) Expand all
1447 try: 1452 try:
1448 subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID) 1453 subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID)
1449 except subprocess2.CalledProcessError: 1454 except subprocess2.CalledProcessError:
1450 DieWithError('Failed to apply the patch') 1455 DieWithError('Failed to apply the patch')
1451 1456
1452 # If we had an issue, commit the current state and register the issue. 1457 # If we had an issue, commit the current state and register the issue.
1453 if not options.nocommit: 1458 if not options.nocommit:
1454 RunGit(['commit', '-m', 'patch from issue %s' % issue]) 1459 RunGit(['commit', '-m', 'patch from issue %s' % issue])
1455 cl = Changelist() 1460 cl = Changelist()
1456 cl.SetIssue(issue) 1461 cl.SetIssue(issue)
1462 cl.SetPatchset(patchset)
1457 print "Committed patch." 1463 print "Committed patch."
1458 else: 1464 else:
1459 print "Patch applied to index." 1465 print "Patch applied to index."
1460 return 0 1466 return 0
1461 1467
1462 1468
1463 def CMDrebase(parser, args): 1469 def CMDrebase(parser, args):
1464 """rebase current branch on top of svn repo""" 1470 """rebase current branch on top of svn repo"""
1465 # Provide a wrapper for git svn rebase to help avoid accidental 1471 # Provide a wrapper for git svn rebase to help avoid accidental
1466 # git svn dcommit. 1472 # git svn dcommit.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 builders_and_tests.setdefault(bot, []).append('defaulttests') 1586 builders_and_tests.setdefault(bot, []).append('defaulttests')
1581 1587
1582 if options.testfilter: 1588 if options.testfilter:
1583 forced_tests = sum((t.split(',') for t in options.testfilter), []) 1589 forced_tests = sum((t.split(',') for t in options.testfilter), [])
1584 builders_and_tests = dict( 1590 builders_and_tests = dict(
1585 (b, forced_tests) for b, t in builders_and_tests.iteritems() 1591 (b, forced_tests) for b, t in builders_and_tests.iteritems()
1586 if t != ['compile']) 1592 if t != ['compile'])
1587 1593
1588 patchset = cl.GetPatchset() 1594 patchset = cl.GetPatchset()
1589 if not cl.GetPatchset(): 1595 if not cl.GetPatchset():
1590 properties = cl.RpcServer().get_issue_properties(cl.GetIssue(), False) 1596 patchset = cl.GetMostRecentPatchset(cl.GetIssue())
1591 patchset = properties['patchsets'][-1]
1592 1597
1593 cl.RpcServer().trigger_try_jobs( 1598 cl.RpcServer().trigger_try_jobs(
1594 cl.GetIssue(), patchset, options.name, options.clobber, options.revision, 1599 cl.GetIssue(), patchset, options.name, options.clobber, options.revision,
1595 builders_and_tests) 1600 builders_and_tests)
1596 return 0 1601 return 0
1597 1602
1598 1603
1599 @usage('[new upstream branch]') 1604 @usage('[new upstream branch]')
1600 def CMDupstream(parser, args): 1605 def CMDupstream(parser, args):
1601 """prints or sets the name of the upstream branch, if any""" 1606 """prints or sets the name of the upstream branch, if any"""
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1704 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1700 1705
1701 # Not a known command. Default to help. 1706 # Not a known command. Default to help.
1702 GenUsage(parser, 'help') 1707 GenUsage(parser, 'help')
1703 return CMDhelp(parser, argv) 1708 return CMDhelp(parser, argv)
1704 1709
1705 1710
1706 if __name__ == '__main__': 1711 if __name__ == '__main__':
1707 fix_encoding.fix_encoding() 1712 fix_encoding.fix_encoding()
1708 sys.exit(main(sys.argv[1:])) 1713 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698