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