unmerge 575395
tags 575395 + patch
thanks

Hi

I have created a script (qdebdiff) that compares the debian/ folder of
two packages. I unmerged #575395 from #417932 and #575821, because this
script does not fix those bugs.

Thanks for considering,
~Niels

--------------000102080209080202070606
Content-Type: text/x-diff;
 name="0001-Added-qdebdiff-which-compares-the-debian-folder-of-t.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename*0="0001-Added-qdebdiff-which-compares-the-debian-folder-of-t.pa";
 filename*1="tch"

From a4aa4756724639fa4e9b49c1e10747db11450019 Mon Sep 17 00:00:00 2001
From: Niels Thykier <[email protected]>
Date: Tue, 30 Mar 2010 17:16:41 +0200
Subject: [PATCH] Added qdebdiff which compares the debian/ folder of two 
packages.

---
 debian/changelog    |    3 +
 debian/control      |    1 +
 debian/copyright    |    4 +-
 scripts/Makefile    |    2 +-
 scripts/qdebdiff.pl |  328 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 335 insertions(+), 3 deletions(-)
 create mode 100755 scripts/qdebdiff.pl

diff --git a/debian/changelog b/debian/changelog
index 8d3ffd5..8605036 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -47,6 +47,9 @@ devscripts (2.10.62) UNRELEASED; urgency=low
   * debchange: Sanitise list of distributions.  Remove {sarge,etch}-backports
     and sarge-volatile, none of which accept uploads any more.
 
+  [ Niels Thykier ]
+  * Added qdebdiff, which only diffs the debian/ folder of two packages.
+
  -- Patrick Schoenfeld <[email protected]>  Mon, 11 Jan 2010 15:32:59 +0100
 
 devscripts (2.10.61) unstable; urgency=low
diff --git a/debian/control b/debian/control
index aeaadd1..06c9241 100644
--- a/debian/control
+++ b/debian/control
@@ -105,6 +105,7 @@ Description: scripts to make the life of a Debian Package 
maintainer easier
   - namecheck: Check project names are not already taken.
   - nmudiff: mail a diff of the current package against the previous version
     to the BTS to assist in tracking NMUs [patchutils, mutt]
+  - qdebdiff: diffs only the debian/ folder of two packages [patchutils]
   - plotchangelog: view a nice plot of the data in a changelog file
     [libtimedate-perl, gnuplot]
   - pts-subscribe: subscribe to the PTS for a limited period of time
diff --git a/debian/copyright b/debian/copyright
index 822b50b..911235a 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -25,8 +25,8 @@ the GPL, version 2 or later.
 
 - deb-reversion is under the Artistic License version 2.0.
 
-- namecheck and the Perl module DB_File::Lock used by bts are copyright
-  under the same terms as Perl, that is:
+- qdebdiff, namecheck and the Perl module DB_File::Lock used by bts are
+  copyright under the same terms as Perl, that is:
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of either:
diff --git a/scripts/Makefile b/scripts/Makefile
index b1dbea9..375db91 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -16,7 +16,7 @@ COMPLETION = $(patsubst 
%.bash_completion,devscripts.%,$(COMPL_FILES))
 GEN_MAN1S = bts.1 build-rdeps.1 chdist.1 dcontrol.1 debcheckout.1 debcommit.1 \
            deb-reversion.1 desktop2menu.1 dget.1 licensecheck.1 mass-bug.1 \
            mk-build-deps.1 namecheck.1 rmadison.1 svnpath.1 tagpending.1 \
-           transition-check.1 devscripts.1
+           transition-check.1 devscripts.1 qdebdiff.1
 
 BINDIR = /usr/bin
 LIBDIR = /usr/lib/devscripts
