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

Side by Side Diff: gclient_utils.py

Issue 14854003: Make git-cl more accurately imitate git's editor selection process, and respect $VISUAL. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 7 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 | git_cl.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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic utils.""" 5 """Generic utils."""
6 6
7 import codecs 7 import codecs
8 import logging 8 import logging
9 import os 9 import os
10 import Queue 10 import Queue
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 work_queue.exceptions.put(sys.exc_info()) 671 work_queue.exceptions.put(sys.exc_info())
672 logging.info('_Worker.run(%s) done' % self.item.name) 672 logging.info('_Worker.run(%s) done' % self.item.name)
673 673
674 work_queue.ready_cond.acquire() 674 work_queue.ready_cond.acquire()
675 try: 675 try:
676 work_queue.ready_cond.notifyAll() 676 work_queue.ready_cond.notifyAll()
677 finally: 677 finally:
678 work_queue.ready_cond.release() 678 work_queue.ready_cond.release()
679 679
680 680
681 def GetEditor(git): 681 def GetEditor(git, git_editor=None):
682 """Returns the most plausible editor to use.""" 682 """Returns the most plausible editor to use."""
683 terminal = os.environ.get('TERM')
684 terminal_is_dumb = not terminal or terminal == 'dumb'
683 if git: 685 if git:
684 editor = os.environ.get('GIT_EDITOR') 686 editor = os.environ.get('GIT_EDITOR') or git_editor
685 else: 687 else:
686 editor = os.environ.get('SVN_EDITOR') 688 editor = os.environ.get('SVN_EDITOR')
689 if not editor and not (git and terminal_is_dumb):
690 editor = os.environ.get('VISUAL')
687 if not editor: 691 if not editor:
688 editor = os.environ.get('EDITOR') 692 editor = os.environ.get('EDITOR')
689 if not editor: 693 if not editor:
690 if sys.platform.startswith('win'): 694 if git and terminal_is_dumb:
695 editor = None
M-A Ruel 2013/05/02 14:13:48 You assume we're going to call git here?
jbroman 2013/05/02 14:27:30 I did this for completeness. git-commit (et al) i
M-A Ruel 2013/05/02 14:35:17 I'd prefer to document it then. There's no referen
696 elif sys.platform.startswith('win'):
691 editor = 'notepad' 697 editor = 'notepad'
692 else: 698 else:
693 editor = 'vim' 699 editor = 'vim'
694 return editor 700 return editor
695 701
696 702
697 def RunEditor(content, git): 703 def RunEditor(content, git, git_editor=None):
698 """Opens up the default editor in the system to get the CL description.""" 704 """Opens up the default editor in the system to get the CL description."""
699 file_handle, filename = tempfile.mkstemp(text=True) 705 file_handle, filename = tempfile.mkstemp(text=True)
700 # Make sure CRLF is handled properly by requiring none. 706 # Make sure CRLF is handled properly by requiring none.
701 if '\r' in content: 707 if '\r' in content:
702 print >> sys.stderr, ( 708 print >> sys.stderr, (
703 '!! Please remove \\r from your change description !!') 709 '!! Please remove \\r from your change description !!')
704 fileobj = os.fdopen(file_handle, 'w') 710 fileobj = os.fdopen(file_handle, 'w')
705 # Still remove \r if present. 711 # Still remove \r if present.
706 fileobj.write(re.sub('\r?\n', '\n', content)) 712 fileobj.write(re.sub('\r?\n', '\n', content))
707 fileobj.close() 713 fileobj.close()
708 714
709 try: 715 try:
710 cmd = '%s %s' % (GetEditor(git), filename) 716 editor = GetEditor(git, git_editor=git_editor)
717 if not editor:
718 return None
719 cmd = '%s %s' % (editor, filename)
711 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': 720 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys':
712 # Msysgit requires the usage of 'env' to be present. 721 # Msysgit requires the usage of 'env' to be present.
713 cmd = 'env ' + cmd 722 cmd = 'env ' + cmd
714 try: 723 try:
715 # shell=True to allow the shell to handle all forms of quotes in 724 # shell=True to allow the shell to handle all forms of quotes in
716 # $EDITOR. 725 # $EDITOR.
717 subprocess2.check_call(cmd, shell=True) 726 subprocess2.check_call(cmd, shell=True)
718 except subprocess2.CalledProcessError: 727 except subprocess2.CalledProcessError:
719 return None 728 return None
720 return FileRead(filename) 729 return FileRead(filename)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 773
765 Python on OSX 10.6 raises a NotImplementedError exception. 774 Python on OSX 10.6 raises a NotImplementedError exception.
766 """ 775 """
767 try: 776 try:
768 import multiprocessing 777 import multiprocessing
769 return multiprocessing.cpu_count() 778 return multiprocessing.cpu_count()
770 except: # pylint: disable=W0702 779 except: # pylint: disable=W0702
771 # Mac OS 10.6 only 780 # Mac OS 10.6 only
772 # pylint: disable=E1101 781 # pylint: disable=E1101
773 return int(os.sysconf('SC_NPROCESSORS_ONLN')) 782 return int(os.sysconf('SC_NPROCESSORS_ONLN'))
OLDNEW
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698