* extfs/patchfs.in: Don't rely on tell() - it doesn't always

work on pipes.  Determine patch size by adding together the line
lengths.
This commit is contained in:
Pavel Roskin 2002-12-19 17:36:58 +00:00
parent 6ee35e2c55
commit 1df0641954
2 changed files with 21 additions and 15 deletions

View File

@ -1,3 +1,9 @@
2002-12-19 Andrew V. Samoilov <sav@bcs.zp.ua>
* extfs/patchfs.in: Don't rely on tell() - it doesn't always
work on pipes. Determine patch size by adding together the line
lengths.
2002-12-19 Adam Byrtek <alpha@debian.org> 2002-12-19 Adam Byrtek <alpha@debian.org>
* extfs/patchfs.in: Allow diffs with function names after "@@". * extfs/patchfs.in: Allow diffs with function names after "@@".

View File

@ -4,9 +4,7 @@
# #
# extfs to handle patches in unified diff format # extfs to handle patches in unified diff format
use bytes;
use strict; use strict;
use POSIX;
# standard binaries # standard binaries
my $bzip = "bzip2"; my $bzip = "bzip2";
@ -56,12 +54,14 @@ sub list
import Date::Parse if ($parsedates); import Date::Parse if ($parsedates);
# state==1 means diff contents, state==0 means comments # state==1 means diff contents, state==0 means comments
$state=1; $f=""; $state = 1; $f = '';
my $cpos = 0;
while (<I>) { while (<I>) {
if (/^-{3} /) { $cpos += length;
if (/^--- /) {
# parse diff header # parse diff header
if ($state==1) { if ($state==1) {
$npos=tell(I)-length; $npos = $cpos - length;
printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $npos-$pos, datetime($time), $prefix, $f printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $npos-$pos, datetime($time), $prefix, $f
if $f; if $f;
$pos=$npos; $pos=$npos;
@ -69,10 +69,10 @@ sub list
$state=1; $state=1;
error "Can't parse unified diff header" error "Can't parse unified diff header"
unless ((($_.=<I>).=<I>)=~/^\-{3} .*\n\+{3} .*\n@@ .* @@.*\n$/); unless ((($_.=<I>).=<I>)=~/^\--- .*\n\+\+\+ .*\n@@ .* @@.*\n$/);
($fsrc)=/^-{3} ([^\s]+).*\n.*\n.*\n$/; ($fsrc)=/^--- ([^\s]+).*\n.*\n.*\n$/;
($fdst)=/^.*\n\+{3} ([^\s]+).*\n.*\n$/; ($fdst)=/^.*\n\+\+\+ ([^\s]+).*\n.*\n$/;
($time)=/^.*\n\+{3} [^\s]+\s+([^\t\n]+).*\n.*\n$/; ($time)=/^.*\n\+\+\+ [^\s]+\s+([^\t\n]+).*\n.*\n$/;
# select filename, conform with (diff.info)Multiple patches # select filename, conform with (diff.info)Multiple patches
$prefix=""; $prefix="";
@ -110,14 +110,14 @@ sub list
} elsif ($state==1 && !/^([+\- \n]|@@)/) { } elsif ($state==1 && !/^([+\- \n]|@@)/) {
# start of comments, end of diff contents # start of comments, end of diff contents
$npos=tell(I)-length; $npos = $cpos - length;
printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $npos-$pos, datetime($time), $prefix, $f printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $npos-$pos, datetime($time), $prefix, $f
if $f; if $f;
$pos=$npos; $pos=$npos;
$state=0; $state=0;
} }
} }
$npos=tell(I); $npos = $cpos;
printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $npos-$pos, datetime($time), $prefix, $f printf "-rw-r--r-- 1 %s %s %d %s %s%s\n", $uid, $gid, $npos-$pos, datetime($time), $prefix, $f
if $f; if $f;
} }
@ -132,15 +132,15 @@ sub copyout
# state==1 means diff contents, state==0 mens comments # state==1 means diff contents, state==0 mens comments
$state=1; $found=0; $buf=""; $state=1; $found=0; $buf="";
while (<I>) { while (<I>) {
if (/^-{3} /) { if (/^--- /) {
# parse diff header # parse diff header
last if ($state==1 && $found); last if ($state==1 && $found);
$state=1; $state=1;
error "Can't parse unified diff header" error "Can't parse unified diff header"
unless ((($_.=<I>).=<I>)=~/^\-{3} .*\n\+{3} .*\n@@ .* @@.*\n$/); unless ((($_.=<I>).=<I>)=~/^\--- .*\n\+\+\+ .*\n@@ .* @@.*\n$/);
($fsrc)=/^-{3} ([^\s]+).*\n.*\n.*\n$/; ($fsrc)=/^--- ([^\s]+).*\n.*\n.*\n$/;
($fdst)=/^.*\n\+{3} ([^\s]+).*\n.*\n$/; ($fdst)=/^.*\n\+\+\+ ([^\s]+).*\n.*\n$/;
$found=1 if (($fsrc eq $file) || ($fdst eq $file)); $found=1 if (($fsrc eq $file) || ($fdst eq $file));
} elsif ($state==1 && !/^([+\- \n]|@@)/) { } elsif ($state==1 && !/^([+\- \n]|@@)/) {