ooo-build r15259 - in branches/opensuse-11-1: . bin patches



Author: pmladek
Date: Fri Jan 30 16:48:34 2009
New Revision: 15259
URL: http://svn.gnome.org/viewvc/ooo-build?rev=15259&view=rev

Log:
2009-01-30  Petr Mladek  <pmladek suse cz>

	* patches/apply.pl.in, bin/sloppypatch.pl: fix to apply patches
	  that have correct file paths on --- lines instead of +++ lines;
	  also support diffs with the "copied context"; it will fix some
	  bugs, e.g. bnc#443698



Modified:
   branches/opensuse-11-1/ChangeLog
   branches/opensuse-11-1/bin/sloppypatch.pl
   branches/opensuse-11-1/patches/apply.pl.in

Modified: branches/opensuse-11-1/bin/sloppypatch.pl
==============================================================================
--- branches/opensuse-11-1/bin/sloppypatch.pl	(original)
+++ branches/opensuse-11-1/bin/sloppypatch.pl	Fri Jan 30 16:48:34 2009
@@ -25,42 +25,81 @@
     sysopen( $fh, $tmpfile, O_RDWR | O_CREAT | O_EXCL ) && last;
 }
 
-my $eliding = 1;
-my $minusline = '';
-my $minusline_dir = '';
-my $minusline_subpath = '';
+sub analyze_path($)
+{
+    my $pf = shift;
+    my $topdir = undef;
+    my $subpath = undef;
+    
+#    print "analyzing path: $pf\n";
+    $pf =~ s|\.\/+||;
+    if ( $pf =~ m/^([^\/]+)([^ \t]+)/ ) {
+	$topdir = "$1";
+	$subpath = "$2";
+	chomp $subpath;
+    }
+    
+    return $topdir, $subpath;
+}
+
+my $applying = 0;
+my $firstline = undef;
+my $firstline_topdir = undef;
+my $firstline_subpath = undef;
 my $sections = 0;
 while (<STDIN>) {
     my $line = $_;
-    if ( $line =~ m/^--- [ \t]*\.?\/?([^\/]+)([^ \t]+)/ ) {
-	$minusline_topdir="$1";
-	$minusline_subpath="$2";
-	$minusline .= $line;
+
+    # unified context patches:
+    # 	first line:  --- path
+    #	second line: +++ path
+    # copied context patches:
+    # 	first line:  *** path
+    #	second line: --- path
+    if  ( ( ! defined $firstline ) &&
+          ( $line =~ m/^[\*-][\*-][\*-] [ \t]*([^\s]+)/ ) ) {
+	# found first line that defines the path of the patched file
+	($firstline_topdir, $firstline_subpath) = analyze_path("$1");
+	$firstline = $line if (defined $firstline_topdir);
 	next;
     }
-    if ( $line =~ m/^\+\+\+ [ \t]*\.?\/?([^\/]+)([^ \t]+)/ ) {
-	my $topdir="$1";
-	my $subpath="$2";
 
-	# need to use the --- path when the file should get removed
-	chomp $subpath;
-	if ("$topdir$subpath" eq "dev/null") {
-	    $topdir="$minusline_topdir";
-	    $subpath="$minusline_subpath";
+    if ( $line =~ m/^[\+-][\+-][\+-] [ \t]*([^\s]+)/ ) {
+	# found second line that defines the path of the patched file
+	($topdir, $subpath) = analyze_path("$1");
+
+	# need to check all ***, +++, --- paths; any of them might be correct
+	# the other path might be invalid, e.g. absolute path
+	# the relative paths starting with ".." must be invalid because we use
+	# the -p0 patches and the upper direcotry name is different with every milestone
+	if ( defined $topdir && "$topdir" ne ".." && -d "$applydir/$topdir" ) {
+#	    print "topdir: $topdir\n";
+	    $applying = 1;
+	} elsif ( defined $firstline_topdir && "$firstline_topdir" ne ".." && -d "$applydir/$firstline_topdir" ) {
+#	    print "firstline_topdir: $firstline_topdir\n";
+	    $applying = 1;
+	    $topdir = $firstline_topdir;
+	    $subpath = $firstline_subpath;
+	} else {
+	    $applying = 0;
 	}
 
-	$eliding = ! -d "$applydir/$topdir";
-
-	if (!$eliding) {
+	if ($applying) {
 	    $sections++;
 	    print STDERR "+ apply fragment for $topdir$subpath\n";
 	}
-	$line = $minusline . $line;
-	$minusline = '';
-	$minusline_topdir='';
-	$minusline_subpath='';
+    
     }
-    if (!$eliding) {
+
+    if (defined $firstline) {
+	# either it is the real first line that defines the file path
+	# or it might be the hunk definition in the copied context patches
+	# we should print it in both cases
+	$line = $firstline . $line;
+	$firstline = undef;
+    }
+
+    if ($applying) {
 	print $fh $line;
     }
 }
@@ -68,6 +107,7 @@
 my $result = 0;
 if ($sections > 0) {
 # patch complains a lot with empty input
+#    print "calling: patch @ARGV < $tmpfile\n";
     if (system ("patch @ARGV < $tmpfile")) {
 	 print STDERR "\nError: failed to apply patch @ARGV: $!\n\n";
     }

Modified: branches/opensuse-11-1/patches/apply.pl.in
==============================================================================
--- branches/opensuse-11-1/patches/apply.pl.in	(original)
+++ branches/opensuse-11-1/patches/apply.pl.in	Fri Jan 30 16:48:34 2009
@@ -46,6 +46,8 @@
 
     foreach my $pf ( patched_files (slurp ($patch)) ) {
 #	print "\tpatched file '$pf'\n";
+	next if ($pf =~ m/^\//);	# skip absolute paths; they might come from the unused +++ or --- line
+	next if ($pf =~ m/^\.\./);	# skip paths starting with ../; they comes from the unused +++ or --- line
 	$pf =~ m/^([^\/]+)\// || die "malformed path $pf";
 	my $topdir = "$dest_dir/$1";
 #	print "\tcheck directory $topdir\n";
@@ -255,20 +257,21 @@
     my @lines = split (/\n/, $file);
     my @dest;
 
-    my $minusfile = '';
+    my $pf = undef;
     foreach my $line (@lines) {
-	if ( $line =~ m/^--- ([^\s]*)/) {
-	    $minusfile = $1;
-            $minusfile =~ s#[/]+#/#g;
-	}
-        if ( $line =~ /^\+\+\+ ([^\s]*)/ ) {
-            my $file = $1;
-            $file =~ s#[/]+#/#g;
-	    if ($file eq '/dev/null') { # removal
-		$file = $minusfile;
-	    }
-            push @dest, $file;
-        }
+	# we need to check all three types of file definitions: ***, +++ and ---
+	if ( $line =~ m/^--- ([^\s]*)/ ) {
+	    $pf = $1;
+	} elsif ( $line =~ /^\+\+\+ ([^\s]*)/ ) {
+	    $pf = $1;
+	} elsif ( $line =~ m/^\*\*\* ([^\s]*)/ ) {
+	    $pf = $1;
+	}
+	if ($pf) {
+            $pf =~ s#[/]+#/#g;
+	    push @dest, $pf if ($pf ne '/dev/null');
+	    $pf = undef;
+	}
     }
 
     return @dest;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]