| 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 # 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 def __init__(self): | 238 def __init__(self): |
| 239 self.default_server = None | 239 self.default_server = None |
| 240 self.cc = None | 240 self.cc = None |
| 241 self.root = None | 241 self.root = None |
| 242 self.is_git_svn = None | 242 self.is_git_svn = None |
| 243 self.svn_branch = None | 243 self.svn_branch = None |
| 244 self.tree_status_url = None | 244 self.tree_status_url = None |
| 245 self.viewvc_url = None | 245 self.viewvc_url = None |
| 246 self.updated = False | 246 self.updated = False |
| 247 self.is_gerrit = None | 247 self.is_gerrit = None |
| 248 self.git_editor = None |
| 248 | 249 |
| 249 def LazyUpdateIfNeeded(self): | 250 def LazyUpdateIfNeeded(self): |
| 250 """Updates the settings from a codereview.settings file, if available.""" | 251 """Updates the settings from a codereview.settings file, if available.""" |
| 251 if not self.updated: | 252 if not self.updated: |
| 252 cr_settings_file = FindCodereviewSettingsFile() | 253 cr_settings_file = FindCodereviewSettingsFile() |
| 253 if cr_settings_file: | 254 if cr_settings_file: |
| 254 LoadCodereviewSettingsFromFile(cr_settings_file) | 255 LoadCodereviewSettingsFromFile(cr_settings_file) |
| 255 self.updated = True | 256 self.updated = True |
| 256 DownloadHooks(False) | 257 DownloadHooks(False) |
| 257 self.updated = True | 258 self.updated = True |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 363 |
| 363 def GetDefaultCCList(self): | 364 def GetDefaultCCList(self): |
| 364 return self._GetConfig('rietveld.cc', error_ok=True) | 365 return self._GetConfig('rietveld.cc', error_ok=True) |
| 365 | 366 |
| 366 def GetIsGerrit(self): | 367 def GetIsGerrit(self): |
| 367 """Return true if this repo is assosiated with gerrit code review system.""" | 368 """Return true if this repo is assosiated with gerrit code review system.""" |
| 368 if self.is_gerrit is None: | 369 if self.is_gerrit is None: |
| 369 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) | 370 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) |
| 370 return self.is_gerrit | 371 return self.is_gerrit |
| 371 | 372 |
| 373 def GetGitEditor(self): |
| 374 """Return the editor specified in the git config, or None if none is.""" |
| 375 if self.git_editor is None: |
| 376 self.git_editor = self._GetConfig('core.editor', error_ok=True) |
| 377 return self.git_editor or None |
| 378 |
| 372 def _GetConfig(self, param, **kwargs): | 379 def _GetConfig(self, param, **kwargs): |
| 373 self.LazyUpdateIfNeeded() | 380 self.LazyUpdateIfNeeded() |
| 374 return RunGit(['config', param], **kwargs).strip() | 381 return RunGit(['config', param], **kwargs).strip() |
| 375 | 382 |
| 376 | 383 |
| 377 def ShortBranchName(branch): | 384 def ShortBranchName(branch): |
| 378 """Convert a name like 'refs/heads/foo' to just 'foo'.""" | 385 """Convert a name like 'refs/heads/foo' to just 'foo'.""" |
| 379 return branch.replace('refs/heads/', '') | 386 return branch.replace('refs/heads/', '') |
| 380 | 387 |
| 381 | 388 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 def prompt(self): | 853 def prompt(self): |
| 847 """Asks the user to update the description.""" | 854 """Asks the user to update the description.""" |
| 848 self._description = ( | 855 self._description = ( |
| 849 '# Enter a description of the change.\n' | 856 '# Enter a description of the change.\n' |
| 850 '# This will be displayed on the codereview site.\n' | 857 '# This will be displayed on the codereview site.\n' |
| 851 '# The first line will also be used as the subject of the review.\n' | 858 '# The first line will also be used as the subject of the review.\n' |
| 852 ) + self._description | 859 ) + self._description |
| 853 | 860 |
| 854 if '\nBUG=' not in self._description: | 861 if '\nBUG=' not in self._description: |
| 855 self.append_footer('BUG=') | 862 self.append_footer('BUG=') |
| 856 content = gclient_utils.RunEditor(self._description, True) | 863 content = gclient_utils.RunEditor(self._description, True, |
| 864 git_editor=settings.GetGitEditor()) |
| 857 if not content: | 865 if not content: |
| 858 DieWithError('Running editor failed') | 866 DieWithError('Running editor failed') |
| 859 | 867 |
| 860 # Strip off comments. | 868 # Strip off comments. |
| 861 content = re.compile(r'^#.*$', re.MULTILINE).sub('', content).strip() | 869 content = re.compile(r'^#.*$', re.MULTILINE).sub('', content).strip() |
| 862 if not content: | 870 if not content: |
| 863 DieWithError('No CL description, aborting') | 871 DieWithError('No CL description, aborting') |
| 864 self._description = content | 872 self._description = content |
| 865 | 873 |
| 866 def append_footer(self, line): | 874 def append_footer(self, line): |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2005 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1998 | 2006 |
| 1999 # Not a known command. Default to help. | 2007 # Not a known command. Default to help. |
| 2000 GenUsage(parser, 'help') | 2008 GenUsage(parser, 'help') |
| 2001 return CMDhelp(parser, argv) | 2009 return CMDhelp(parser, argv) |
| 2002 | 2010 |
| 2003 | 2011 |
| 2004 if __name__ == '__main__': | 2012 if __name__ == '__main__': |
| 2005 fix_encoding.fix_encoding() | 2013 fix_encoding.fix_encoding() |
| 2006 sys.exit(main(sys.argv[1:])) | 2014 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |