throw away deltas bigger than 80% of the reference
authorLudwig Nussel <ludwig.nussel@suse.de>
Fri, 29 Oct 2010 09:19:02 +0000 (11:19 +0200)
committerLudwig Nussel <ludwig.nussel@suse.de>
Fri, 29 Oct 2010 09:19:02 +0000 (11:19 +0200)
mkdrpms

diff --git a/mkdrpms b/mkdrpms
index 1ea2972..373f709 100755 (executable)
--- a/mkdrpms
+++ b/mkdrpms
@@ -7,6 +7,7 @@ BEGIN {
 use Build;
 use strict;
 
+my $limit = 80; # throw away deltas bigger than this percentage of the reference
 my %oldpkgs;
 
 sub query
@@ -30,6 +31,15 @@ sub query
     return { name => $res{'NAME'}->[0], file => $file, version => $res{'VERSION'}->[0], release => $res{'RELEASE'}->[0], arch => $arch};
 }
 
+while (@ARGV) {
+  if ($ARGV[0] eq '--limit') {
+    shift @ARGV || die "--limit needs an argument\n";
+    $limit = shift @ARGV;
+    next;
+  }
+  last;
+}
+
 my $prevbuild = shift @ARGV || die "USAGE: $0 <oldpkgdir> <directories...>";
 my @prevbuild = ($prevbuild);
 my $i = 1;
@@ -74,12 +84,12 @@ for my $dir (@ARGV) {
            } else {
                my $ns = (stat($dn))[7] || 1;
                my $os = (stat($file))[7] || 1;
-               my $saved = int($ns / $os * 100);
-               if ($ns >= $os) {
-                   print "too big ($saved%), removed\n";
-                   unlink $file;
+               my $factor = int($ns / $os * 100);
+               if ($factor > $limit) {
+                   print "too big ($factor%), removed\n";
+                   unlink $ns;
                } else {
-                   print "ok ($saved%)\n";
+                   print "ok ($factor%)\n";
                }
            }
        }