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

Unified 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: Make tests use $GIT_EDITOR instead of $EDITOR (previously they failed for me, as $EDITOR was overriā€¦ Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
diff --git a/gclient_utils.py b/gclient_utils.py
index ddcce9b17746568b242c6fead28287c1ea834c5f..041813b0d164322a816669b175e3f7259ac109cb 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -678,13 +678,29 @@ class ExecutionQueue(object):
work_queue.ready_cond.release()
-def GetEditor(git):
- """Returns the most plausible editor to use."""
+def GetEditor(git, git_editor=None):
+ """Returns the most plausible editor to use.
+
+ In order of preference:
+ - GIT_EDITOR/SVN_EDITOR environment variable
+ - core.editor git configuration variable (if supplied by git-cl)
+ - VISUAL environment variable
+ - EDITOR environment variable
+ - vim (non-Windows) or notepad (Windows)
+
+ In the case of git-cl, this matches git's behaviour, except that it does not
+ include dumb terminal detection.
+
+ In the case of gcl, this matches svn's behaviour, except that it does not
+ accept a command-line flag or check the editor-cmd configuration variable.
+ """
if git:
- editor = os.environ.get('GIT_EDITOR')
+ editor = os.environ.get('GIT_EDITOR') or git_editor
else:
editor = os.environ.get('SVN_EDITOR')
if not editor:
+ editor = os.environ.get('VISUAL')
+ if not editor:
editor = os.environ.get('EDITOR')
if not editor:
if sys.platform.startswith('win'):
@@ -694,7 +710,7 @@ def GetEditor(git):
return editor
-def RunEditor(content, git):
+def RunEditor(content, git, git_editor=None):
"""Opens up the default editor in the system to get the CL description."""
file_handle, filename = tempfile.mkstemp(text=True)
# Make sure CRLF is handled properly by requiring none.
@@ -707,7 +723,10 @@ def RunEditor(content, git):
fileobj.close()
try:
- cmd = '%s %s' % (GetEditor(git), filename)
+ editor = GetEditor(git, git_editor=git_editor)
+ if not editor:
+ return None
+ cmd = '%s %s' % (editor, filename)
if sys.platform == 'win32' and os.environ.get('TERM') == 'msys':
# Msysgit requires the usage of 'env' to be present.
cmd = 'env ' + cmd
« 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