{"thread":{"id":"6977","subject":"[PATCH] Factorize editor handling.","startedAt":"2007-02-26T19:48:12Z","lastAt":"2007-02-27T14:17:34Z","messageCount":2,"participants":["Yann Dirson","Catalin Marinas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35530","messageId":"20070226194812.28907.80551.stgit@gandelf.nowhere.earth","threadId":"6977","inReplyTo":null,"subject":"[PATCH] Factorize editor handling.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-02-26T19:48:12Z","receivedAt":"2007-02-26T19:48:12Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"\nAt the same time we trap the editor error for all editor calls, not\njust when called from \"stg mail\".  We may want to define a new\nexception for this though.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/mail.py |   17 +----------------\n stgit/stack.py         |   14 +-------------\n stgit/utils.py         |   23 ++++++++++++++++++++++-\n 3 files changed, 24 insertions(+), 30 deletions(-)\n\ndiff --git a/stgit/commands/mail.py b/stgit/commands/mail.py\nindex 762829c..151a408 100644\n--- a/stgit/commands/mail.py\n+++ b/stgit/commands/mail.py\n@@ -272,22 +272,7 @@ def __edit_message(msg):\n     f.write(msg)\n     f.close()\n \n-    # the editor\n-    editor = config.get('stgit.editor')\n-    if editor:\n-        pass\n-    elif 'EDITOR' in os.environ:\n-        editor = os.environ['EDITOR']\n-    else:\n-        editor = 'vi'\n-    editor += ' %s' % fname\n-\n-    print 'Invoking the editor: \"%s\"...' % editor,\n-    sys.stdout.flush()\n-    err = os.system(editor)\n-    if err:\n-        raise CmdException, 'editor failed, exit code: %d' % err\n-    print 'done'\n+    call_editor(fname)\n \n     # read the message back\n     f = file(fname)\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 99f10e5..feb77e3 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -91,19 +91,7 @@ def edit_file(series, line, comment, show_patch = True):\n     print >> f, __comment_prefix, 'vi: set textwidth=75 filetype=diff nobackup:'\n     f.close()\n \n-    # the editor\n-    editor = config.get('stgit.editor')\n-    if editor:\n-        pass\n-    elif 'EDITOR' in os.environ:\n-        editor = os.environ['EDITOR']\n-    else:\n-        editor = 'vi'\n-    editor += ' %s' % fname\n-\n-    print 'Invoking the editor: \"%s\"...' % editor,\n-    sys.stdout.flush()\n-    print 'done (exit code: %d)' % os.system(editor)\n+    call_editor(fname)\n \n     f = file(fname, 'r+')\n \ndiff --git a/stgit/utils.py b/stgit/utils.py\nindex 67431ec..d7d4777 100644\n--- a/stgit/utils.py\n+++ b/stgit/utils.py\n@@ -1,7 +1,8 @@\n \"\"\"Common utility functions\n \"\"\"\n \n-import errno, os, os.path\n+import errno, os, os.path, sys\n+from stgit.config import config\n \n __copyright__ = \"\"\"\n Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>\n@@ -152,3 +153,23 @@ def rename(basedir, file1, file2):\n     create_dirs(os.path.dirname(full_file2))\n     os.rename(os.path.join(basedir, file1), full_file2)\n     remove_dirs(basedir, os.path.dirname(file1))\n+\n+def call_editor(filename):\n+    \"\"\"Run the editor on the specified filename.\"\"\"\n+\n+    # the editor\n+    editor = config.get('stgit.editor')\n+    if editor:\n+        pass\n+    elif 'EDITOR' in os.environ:\n+        editor = os.environ['EDITOR']\n+    else:\n+        editor = 'vi'\n+    editor += ' %s' % filename\n+\n+    print 'Invoking the editor: \"%s\"...' % editor,\n+    sys.stdout.flush()\n+    err = os.system(editor)\n+    if err:\n+        raise Exception, 'editor failed, exit code: %d' % err\n+    print 'done'\n"},{"id":"35617","messageId":"b0943d9e0702270617h6ba8669bke55182f84296064b@mail.gmail.com","threadId":"6977","inReplyTo":"20070226194812.28907.80551.stgit@gandelf.nowhere.earth","subject":"Re: [PATCH] Factorize editor handling.","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2007-02-27T14:17:34Z","receivedAt":"2007-02-27T14:17:34Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 26/02/07, Yann Dirson <ydirson@altern.org> wrote:\n> At the same time we trap the editor error for all editor calls, not\n> just when called from \"stg mail\".\n\nI merged this patch. In the initial StGIT versions, someone complained\nthat an editor (ed) returning a non-zero code is not actually an error\nand shouldn't raise an exception. If anyone complains about this in\nthe future (that person is no longer using StGIT :-)), we could add a\nconfig option to not raise the exception (though with some problems\nfor them).\n\n> We may want to define a new exception for this though.\n\nI added an EditorException since it needs to cought in main.py to\navoid a stack dump.\n\n-- \nCatalin\n"}]}