Author: sparky                       Date: Thu Nov 23 03:26:49 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- s/chunk/hunk/, some BUGS

---- Files affected:
SOURCES:
   patch_minimizer (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/patch_minimizer
diff -u SOURCES/patch_minimizer:1.1 SOURCES/patch_minimizer:1.2
--- SOURCES/patch_minimizer:1.1 Thu Nov 23 04:22:26 2006
+++ SOURCES/patch_minimizer     Thu Nov 23 04:26:44 2006
@@ -7,6 +7,11 @@
 # (c) 2006 PLD Linux Distribution
 # Main author: [EMAIL PROTECTED]
 #
+# BUGS:
+#  - if patch contains more than one change for same file only one will be
+#    copied
+#  - works well only with patch prepared for -p1
+#  
 use strict;
 use warnings;
 
@@ -90,38 +95,38 @@
        }
        $split_patch[0] = [EMAIL PROTECTED];
 
-       my @chunk = (undef, undef, undef);
+       my @hunk = (undef, undef, undef);
        my $l;
        while ($l = shift @patch) {
                if ($l =~ /^--- /) {
-                       if (defined $chunk[2]) {
-                               push @split_patch, [EMAIL PROTECTED];
-                               @chunk = (undef, undef, undef);
+                       if (defined $hunk[2]) {
+                               push @split_patch, [EMAIL PROTECTED];
+                               @hunk = (undef, undef, undef);
                        }
-                       $chunk[0] = find_file_common($l, $chunk[2])
-                               if defined $chunk[2];
-                       $chunk[1] = $l;
+                       $hunk[0] = find_file_common($l, $hunk[2])
+                               if defined $hunk[2];
+                       $hunk[1] = $l;
                        next;
                }
-               if ($l =~ /^\+\+\+ / and defined $chunk[1]) {
-                       $chunk[2] = $l;
-                       $chunk[0] = find_file_common($chunk[1], $chunk[2]);
+               if ($l =~ /^\+\+\+ / and defined $hunk[1]) {
+                       $hunk[2] = $l;
+                       $hunk[0] = find_file_common($hunk[1], $hunk[2]);
                        next;
                }
-               next unless defined $chunk[0];
+               next unless defined $hunk[0];
                if ($l !~ /^[+-@ ]/) {
-                       push @split_patch, [EMAIL PROTECTED];
-                       @chunk = (undef, undef, undef);
+                       push @split_patch, [EMAIL PROTECTED];
+                       @hunk = (undef, undef, undef);
                        redo;
                }
-               push @chunk, $l;
+               push @hunk, $l;
        }
-       push @split_patch, [EMAIL PROTECTED] if defined $chunk[0];
+       push @split_patch, [EMAIL PROTECTED] if defined $hunk[0];
 
        return [EMAIL PROTECTED]
 }
 
-sub sort_chunks($$) {
+sub sort_hunks($$) {
        my ($new, $old_files) = @_;
        my $diff;
        local $" = "";
@@ -129,24 +134,24 @@
        shift @{$new};
        my %new_hash = map { $_->[0] => $_ } @{$new};
        
-       foreach my $oldchunk (@{$old_files}) {
-               my $f = $oldchunk->[0];
+       foreach my $oldhunk (@{$old_files}) {
+               my $f = $oldhunk->[0];
                next unless exists $new_hash{$f};
-               my $newchunk = $new_hash{$f};
-               $diff .= "$oldchunk->[1]";
-               $diff .= "$oldchunk->[2]";
+               my $newhunk = $new_hash{$f};
+               $diff .= "$oldhunk->[1]";
+               $diff .= "$oldhunk->[2]";
                
-               shift @{$newchunk};
-               shift @{$newchunk};
-               shift @{$newchunk};
-               $diff .= "@{$newchunk}";
+               shift @{$newhunk};
+               shift @{$newhunk};
+               shift @{$newhunk};
+               $diff .= "@{$newhunk}";
                delete $new_hash{$f};
        }
        
        foreach my $f (sort keys %new_hash) {
-               my $newchunk = $new_hash{$f};
-               shift @{$newchunk};
-               $diff .= "@{$newchunk}";
+               my $newhunk = $new_hash{$f};
+               shift @{$newhunk};
+               $diff .= "@{$newhunk}";
        }
        return $diff;
 }
@@ -155,7 +160,7 @@
        my ($file) = @_;
        my $old_files = get_files($file);
        my $splat = split_patch($file);
-       my $new_diff = sort_chunks($splat, $old_files);
+       my $new_diff = sort_hunks($splat, $old_files);
        rename $file, $file.".bak" or die "Can't rename file\n";
        open F_OUT, ">", $file or die "Dupa: $!\n";
        print F_OUT $new_diff;
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/patch_minimizer?r1=1.1&r2=1.2&f=u

_______________________________________________
pld-cvs-commit mailing list
pld-cvs-commit@lists.pld-linux.org
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to