[Pkg-libvirt-commits] [libguestfs] 231/266: fish: edit: centralize the EDITOR handling

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 356fe582b8d64163fb84f662b37f534633b9c2a7
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Fri Aug 29 16:38:04 2014 +0200

    fish: edit: centralize the EDITOR handling
    
    Allow null as value for the editor parameter of edit_file_editor, which
    will then get it from the EDITOR envvar (falling back on vi).
    
    This is basically code motion from the two edit_file_editor users to it.
---
 edit/edit.c      | 12 +++---------
 fish/edit.c      |  7 ++-----
 fish/file-edit.c |  6 ++++++
 fish/file-edit.h |  3 +++
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/edit/edit.c b/edit/edit.c
index f1c3b91..821f280 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -333,15 +333,9 @@ edit (const char *filename, const char *root)
 
   if (perl_expr != NULL) {
     r = edit_file_perl (g, filename, perl_expr, backup_extension, verbose);
-  } else {
-    const char *editor;
-
-    editor = getenv ("EDITOR");
-    if (editor == NULL)
-      editor = "vi";
-
-    r = edit_file_editor (g, filename, editor, backup_extension, verbose);
-  }
+  } else
+    r = edit_file_editor (g, filename, NULL /* use $EDITOR */,
+                          backup_extension, verbose);
 
   switch (r) {
   case -1:
diff --git a/fish/edit.c b/fish/edit.c
index 0f41a88..013306e 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -47,11 +47,8 @@ run_edit (const char *cmd, size_t argc, char *argv[])
     editor = "vi";
   else if (STRCASEEQ (cmd, "emacs"))
     editor = "emacs -nw";
-  else {
-    editor = getenv ("EDITOR");
-    if (editor == NULL)
-      editor = "vi"; /* could be cruel here and choose ed(1) */
-  }
+  else
+    editor = NULL; /* use $EDITOR */
 
   /* Handle 'win:...' prefix. */
   remotefilename = win_prefix (argv[0]);
diff --git a/fish/file-edit.c b/fish/file-edit.c
index 74cb89b..e6d25f5 100644
--- a/fish/file-edit.c
+++ b/fish/file-edit.c
@@ -52,6 +52,12 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
   int r;
   struct utimbuf times;
 
+  if (editor == NULL) {
+    editor = getenv ("EDITOR");
+    if (editor == NULL)
+      editor = "vi";
+  }
+
   /* Download the file and write it to a temporary. */
   if (do_download (g, filename, &tmpfilename) == -1)
     return -1;
diff --git a/fish/file-edit.h b/fish/file-edit.h
index 3f8b95e..1635254 100644
--- a/fish/file-edit.h
+++ b/fish/file-edit.h
@@ -25,6 +25,9 @@
  * Edit 'filename' using the specified 'editor' application.
  * If 'backup_extension' is not null, then a copy of 'filename' is saved
  * with 'backup_extension' appended to its file name.
+ * If 'editor' is null, then the EDITOR environment variable
+ * will be queried for the editor application, leaving "vi" as fallback
+ * if not set.
  *
  * Returns -1 for failure, 0 on success, 1 if the editor did not change
  * the file (e.g. the user closed the editor without saving).

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list