Make git-cl more accurately imitate git's editor selection process, and respect $VISUAL.

It is somewhat surprising when git-cl, which acts as a git subcommand, launches
a different editor. In particular, git has a config option (core.editor) which
specifies the editor that should be used. Since we already respect $GIT_EDITOR,
it makes sense for git-cl to respect core.editor and $VISUAL as well.

R=maruel@chromium.org
BUG=237504

Review URL: https://chromiumcodereview.appspot.com/14854003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@198101 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index 4e89e06..9f69176 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -245,6 +245,7 @@
     self.viewvc_url = None
     self.updated = False
     self.is_gerrit = None
+    self.git_editor = None
 
   def LazyUpdateIfNeeded(self):
     """Updates the settings from a codereview.settings file, if available."""
@@ -369,6 +370,12 @@
       self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True)
     return self.is_gerrit
 
+  def GetGitEditor(self):
+    """Return the editor specified in the git config, or None if none is."""
+    if self.git_editor is None:
+      self.git_editor = self._GetConfig('core.editor', error_ok=True)
+    return self.git_editor or None
+
   def _GetConfig(self, param, **kwargs):
     self.LazyUpdateIfNeeded()
     return RunGit(['config', param], **kwargs).strip()
@@ -853,7 +860,8 @@
 
     if '\nBUG=' not in self._description:
       self.append_footer('BUG=')
-    content = gclient_utils.RunEditor(self._description, True)
+    content = gclient_utils.RunEditor(self._description, True,
+                                      git_editor=settings.GetGitEditor())
     if not content:
       DieWithError('Running editor failed')