Parcourir la 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 il y a 12 ans
Parent
commit
f2ea976c0a
2 fichiers modifiés avec 13 ajouts et 2 suppressions
  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
     versions expect a trailing space from dpkg-parsechangelog output.
     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 ]
   * 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-2014 Guillem Jover <guillem@debian.org>
 #
 # 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
@@ -26,6 +27,7 @@ use Dpkg;
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
 use Dpkg::File;
+use Dpkg::Path qw(find_command);
 use Dpkg::Compression;
 use Dpkg::Source::Archive;
 use Dpkg::Source::Patch;
@@ -35,6 +37,7 @@ use Dpkg::Vendor qw(run_vendor_hook);
 use Dpkg::Control;
 use Dpkg::Changelog::Parse;
 
+use List::Util qw(first);
 use POSIX qw(:errno_h);
 use Cwd;
 use File::Basename;
@@ -666,8 +669,13 @@ sub do_commit {
     }
     mkpath(File::Spec->catdir($dir, 'debian', 'patches'));
     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);
     pop_exit_handler();
     info(_g('local changes have been recorded in a new patch: %s'), $patch);