]> git.pld-linux.org Git - packages/rpm-build-tools.git/commitdiff
- sed split was buggy, use diff2hunks code by dig
authorElan Ruusamäe <glen@pld-linux.org>
Mon, 12 Dec 2005 13:32:47 +0000 (13:32 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    builder.sh -> 1.357

builder.sh

index 03168a335deb83d1586da6ac14a9118e3966fa05..d2a4e95565af4b1ba21f692c705ca260a59e68c9 100644 (file)
@@ -1463,6 +1463,47 @@ diffcol()
         ' "$@"
 }
 
+
+diff2hunks()
+{
+        # diff2hunks orignally by dig
+        perl -e '
+#! /usr/bin/perl -w
+
+use strict;
+
+for my $filename (@ARGV) {
+    my $counter = 1;
+    my $fh;
+    open $fh, "<", $filename or die "$filename: open for reading: $!";
+    my @lines = <$fh>;
+    my @hunks;
+    my @curheader;
+    for my $i (0 ... $#lines) {
+        next unless $lines[$i] =~ m/^\@\@ /;
+        if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
+            @curheader = @lines[$i - 2 ... $i - 1];
+        }
+        next unless @curheader;
+        my $j = $i + 1;
+        while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
+        $j -= 2
+            if $j >= 3 and $j < @lines
+                and $lines[$j - 2] =~ m/^--- /
+                and $lines[$j - 1] =~ m/^\+\+\+ /;
+        $j--;
+        $j-- until $lines[$j] =~ m/^[ @+-]/;
+        my $hunkfilename = $filename;
+        $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
+        my $ofh;
+        open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
+        print $ofh @curheader, @lines[$i ... $j];
+        close $ofh;
+    }
+}
+' "$@"
+}
+
 adapterize()
 {
         cd "$SPECS_DIR"
@@ -1484,12 +1525,8 @@ adapterize()
                                                  break
                                         ;;
                                         [cC]) # confirm each chunk
-                                                 head -n 2 $tmpdir/$SPECFILE.diff > $tmpdir/header.diff
-                                                 lines=$(grep -n ^@@ $tmpdir/$SPECFILE.diff | cut -d: -f1)
-                                                 for a in $lines; do
-                                                               t=$tmpdir/chunk-$a.diff
-                                                               cat $tmpdir/header.diff > $t
-                                                               sed -ne "$a,/@@/p" $tmpdir/$SPECFILE.diff >> $t
+                                                 diff2hunks $tmpdir/$SPECFILE.diff
+                                                 for t in $(ls $tmpdir/$SPECFILE-*.diff); do
                                                                diffcol $t | less -r
                                                                echo -n "Accept? (Yes, [N]o)? "
                                                                read ans
This page took 0.034411 seconds and 4 git commands to generate.