Browse Source

Dpkg::Source::Package::V2: Do not assume sensible-editor is present

This command is very Debian specific, fallback to try to use
VISUAL, EDITOR or vi if the previous are either unset or not found.
Guillem Jover 12 years ago
parent
commit
f2ea976c0a
2 changed files with 13 additions and 2 deletions
  1. 3 0
      debian/changelog
  2. 10 2
      scripts/Dpkg/Source/Package/V2.pm

+ 3 - 0
debian/changelog

@@ -52,6 +52,9 @@ dpkg (1.17.10) UNRELEASED; urgency=low
     first line. Bump dpkg-dev Breaks on devscripts to 2.14.4, as previous
     first line. Bump dpkg-dev Breaks on devscripts to 2.14.4, as previous
     versions expect a trailing space from dpkg-parsechangelog output.
     versions expect a trailing space from dpkg-parsechangelog output.
     Based on a patch by Johannes Schauer <j.schauer@email.de>. Closes: #749044
     Based on a patch by Johannes Schauer <j.schauer@email.de>. Closes: #749044
+  * Do not assume that sensible-editor is present on «dpkg-source --commit»,
+    as that command is very Debian specific. Fallback to try VISUAL, EDITOR,
+    or vi, if the previous commands are either unset or not found.
 
 
   [ Updated programs translations ]
   [ Updated programs translations ]
   * Catalan (Guillem Jover).
   * Catalan (Guillem Jover).

+ 10 - 2
scripts/Dpkg/Source/Package/V2.pm

@@ -1,4 +1,5 @@
 # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
 # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
+# Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
 #
 #
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
@@ -26,6 +27,7 @@ use Dpkg;
 use Dpkg::Gettext;
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
 use Dpkg::ErrorHandling;
 use Dpkg::File;
 use Dpkg::File;
+use Dpkg::Path qw(find_command);
 use Dpkg::Compression;
 use Dpkg::Compression;
 use Dpkg::Source::Archive;
 use Dpkg::Source::Archive;
 use Dpkg::Source::Patch;
 use Dpkg::Source::Patch;
@@ -35,6 +37,7 @@ use Dpkg::Vendor qw(run_vendor_hook);
 use Dpkg::Control;
 use Dpkg::Control;
 use Dpkg::Changelog::Parse;
 use Dpkg::Changelog::Parse;
 
 
+use List::Util qw(first);
 use POSIX qw(:errno_h);
 use POSIX qw(:errno_h);
 use Cwd;
 use Cwd;
 use File::Basename;
 use File::Basename;
@@ -666,8 +669,13 @@ sub do_commit {
     }
     }
     mkpath(File::Spec->catdir($dir, 'debian', 'patches'));
     mkpath(File::Spec->catdir($dir, 'debian', 'patches'));
     my $patch = $self->register_patch($dir, $tmpdiff, $patch_name);
     my $patch = $self->register_patch($dir, $tmpdiff, $patch_name);
-    system('sensible-editor', $patch);
-    subprocerr('sensible-editor') if $?;
+    my @editors = ('sensible-editor', $ENV{VISUAL}, $ENV{EDITOR}, 'vi');
+    my $editor = first { defined $_ and find_command($_) } @editors;
+    if (not $editor) {
+        error(_g('cannot find an editor'));
+    }
+    system($editor, $patch);
+    subprocerr($editor) if $?;
     unlink($tmpdiff) or syserr(_g('cannot remove %s'), $tmpdiff);
     unlink($tmpdiff) or syserr(_g('cannot remove %s'), $tmpdiff);
     pop_exit_handler();
     pop_exit_handler();
     info(_g('local changes have been recorded in a new patch: %s'), $patch);
     info(_g('local changes have been recorded in a new patch: %s'), $patch);