diff --git a/scripts/qdebdiff.pl b/scripts/qdebdiff.pl
new file mode 100755
index 0000000..c1e6848
--- /dev/null
+++ b/scripts/qdebdiff.pl
@@ -0,0 +1,328 @@
+#!/usr/bin/perl
+#
+# Copyright: 2010, Niels Thykier <[email protected]>
+# It comes with ABSOLUTELY NO WARRANTY and may distributed
+# and modified under the same terms as Perl itself.
+#
+
+=head1 NAME
+
+qdebdiff - Diffs the debian/ folder of two debian packages.
+
+=head1 SYNOPSIS
+
+B<qdebdiff> I<[options]> I<< <dsc1> >> I<< <dsc2> >>
+
+B<qdebdiff> B<--help>
+
+=head1 DESCRIPTION
+
+B<qdebdiff> compares the debian/ folder of two debian packages
+and optionally pipes it to colordiff or/and a pager.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-h> B<--help>
+
+Prints usage info and exits.
+
+=item B<--version>
+
+Prints version and license info and exits.
+
+=item B<--color>
+
+Pipe the resulting diff through colordiff.
+
+With this option, qdebdiff will pass -R to the pager if it
+thinks it is less.
+
+Note: This is silently ignored if colordiff is not in PATH.
+
+=item B<--pager>
+
+Pipe the resulting diff to a pager. If environment variable
+PAGER is set, this will be used; otherwise qdebdiff will look
+for a pager.
+
+=item B<--less>
+
+Assume the pager is less; this option implies B<--pager>. If
+PAGER is set, it is assumed to be less. If PAGER is not set
+qdebdiff will fail with an error, if it cannot find less.
+
+By default, qdebdiff will guess whether the pager is less
+based on the name of the command.
+
+=item B<-d> B<--debug>
+
+Enable debug printing to stderr.
+
+=back
+
+=cut
+
+use strict;
+use warnings;
+use Dpkg::Control;
+use Cwd 'abs_path';
+use Getopt::Long;
+
+my $progname = $0;
+my $debug = 0;
+my $diff = 'diff';
+my $idiff = 'interdiff';
+my $pager = 0;
+my $isless = 0;
+my $color = 0;
+$progname =~ s...@[^/]*/@@g;
+
+GetOptions( 'd|debug' => sub { $debug = 1; }, 
+           'h|help' => sub { usage(); exit(0); },
+           'version' => sub { version(); exit(0); },
+           'pager' => \$pager,
+           'less' => sub { $pager = 1; $isless = 1; },
+           'color' => \$color
+    ) or choke("Usage: $progname [options] <dsc1> <dsc2>\nUse: $progname 
--help for more details.");
+
+usage() && exit(1) if(scalar(@ARGV) != 2);
+
+if( ! -t STDOUT && $pager){
+    print STDERR "Ignoring request for pager - stdout is not a tty!\n";
+    $pager = 0;
+}
+
+my $api = undef;
+eval { $api = $Dpkg::Control::VERSION; };
+my $old = shift(@ARGV);
+my $new = shift(@ARGV);
+my ($osrc, $oversion, $oformat, $onative, $odscdir, $odebchanges) = 
parseDSC($old);
+my ($nsrc, $nversion, $nformat, $nnative, $ndscdir, $ndebchanges) = 
parseDSC($new);
+my $tmpdir = undef;
+
+choke("Cannot find $odscdir/$odebchanges") unless( -e "$odscdir/$odebchanges");
+choke("Cannot find $ndscdir/$ndebchanges") unless( -e "$ndscdir/$ndebchanges");
+
+debug("$oformat vs $nformat; is native $onative vs $nnative");
+
+checkRequirements();
+
+chomp($tmpdir = `mktemp -d`);
+
+if($oformat =~ m/^3.0/ && $nformat =~ m/^3.0/){
+    # Both are 3.0
+    # ensure the name + version are not equal
+    my ($ounpack, $nunpack);
+    $oversion = "$oversion~" if($nversion eq $oversion && $osrc eq $nsrc);
+    $ounpack = unpackTar("$odscdir/$odebchanges", $tmpdir, $onative, $osrc, 
$oversion);
+    $nunpack = unpackTar("$ndscdir/$ndebchanges", $tmpdir, $nnative, $nsrc, 
$nversion);
+    output("$diff -Nur \"$ounpack\" \"$nunpack\"");
+} else {
+    my $odgz = "$odscdir/$odebchanges";
+    my $ndgz = "$ndscdir/$ndebchanges";
+    my $oup = $oversion;
+    my $nup = $nversion;
+    $oup =~ s/-[^-]*$//;
+    $nup =~ s/-[^-]*$//;
+    print "$0: Since the upstream versions differ, this will probably not 
produce anything useful.\n" if($oup ne $nup);
+    print "$0: Since the source names differ, this will probably not produce 
anything useful.\n" if($osrc ne $nsrc);
+    $odgz = diffgzTar($odgz, $tmpdir, $osrc, $oversion, $onative) if($oformat 
=~ m/^3.0/ or $onative);
+    $ndgz = diffgzTar($ndgz, $tmpdir, $nsrc, $nversion, $nnative) if($nformat 
=~ m/^3.0/ or $nnative);
+    output("$idiff -z \"$odgz\" \"$ndgz\"");
+}
+
+system("rm -fr \"$tmpdir\"") == 0 or warn("Could not clean up \"$tmpdir\"");
+exit;
+
+### END OF SCRIPT ###
+
+sub output{
+    my $command = shift;
+    my $pcmd;
+    # We only use color if colordiff is available
+    $color = 0 unless($color && hasCommand('colordiff'));
+    if($color){
+       $command .= " | colordiff ";
+    }
+    if($pager){
+       my $pagercmd = $ENV{PAGER};
+       if(!defined($pagercmd)){
+           foreach my $cmd ('less', 'more'){
+               if(hasCommand($cmd)){
+                   $pagercmd = $cmd;
+                   last;
+               }
+           }
+           choke("less does not appear in path.") if($isless && $pagercmd ne 
'less');
+           $isless = $isless || $pagercmd =~ m/less/;
+       }
+       $pagercmd .= " -R" if($pagercmd !~ m/-R/ && $isless && $color);
+       $command .= " | $pagercmd";
+    }
+    debug($command);
+    system($command) == 0 or exit(1);
+}
+
+
+sub doParseDSC {
+    my $filename = shift;
+    my $dsc = Dpkg::Control->new("type" => CTRL_PKG_SRC);
+    if(defined($api)){
+       # dpkg >= 1.15.6 - using libdpkg-perl
+       open(DSC, "<", $filename) or choke("$filename: $!");
+       $dsc->parse(*DSC{IO}, $filename);
+       close(DSC);
+    } else {
+       # dpkg < 1.15.6 - using dpkg-dev
+       $dsc->parse($filename);
+    }
+    return $dsc;
+}
+
+sub parseDSC {
+    my $filename = shift;
+    my ($src, $version, $format, $debchanges);
+    my $dsc;
+    my $dscdir = $filename;
+    my $orig = undef;
+    my $native = 0;
+    local *DSC;
+    $dscdir = "." unless($dscdir =~ m@/@o);
+    $dscdir =~ s@/[^/]*$@@o;
+    choke("Could not find: $filename") unless( -e $filename );
+    $dsc = doParseDSC($filename);
+    ($src, $version, $format) = ($dsc->{'Source'}, $dsc->{'Version'}, 
$dsc->{'Format'});
+    {
+       my @filesField = split(/\s+/, $dsc->{'Files'});
+       my $len = scalar(@filesField);
+       my $i = 3;
+       for( ; $i < $len ; $i+=3 ){
+           if($format eq '3.0 (quilt)'){
+               $debchanges = $filesField[$i] if($filesField[$i] =~ 
m/^${src}_${version}\.debian\.tar\./);
+           } elsif($format eq '3.0 (native)'){
+               $debchanges = $filesField[$i] if($filesField[$i] =~ 
m/^${src}_${version}\.tar\./);
+           } else {
+               $debchanges = $filesField[$i] if($filesField[$i] =~ 
m/^${src}_${version}\.diff\.gz/);
+               $orig = $filesField[$i] if($filesField[$i] =~ 
m/^${src}_${version}\.tar/);
+           }
+       }
+    }
+    if(!defined($debchanges) and $format eq '1.0'){
+       $debchanges = $orig;
+       $native = 1;
+    } else {
+       $native = $format eq '3.0 (native)';
+    }
+    choke("Could not find debian changes.") unless(defined($debchanges));
+    return ($src, $version, $format, $native, $dscdir, $debchanges);
+}
+
+sub unpackTar {
+    my $tar = abs_path(shift);
+    my $tmp = shift;
+    my $native = shift;
+    my $src = shift;
+    my $version = shift;
+    my $comp = " --auto-compress ";
+    my $args = $native ? "$src-$version/debian/" : "";
+    $tmp = "$tmp/$src-$version" unless($native);
+    debug("mkdir -p \"$tmp\" && cd \"$tmp\" && tar -x $comp -f \"$tar\" 
$args");
+    system("mkdir -p \"$tmp\" && cd \"$tmp\" && tar -x $comp -f \"$tar\" 
$args") == 0 or choke("Failed to untar $tar.");
+    $tmp = "$tmp/$src-$version" if($native);
+    return $tmp;
+}
+
+sub diffgzTar {
+    my $tar = shift;
+    my $tmp = shift;
+    my $src = shift;
+    my $version = shift;
+    my $native = shift;
+    my $uver = $version;
+    my $unpacked;
+    $uver =~ s/-[^-]*$//o;
+    $unpacked = unpackTar($tar, $tmp, $native, $src, $uver);
+    $unpacked =~ s...@^$tmp/@@;
+    debug("mkdir -p \"$tmp/$src-$uver.orig\"".
+         " && cd \"$tmp\" && $diff -Nur $src-$uver.orig $unpacked | gzip -9c > 
$src-$version.diff.gz");
+    system("mkdir -p \"$tmp/$src-$uver.orig\"".
+          " && cd \"$tmp\" && $diff -Nur $src-$uver.orig $unpacked | gzip -9c 
> $src-$version.diff.gz") == 0 or
+          choke("Failed to create fake diff.gz");
+    return "$tmp/$src-$version.diff.gz";
+}
+
+sub debug{
+    my $msg = shift;
+    print STDERR "D: $msg\n" if($debug);
+}
+
+sub choke{
+    my $msg = shift;
+    print STDERR "$msg\n";
+    system("rm -fr \"$tmpdir\"") if(defined($tmpdir));
+    exit(1);
+}
+
+sub hasCommand{
+    my $cmd = shift;
+    return system("which $cmd 2>/dev/null >/dev/null") == 0;
+}
+
+sub checkRequirements{
+    my @needed = ("diff", "tar");
+    push(@needed, "interdiff") if($oformat eq '1.0' or $nformat eq '1.0');
+    foreach my $cmd (@needed){
+       debug("Checking for $cmd");
+       hasCommand($cmd) or choke("Cannot find $cmd, which is needed for this 
operation.");
+    }
+    # We are good.
+    1;
+}
+
+sub version {
+    print <<EOF
+$progname: ###VERSION###
+Copyright (C): 2010, Niels Thykier <[email protected]>.
+
+This script comes with ABSOLUTELY NO WARRANTY and may be modified
+and distributed under the same terms as Perl. 
+EOF
+;
+}
+
+sub usage{
+    my $slash = '/';
+    print <<EOF
+$progname: <dsc1> <dsc2>
+
+Compares the debian/ folder of two debian packages.
+
+ -d, --debug      Prints debug information to stderr.
+ -h, --help       Prints this usage and exits.
+ --version        Prints version and license info and exits.
+ --pager          Pipe the output to a pager.
+ --less           Assume the pager is less (implies --pager).
+ --color          Pipe the output through colordiff.
+                  NB: May not work, if your pager is not less.
+
+If at least one of the source packages are 1.0, then the final difference
+will be generated using interdiff. diff will still be used to convert any
+3.0 sources into a diff.gz.
+
+If name of the pager suggests it is less (or --less is passed), $progname
+will pass the correct options to make it display the colors.
+
+Note: --color is silently ignored if colordiff is not available.
+
+EOF
+;
+
+}
+
+=head1 AUTHOR
+
+Niels Thykier <[email protected]>
+
+=cut
-- 
1.7.0


--------------000102080209080202070606--

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to