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

Side by Side Diff: git_cl.py

Issue 1873233002: git cl checkout: implement for Gerrit + add test. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@G200-fox
Patch Set: Created 4 years, 8 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 | tests/git_cl_test.py » ('j') | 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 and Gerrit.""" 8 """A git-command for integrating reviews on Rietveld and Gerrit."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 raise NotImplementedError() 1361 raise NotImplementedError()
1362 1362
1363 def FetchDescription(self): 1363 def FetchDescription(self):
1364 """Fetches and returns description from the codereview server.""" 1364 """Fetches and returns description from the codereview server."""
1365 raise NotImplementedError() 1365 raise NotImplementedError()
1366 1366
1367 def GetCodereviewServerSetting(self): 1367 def GetCodereviewServerSetting(self):
1368 """Returns git config setting for the codereview server.""" 1368 """Returns git config setting for the codereview server."""
1369 raise NotImplementedError() 1369 raise NotImplementedError()
1370 1370
1371 @staticmethod 1371 @classmethod
1372 def IssueSetting(branch): 1372 def IssueSetting(cls, branch):
1373 return 'branch.%s.%s' % (branch, cls.IssueSettingPrefix())
1374
1375 @classmethod
1376 def IssueSettingPrefix(cls):
1373 """Returns name of git config setting which stores issue number for a given 1377 """Returns name of git config setting which stores issue number for a given
1374 branch.""" 1378 branch."""
1375 raise NotImplementedError() 1379 raise NotImplementedError()
1376 1380
1377 def PatchsetSetting(self): 1381 def PatchsetSetting(self):
1378 """Returns name of git config setting which stores issue number.""" 1382 """Returns name of git config setting which stores issue number."""
1379 raise NotImplementedError() 1383 raise NotImplementedError()
1380 1384
1381 def GetRieveldObjForPresubmit(self): 1385 def GetRieveldObjForPresubmit(self):
1382 # This is an unfortunate Rietveld-embeddedness in presubmit. 1386 # This is an unfortunate Rietveld-embeddedness in presubmit.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 1573
1570 def RpcServer(self): 1574 def RpcServer(self):
1571 """Returns an upload.RpcServer() to access this review's rietveld instance. 1575 """Returns an upload.RpcServer() to access this review's rietveld instance.
1572 """ 1576 """
1573 if not self._rpc_server: 1577 if not self._rpc_server:
1574 self._rpc_server = rietveld.CachingRietveld( 1578 self._rpc_server = rietveld.CachingRietveld(
1575 self.GetCodereviewServer(), 1579 self.GetCodereviewServer(),
1576 self._auth_config or auth.make_auth_config()) 1580 self._auth_config or auth.make_auth_config())
1577 return self._rpc_server 1581 return self._rpc_server
1578 1582
1579 @staticmethod 1583 @classmethod
1580 def IssueSetting(branch): 1584 def IssueSettingPrefix(cls):
1581 return 'branch.%s.rietveldissue' % branch 1585 return 'rietveldissue'
1582 1586
1583 def PatchsetSetting(self): 1587 def PatchsetSetting(self):
1584 """Return the git setting that stores this change's most recent patchset.""" 1588 """Return the git setting that stores this change's most recent patchset."""
1585 return 'branch.%s.rietveldpatchset' % self.GetBranch() 1589 return 'branch.%s.rietveldpatchset' % self.GetBranch()
1586 1590
1587 def GetCodereviewServerSetting(self): 1591 def GetCodereviewServerSetting(self):
1588 """Returns the git setting that stores this change's rietveld server.""" 1592 """Returns the git setting that stores this change's rietveld server."""
1589 branch = self.GetBranch() 1593 branch = self.GetBranch()
1590 if branch: 1594 if branch:
1591 return 'branch.%s.rietveldserver' % branch 1595 return 'branch.%s.rietveldserver' % branch
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 self._gerrit_host = urlparse.urlparse(self._gerrit_server).netloc 1714 self._gerrit_host = urlparse.urlparse(self._gerrit_server).netloc
1711 if not self._gerrit_server: 1715 if not self._gerrit_server:
1712 # We assume repo to be hosted on Gerrit, and hence Gerrit server 1716 # We assume repo to be hosted on Gerrit, and hence Gerrit server
1713 # has "-review" suffix for lowest level subdomain. 1717 # has "-review" suffix for lowest level subdomain.
1714 parts = urlparse.urlparse(self.GetRemoteUrl()).netloc.split('.') 1718 parts = urlparse.urlparse(self.GetRemoteUrl()).netloc.split('.')
1715 parts[0] = parts[0] + '-review' 1719 parts[0] = parts[0] + '-review'
1716 self._gerrit_host = '.'.join(parts) 1720 self._gerrit_host = '.'.join(parts)
1717 self._gerrit_server = 'https://%s' % self._gerrit_host 1721 self._gerrit_server = 'https://%s' % self._gerrit_host
1718 return self._gerrit_server 1722 return self._gerrit_server
1719 1723
1720 @staticmethod 1724 @classmethod
1721 def IssueSetting(branch): 1725 def IssueSettingPrefix(cls):
1722 return 'branch.%s.gerritissue' % branch 1726 return 'gerritissue'
1723 1727
1724 def PatchsetSetting(self): 1728 def PatchsetSetting(self):
1725 """Return the git setting that stores this change's most recent patchset.""" 1729 """Return the git setting that stores this change's most recent patchset."""
1726 return 'branch.%s.gerritpatchset' % self.GetBranch() 1730 return 'branch.%s.gerritpatchset' % self.GetBranch()
1727 1731
1728 def GetCodereviewServerSetting(self): 1732 def GetCodereviewServerSetting(self):
1729 """Returns the git setting that stores this change's Gerrit server.""" 1733 """Returns the git setting that stores this change's Gerrit server."""
1730 branch = self.GetBranch() 1734 branch = self.GetBranch()
1731 if branch: 1735 if branch:
1732 return 'branch.%s.gerritserver' % branch 1736 return 'branch.%s.gerritserver' % branch
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after
4525 for gn_diff_file in gn_diff_files: 4529 for gn_diff_file in gn_diff_files:
4526 stdout = RunCommand(cmd + [gn_diff_file], cwd=top_dir) 4530 stdout = RunCommand(cmd + [gn_diff_file], cwd=top_dir)
4527 if opts.diff: 4531 if opts.diff:
4528 sys.stdout.write(stdout) 4532 sys.stdout.write(stdout)
4529 4533
4530 return return_value 4534 return return_value
4531 4535
4532 4536
4533 @subcommand.usage('<codereview url or issue id>') 4537 @subcommand.usage('<codereview url or issue id>')
4534 def CMDcheckout(parser, args): 4538 def CMDcheckout(parser, args):
4535 """Checks out a branch associated with a given Rietveld issue.""" 4539 """Checks out a branch associated with a given Rietveld or Gerrit issue."""
4536 # TODO(tandrii): consider adding this for Gerrit?
4537 _, args = parser.parse_args(args) 4540 _, args = parser.parse_args(args)
4538 4541
4539 if len(args) != 1: 4542 if len(args) != 1:
4540 parser.print_help() 4543 parser.print_help()
4541 return 1 4544 return 1
4542 4545
4543 issue_arg = ParseIssueNumberArgument(args[0]) 4546 issue_arg = ParseIssueNumberArgument(args[0])
4544 if not issue_arg.valid: 4547 if not issue_arg.valid:
4545 parser.print_help() 4548 parser.print_help()
4546 return 1 4549 return 1
4547 target_issue = str(issue_arg.issue) 4550 target_issue = str(issue_arg.issue)
4548 4551
4549 key_and_issues = [x.split() for x in RunGit( 4552 def find_issues(issueprefix):
4550 ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue']) 4553 key_and_issues = [x.split() for x in RunGit(
4551 .splitlines()] 4554 ['config', '--local', '--get-regexp', r'branch\..*\.%s' % issueprefix])
4555 .splitlines()]
4556 for key, issue in key_and_issues:
4557 if issue == target_issue:
4558 yield re.sub(r'branch\.(.*)\.%s' % issueprefix, r'\1', key)
4559
4552 branches = [] 4560 branches = []
4553 for key, issue in key_and_issues: 4561 for cls in _CODEREVIEW_IMPLEMENTATIONS.values():
4554 if issue == target_issue: 4562 branches.extend(find_issues(cls.IssueSettingPrefix()))
4555 branches.append(re.sub(r'branch\.(.*)\.rietveldissue', r'\1', key))
4556
4557 if len(branches) == 0: 4563 if len(branches) == 0:
4558 print 'No branch found for issue %s.' % target_issue 4564 print 'No branch found for issue %s.' % target_issue
4559 return 1 4565 return 1
4560 if len(branches) == 1: 4566 if len(branches) == 1:
4561 RunGit(['checkout', branches[0]]) 4567 RunGit(['checkout', branches[0]])
4562 else: 4568 else:
4563 print 'Multiple branches match issue %s:' % target_issue 4569 print 'Multiple branches match issue %s:' % target_issue
4564 for i in range(len(branches)): 4570 for i in range(len(branches)):
4565 print '%d: %s' % (i, branches[i]) 4571 print '%d: %s' % (i, branches[i])
4566 which = raw_input('Choose by index: ') 4572 which = raw_input('Choose by index: ')
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4628 if __name__ == '__main__': 4634 if __name__ == '__main__':
4629 # These affect sys.stdout so do it outside of main() to simplify mocks in 4635 # These affect sys.stdout so do it outside of main() to simplify mocks in
4630 # unit testing. 4636 # unit testing.
4631 fix_encoding.fix_encoding() 4637 fix_encoding.fix_encoding()
4632 setup_color.init() 4638 setup_color.init()
4633 try: 4639 try:
4634 sys.exit(main(sys.argv[1:])) 4640 sys.exit(main(sys.argv[1:]))
4635 except KeyboardInterrupt: 4641 except KeyboardInterrupt:
4636 sys.stderr.write('interrupted\n') 4642 sys.stderr.write('interrupted\n')
4637 sys.exit(1) 4643 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698