# # # patch "NEWS" # from [bed877b4e54bd7dc59e9eb3b36a6994a00c80af7] # to [8583baa78f5a64175d6d8f7914fddb3ad407296e] # # patch "std_hooks.lua" # from [47f92f3269c99464106e72b9f3839027c3eacce1] # to [64007e804a2f1f9e4cf7a2c1c3faeb9771d83c05] # ============================================================ --- NEWS bed877b4e54bd7dc59e9eb3b36a6994a00c80af7 +++ NEWS 8583baa78f5a64175d6d8f7914fddb3ad407296e @@ -62,6 +62,10 @@ - Additional '--full' option for 'mtn db info' to display some statistic analysis of the date certs in the database. + - Command line options in the EDITOR and/or VISUAL environment + variables are honored; for instance, EDITOR="emacs -nw" + works now. (Debian bug #320565.) + Internal - Using 64 bit integer values to represent dates internally. This ============================================================ --- std_hooks.lua 47f92f3269c99464106e72b9f3839027c3eacce1 +++ std_hooks.lua 64007e804a2f1f9e4cf7a2c1c3faeb9771d83c05 @@ -277,21 +277,21 @@ function edit_comment(basetext, user_log function edit_comment(basetext, user_log_message) local exe = nil - if (program_exists_in_path("vi")) then exe = "vi" end - if (string.sub(get_ostype(), 1, 6) ~= "CYGWIN" and program_exists_in_path("notepad.exe")) then exe = "notepad.exe" end - local debian_editor = io.open("/usr/bin/editor") - if (debian_editor ~= nil) then - debian_editor:close() - exe = "/usr/bin/editor" - end + + -- top priority is VISUAL, then EDITOR, then a series of hardcoded + -- defaults, if available. + local visual = os.getenv("VISUAL") - if (visual ~= nil) then exe = visual end local editor = os.getenv("EDITOR") - if (editor ~= nil) then exe = editor end - - if (exe == nil) then - io.write("Could not find editor to enter commit message\n" - .. "Try setting the environment variable EDITOR\n") + if (visual ~= nil) then exe = visual + elseif (editor ~= nil) then exe = editor + elseif (program_exists_in_path("editor")) then exe = "editor" + elseif (program_exists_in_path("vi")) then exe = "vi" + elseif (string.sub(get_ostype(), 1, 6) ~= "CYGWIN" and + program_exists_in_path("notepad.exe")) then exe = "notepad" + else + io.write(gettext("Could not find editor to enter commit message\n" + .. "Try setting the environment variable EDITOR\n")) return nil end @@ -305,11 +305,44 @@ function edit_comment(basetext, user_log tmp:write(basetext) io.close(tmp) - if (execute(exe, tname) ~= 0) then - io.write(string.format(gettext("Error running editor '%s' to enter log message\n"), - exe)) - os.remove(tname) - return nil + -- By historical convention, VISUAL and EDITOR can contain arguments + -- (and, in fact, arbitrarily complicated shell constructs). Since Lua + -- has no word-splitting functionality, we invoke the shell to deal with + -- anything more complicated than a single word with no metacharacters. + -- This, unfortunately, means we have to quote the file argument. + + if (not string.find(editor, "[^%w_.+-]")) then + -- safe to call spawn directly + if (execute(exe, tname) ~= 0) then + io.write(string.format(gettext("Error running editor '%s' ".. + "to enter log message\n"), + exe)) + os.remove(tname) + return nil + end + else + -- must use shell + local shell = os.getenv("SHELL") + if (shell == nil) then shell = "sh" end + if (not program_exists_in_path(shell)) then + io.write(string.format(gettext("Editor command '%s' needs a shell, ".. + "but '%s' is not to be found"), + exe, shell)) + os.remove(tname) + return nil + end + + -- Single-quoted strings in both Bourne shell and csh can contain + -- anything but a single quote. + local safe_tname = " '" .. string.gsub(tname, "'", "'\\''") .. "'" + + if (execute(shell, "-c", editor .. safe_tname) ~= 0) then + io.write(string.format(gettext("Error running editor '%s' ".. + "to enter log message\n"), + exe)) + os.remove(tname) + return nil + end end tmp = io.open(tname, "r")