Package: devscripts
Version: 2.10.64
Severity: minor

Please find attached a proposed patch for a new script, dep3changelog, which
takes a DEP3-style patch header and synthesizes a changelog entry.  This
saves a lot of tedious work writing both a patch header and a changelog
entry with identical information.  I think it would be nice to have this
included in devscripts for others' use.

--- ~/.devscripts ---
DEBCHANGE_RELEASE_HEURISTIC=changelog
DEBCHANGE_FORCE_SAVE_ON_RELEASE=no

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages devscripts depends on:
ii  dpkg-dev                      1.15.7.2   Debian package development tools
ii  libc6                         2.11.2-2   Embedded GNU C Library: Shared lib
ii  perl                          5.10.1-14  Larry Wall's Practical Extraction 

Versions of packages devscripts recommends:
ii  at                3.1.12-1               Delayed job execution and batch pr
ii  bsd-mailx [mailx] 8.1.2-0.20100314cvs-1  simple mail user agent
ii  bzr               2.1.2-1                easy to use distributed version co
ii  curl              7.21.0-1               Get a file from an HTTP, HTTPS or 
ii  cvs               1:1.12.13-12           Concurrent Versions System
ii  dctrl-tools       2.14                   Command-line tools to process Debi
ii  debian-keyring [d 2010.06.08             GnuPG (and obsolete PGP) keys of D
ii  dput              0.9.6.1                Debian package upload tool
ii  equivs            2.0.8                  Circumvent Debian package dependen
ii  fakeroot          1.14.4-1               Gives a fake root environment
ii  galeon [www-brows 2.0.7-2.1+b1           GNOME web browser for advanced use
ii  git [git-core]    1:1.7.1-1              fast, scalable, distributed revisi
ii  git-core          1:1.7.1-1              fast, scalable, distributed revisi
ii  gnupg             1.4.10-4               GNU privacy guard - a free PGP rep
ii  iceape-browser [w 2.0.5-1                Iceape Navigator (Internet browser
ii  iceweasel [www-br 3.5.10-1               Web browser based on Firefox
ii  libauthen-sasl-pe 2.1500-1               Authen::SASL - SASL Authentication
ii  libcrypt-ssleay-p 0.57-2                 Support for https protocol in LWP
ii  libjson-perl      2.21-1                 Perl module to parse and convert t
ii  libparse-debcontr 2.005-2                Easy OO parsing of Debian control-
ii  libsoap-lite-perl 0.712-1                Perl implementation of a SOAP clie
ii  libterm-size-perl 0.2-4+b1               Perl extension for retrieving term
ii  libtimedate-perl  1.2000-1               collection of modules to manipulat
ii  liburi-perl       1.54-1                 module to manipulate and access UR
ii  libwww-perl       5.836-1                Perl HTTP/WWW client/server librar
ii  libyaml-syck-perl 1.09-1                 Perl module providing a fast, ligh
ii  lintian           2.4.3                  Debian package checker
ii  lsb-release       3.2-23.1               Linux Standard Base version report
ii  lynx-cur [www-bro 2.8.8dev.4-2           Text-mode WWW Browser with NLS sup
ii  lzma              4.43-14                Compression method of 7z format in
ii  mailx             1:20081101-2           Transitional package for mailx ren
ii  man-db            2.5.7-3                on-line manual pager
ii  mercurial         1.6-2                  scalable distributed version contr
ii  openssh-client [s 1:5.5p1-4              secure shell (SSH) client, for sec
ii  patch             2.6-2                  Apply a diff file to an original
ii  patchutils        0.3.1-2                Utilities to work with patches
ii  sensible-utils    0.0.4                  Utilities for sensible alternative
ii  strace            4.5.20-2               A system call tracer
ii  subversion        1.6.12dfsg-1           Advanced version control system
ii  tla               1.3.5+dfsg-15          GNU Arch revision control system
ii  unzip             6.0-4                  De-archiver for .zip files
ii  w3m [www-browser] 0.5.2-6                WWW browsable pager with excellent
ii  wdiff             0.6.3-1                Compares two files word by word
ii  wget              1.12-2                 retrieves files from the web
ii  xz-utils          4.999.9beta+20100527-1 XZ-format compression utilities

Versions of packages devscripts suggests:
ii  build-essential               11.5       Informational list of build-essent
pn  cvs-buildpackage              <none>     (no description available)
pn  devscripts-el                 <none>     (no description available)
ii  gnuplot                       4.4.0-1    A command-line driven interactive 
ii  libfile-desktopentry-perl     0.04-2     Perl module to handle freedesktop 
pn  libnet-smtp-ssl-perl          <none>     (no description available)
ii  mutt                          1.5.20-9   text-based mailreader supporting M
ii  svn-buildpackage              0.8.1      helper programs to maintain Debian
ii  w3m                           0.5.2-6    WWW browsable pager with excellent

-- no debconf information
>From 1fa018d9b4ae3ea3fd014b473953ab27dd0d972d Mon Sep 17 00:00:00 2001
From: Steve Langasek <steve.langa...@canonical.com>
Date: Fri, 3 Sep 2010 00:05:52 -0700
Subject: [PATCH] new script dep3changelog, which parses a DEP3 patch header and 
feeds a suitable changelog entry to dch.

---
 debian/changelog         |    4 +
 debian/control           |    1 +
 scripts/dep3changelog.pl |  186 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 191 insertions(+), 0 deletions(-)
 create mode 100755 scripts/dep3changelog.pl

diff --git a/debian/changelog b/debian/changelog
index 2b97d83..41ac0b7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,10 @@ devscripts (2.10.69) UNRELEASED; urgency=low
     what should be written inside of source files.
     (Closes: #502512) 
 
+  [ Steve Langasek ]
+  * new script dep3changelog, which parses a DEP3 patch header and feeds a
+    suitable changelog entry to dch.
+
  -- Patrick Schoenfeld <schoenf...@debian.org>  Thu, 07 Oct 2010 13:48:06 +0200
 
 devscripts (2.10.68) unstable; urgency=low
diff --git a/debian/control b/debian/control
index e2466e8..3fe99b0 100644
--- a/debian/control
+++ b/debian/control
@@ -80,6 +80,7 @@ Description: scripts to make the life of a Debian Package 
maintainer easier
     lintian, gnupg]
   - deb-reversion: increases a binary package version number and repacks the
     archive
+  - dep3changelog: generate a changelog entry from a DEP3-style patch header
   - desktop2menu: produce a skeleton menu file from a freedesktop.org
     desktop file [libfile-desktopentry-perl]
   - dget: downloads Debian source and binary packages [wget | curl]
diff --git a/scripts/dep3changelog.pl b/scripts/dep3changelog.pl
new file mode 100755
index 0000000..a88eef7
--- /dev/null
+++ b/scripts/dep3changelog.pl
@@ -0,0 +1,186 @@
+#! /usr/bin/perl -w
+
+# dep3changelog: extract a DEP3 patch header from the named file and
+# automatically update debian/changelog with a suitable entry
+#
+# Copyright 2010 Steve Langasek <vor...@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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+# USA
+
+use 5.008;  # We're using PerlIO layers
+use strict;
+use open ':utf8';  # patch headers are required to be UTF-8
+
+# for checking whether user names are valid and making format() behave
+use Encode qw/decode_utf8 encode_utf8/;
+use Getopt::Long;
+use File::Basename;
+
+# Predeclare functions
+my $warnings = 0;
+
+# And global variables
+my $progname = basename($0);
+my %env;
+
+sub usage () {
+    print <<"EOF";
+Usage: $progname patch [patch...] [options] [-- [dch options]]
+Options:
+   --help, -h
+         Display this help message and exit
+  --version
+         Display version information
+  Additional options specified after -- are passed to dch.
+EOF
+}
+
+sub version () {
+    print <<"EOF";
+This is $progname, from the Debian devscripts package, version ###VERSION###
+This code is copyright 2010 by Steve Langasek, all rights reserved.
+This program comes with ABSOLUTELY NO WARRANTY.
+You are free to redistribute this code under the terms of the
+GNU General Public License, version 2 or later.
+EOF
+}
+
+my ($opt_help, $opt_version);
+GetOptions("help|h" => \$opt_help,
+       "version" => \$opt_version,
+)
+or die "Usage: $progname patch [... patch] [-- [dch options]]\nRun $progname 
--help for more details\n";
+
+if ($opt_help) { usage; exit 0; }
+if ($opt_version) { version; exit 0; }
+
+my @patches;
+
+while (@ARGV && $ARGV[0] !~ /^-/) {
+       push(@patches,shift(@ARGV));
+}
+
+# Check, sanitise and decode these environment variables
+check_env_utf8('DEBFULLNAME');
+check_env_utf8('NAME');
+check_env_utf8('DEBEMAIL');
+check_env_utf8('EMAIL');
+
+if (exists $env{'DEBEMAIL'} and $env{'DEBEMAIL'} =~ /^(.*)\s+<(.*)>$/) {
+       $env{'DEBFULLNAME'} = $1 unless exists $env{'DEBFULLNAME'};
+       $env{'DEBEMAIL'} = $2;
+}
+if (! exists $env{'DEBEMAIL'} or ! exists $env{'DEBFULLNAME'}) {
+       if (exists $env{'EMAIL'} and $env{'EMAIL'} =~ /^(.*)\s+<(.*)>$/) {
+               $env{'DEBFULLNAME'} = $1 unless exists $env{'DEBFULLNAME'};
+               $env{'EMAIL'} = $2;
+       }
+}
+
+my $fullname = '';
+my $email = '';
+
+if (exists $env{'DEBFULLNAME'}) {
+       $fullname = $env{'DEBFULLNAME'};
+} elsif (exists $env{'NAME'}) {
+       $fullname = $env{'NAME'};
+} else {
+       my @pw = getpwuid $<;
+       if ($pw[6]) {
+               if (my $pw = decode_utf8($pw[6])) {
+                       $pw =~ s/,.*//;
+                       $fullname = $pw;
+               } else {
+                       warn "$progname warning: passwd full name field for uid 
$<\nis not UTF-8 encoded; ignoring\n";
+                       $warnings++;
+               }
+       }
+}
+
+if (exists $env{'DEBEMAIL'}) {
+       $email = $env{'DEBEMAIL'};
+} elsif (exists $env{'EMAIL'}) {
+       $email = $env{'EMAIL'};
+}
+
+for my $patch (@patches) {
+       my $shebang = 0;
+       my $dpatch = 0;
+       # TODO: more than one debian or launchpad bug in a patch?
+       my ($description,$author,$debbug,$lpbug,$origin);
+
+       next unless (open PATCH, $patch);
+       while (<PATCH>) {
+               # first line only
+               if (!$shebang) {
+                       $shebang = 1;
+                       if (/^#!/) {
+                               $dpatch = $shebang = 1;
+                               next;
+                       }
+               }
+               last if (/^---/ || /^\s*$/);
+               chomp;
+               # only if there was a shebang do we strip comment chars
+               s/^# // if ($dpatch);
+               # fixme: this should only apply to the description field.
+               next if (/^ /);
+
+               if (/^(Description|Subject):\s+(.*)\s*/) {
+                       $description = $2;
+               } elsif (/^(Author|From):\s+(.*)\s*/) {
+                       $author = $2;
+               } elsif (/^Origin:\s+(.*)\s*/) {
+                       $origin = $1;
+               } elsif 
(/^bug-debian:\s+http:\/\/bugs\.debian\.org\/([0-9]+)\s*/i) {
+                       $debbug = $1;
+               } elsif 
(/^bug-ubuntu:\s+https:\/\/.*launchpad\.net\/.*\/([0-9]+)\s*/i) {
+                       $lpbug = $1;
+               }
+       }
+       close PATCH;
+       if (!$description || (!$origin && !$author)) {
+               print STDERR "$patch: Invalid DEP3 header\n";
+               next;
+       }
+       my $changelog = "$patch: $description";
+       $changelog .= '.' unless ($changelog =~ /\.$/);
+       if ($author && $author ne $fullname && $author ne "$fullname <$email>")
+       {
+               $changelog .= "  Thanks to $author.";
+       }
+       if ($debbug || $lpbug) {
+               $changelog .= '  Closes';
+               $changelog .= ": #$debbug" if ($debbug);
+               $changelog .= "," if ($debbug && $lpbug);
+               $changelog .= " LP: #$lpbug" if ($lpbug);
+               $changelog .= '.';
+       }
+       system('dch',$changelog,@ARGV);
+}
+
+# Is the environment variable valid or not?
+sub check_env_utf8 {
+    my $envvar = $_[0];
+
+    if (exists $ENV{$envvar} and $ENV{$envvar} ne '') {
+       if (! decode_utf8($ENV{$envvar})) {
+           warn "$progname warning: environment variable $envvar not UTF-8 
encoded; ignoring\n";
+       } else {
+           $env{$envvar} = decode_utf8($ENV{$envvar});
+       }
+    }
+}
-- 
1.7.1

Reply via email to