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

Side by Side Diff: git_cl.py

Issue 9969099: Allow overriding base-url in git-cl. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 8 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 | Annotate | Revision Log
« 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.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 import logging 10 import logging
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 'by running "git svn info" as documented here: %s', 404 'by running "git svn info" as documented here: %s',
405 self._remote, 405 self._remote,
406 GIT_INSTRUCTIONS_URL) 406 GIT_INSTRUCTIONS_URL)
407 else: 407 else:
408 logging.warn('Could not determine which remote this change is ' 408 logging.warn('Could not determine which remote this change is '
409 'associated with. You may prevent this message by ' 409 'associated with. You may prevent this message by '
410 'running "git svn info" as documented here: %s', 410 'running "git svn info" as documented here: %s',
411 GIT_INSTRUCTIONS_URL) 411 GIT_INSTRUCTIONS_URL)
412 return self._remote 412 return self._remote
413 413
414 def GetGitBaseUrlFromConfig(self):
415 """Return the configured base URL from branch.<branchname>.baseurl.
416
417 Returns None if it is not set.
418 """
419 return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()],
420 error_ok=True).strip()
414 421
415 def GetRemoteUrl(self): 422 def GetRemoteUrl(self):
416 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. 423 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'.
417 424
418 Returns None if there is no remote. 425 Returns None if there is no remote.
419 """ 426 """
420 remote = self.GetRemote() 427 remote = self.GetRemote()
421 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() 428 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip()
422 429
423 def GetIssue(self): 430 def GetIssue(self):
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 url = args[0] 787 url = args[0]
781 if not url.endswith('codereview.settings'): 788 if not url.endswith('codereview.settings'):
782 url = os.path.join(url, 'codereview.settings') 789 url = os.path.join(url, 'codereview.settings')
783 790
784 # Load code review settings and download hooks (if available). 791 # Load code review settings and download hooks (if available).
785 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) 792 LoadCodereviewSettingsFromFile(urllib2.urlopen(url))
786 DownloadHooks(True) 793 DownloadHooks(True)
787 return 0 794 return 0
788 795
789 796
797 def CMDbaseurl(parser, args):
798 """get or set base-url for this branch"""
799 branchref = RunGit(['symbolic-ref', 'HEAD']).strip()
800 branch = ShortBranchName(branchref)
801 _, args = parser.parse_args(args)
802 if not args:
803 print("Current base-url:")
804 return RunGit(['config', 'branch.%s.base-url' % branch],
M-A Ruel 2012/04/03 15:29:58 Won't this crash if the value is not present?
kalmard 2012/04/03 15:37:42 It returns a valid error. I don't think that's a p
805 error_ok=False).strip()
806 else:
807 print("Setting base-url to %s" % args[0])
808 return RunGit(['config', 'branch.%s.base-url' % branch, args[0]],
M-A Ruel 2012/04/03 15:29:58 Also, isn't this annoying to have this per branch
kalmard 2012/04/03 15:37:42 I figured it made sense to make this per-branch si
809 error_ok=False).strip()
810
811
790 def CMDstatus(parser, args): 812 def CMDstatus(parser, args):
791 """show status of changelists""" 813 """show status of changelists"""
792 parser.add_option('--field', 814 parser.add_option('--field',
793 help='print only specific field (desc|id|patch|url)') 815 help='print only specific field (desc|id|patch|url)')
794 (options, args) = parser.parse_args(args) 816 (options, args) = parser.parse_args(args)
795 817
796 # TODO: maybe make show_branches a flag if necessary. 818 # TODO: maybe make show_branches a flag if necessary.
797 show_branches = not options.field 819 show_branches = not options.field
798 820
799 if show_branches: 821 if show_branches:
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 if options.send_mail: 997 if options.send_mail:
976 if not change_desc.reviewers: 998 if not change_desc.reviewers:
977 DieWithError("Must specify reviewers to send email.") 999 DieWithError("Must specify reviewers to send email.")
978 upload_args.append('--send_mail') 1000 upload_args.append('--send_mail')
979 cc = ','.join(filter(None, (cl.GetCCList(), options.cc))) 1001 cc = ','.join(filter(None, (cl.GetCCList(), options.cc)))
980 if cc: 1002 if cc:
981 upload_args.extend(['--cc', cc]) 1003 upload_args.extend(['--cc', cc])
982 1004
983 # Include the upstream repo's URL in the change -- this is useful for 1005 # Include the upstream repo's URL in the change -- this is useful for
984 # projects that have their source spread across multiple repos. 1006 # projects that have their source spread across multiple repos.
985 remote_url = None 1007 remote_url = cl.GetGitBaseUrlFromConfig()
986 if settings.GetIsGitSvn(): 1008 if not remote_url:
987 # URL is dependent on the current directory. 1009 if settings.GetIsGitSvn():
988 data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) 1010 # URL is dependent on the current directory.
989 if data: 1011 data = RunGit(['svn', 'info'], cwd=settings.GetRoot())
990 keys = dict(line.split(': ', 1) for line in data.splitlines() 1012 if data:
991 if ': ' in line) 1013 keys = dict(line.split(': ', 1) for line in data.splitlines()
992 remote_url = keys.get('URL', None) 1014 if ': ' in line)
993 else: 1015 remote_url = keys.get('URL', None)
994 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): 1016 else:
995 remote_url = (cl.GetRemoteUrl() + '@' 1017 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch():
996 + cl.GetUpstreamBranch().split('/')[-1]) 1018 remote_url = (cl.GetRemoteUrl() + '@'
1019 + cl.GetUpstreamBranch().split('/')[-1])
997 if remote_url: 1020 if remote_url:
998 upload_args.extend(['--base_url', remote_url]) 1021 upload_args.extend(['--base_url', remote_url])
999 1022
1000 try: 1023 try:
1001 issue, patchset = upload.RealMain(['upload'] + upload_args + args) 1024 issue, patchset = upload.RealMain(['upload'] + upload_args + args)
1002 except KeyboardInterrupt: 1025 except KeyboardInterrupt:
1003 sys.exit(1) 1026 sys.exit(1)
1004 except: 1027 except:
1005 # If we got an exception after the user typed a description for their 1028 # If we got an exception after the user typed a description for their
1006 # change, back up the description before re-raising. 1029 # change, back up the description before re-raising.
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1544 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1522 1545
1523 # Not a known command. Default to help. 1546 # Not a known command. Default to help.
1524 GenUsage(parser, 'help') 1547 GenUsage(parser, 'help')
1525 return CMDhelp(parser, argv) 1548 return CMDhelp(parser, argv)
1526 1549
1527 1550
1528 if __name__ == '__main__': 1551 if __name__ == '__main__':
1529 fix_encoding.fix_encoding() 1552 fix_encoding.fix_encoding()
1530 sys.exit(main(sys.argv[1:])) 1553 sys.exit(main(sys.argv[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