patchfs fix for unified diffs

Oskar Liljeblad oskar at osk.mine.nu
Mon Oct 13 21:14:09 UTC 2003


Hello

This patch fixes a bug in MC's patchfs.
Without the patch the linux kernel 2.4.21 patch
(ftp://ftp.kernel.org/pub/linux/kernel/v2.4/patch-2.4.21.gz)
could not be viewed because it contained a few lines which
confused the patchfs parser:

--- Sym = Symetric: both link partners are allowed to send PAUSE frames
--- SymOrRem = SymetricOrRemote: both or only remote partner are allowed
-   to send PAUSE frames

You'd get some dialog saying that the unified diff couldn't
be parsed. This patch fixes that by parsing @@-lines in
the diff and that way counting number of lines in each hunk.
All lines in the hunk are then ignored instead of being parsed.

Regards,

Oskar

diff -u patchfs.v0 patchfs
--- patchfs.v0  2003-10-13 23:03:04.000000000 +0200
+++ patchfs     2003-10-13 23:10:41.000000000 +0200
@@ -82,7 +82,13 @@
            }
        }
 
-       if (($unified && /^--- /) || ($context && /^\*\*\* [^\*]*$/)) {
+       if ($state==1 && $unified && /^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/) {
+           my $lines = $2+$4;
+           while ($lines > 0 && defined ($_ = <I>)) {
+               $lines -= 1 if /^[-+]/;
+               $lines -= 2 if /^ /;
+           }
+       } elsif (($unified && /^--- /) || ($context && /^\*\*\* [^\*]*$/)) {
            # start of new file
            if ($state==1) {
                printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $len, datetime($time), $prefix, $f
@@ -172,7 +178,13 @@
            }
        }
 
-       if (($unified && /^--- /) || ($context && /^\*\*\* [^\*]*$/)) {
+       if ($state==1 && $unified && /^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/) {
+           my $lines = $2+$4;
+           while ($lines > 0 && defined ($_ = <I>)) {
+               $lines -= 1 if /^[-+]/;
+               $lines -= 2 if /^ /;
+           }
+       } elsif (($unified && /^--- /) || ($context && /^\*\*\* [^\*]*$/)) {
            last if ($state==1 && $found);
            $state=1;



More information about the mc-devel mailing list