Changeset 18513 in webkit


Ignore:
Timestamp:
Jan 1, 2007 8:13:43 PM (17 years ago)
Author:
ddkilzer
Message:

WebKitTools:

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=12023
svn-create-patch and friends should handle moved/copied files

  • Scripts/svn-apply: Identify copied files and handle those before all other patches.
  • Scripts/svn-create-patch: Generate patches with subtle changes for copied files. (findMimeType($)): Added. (findModificationTime($)): Added. (findSourceFileAndRevision($)): Added. (generateDiff($$$)): Changed to use svn stat instead of svn diff. (isBinaryMimeType($)): Added. (manufacturePatchForAdditionWithHistory($$)): Added.
  • Scripts/svn-unapply: Identify copied files and handle those after unapplying all other patches.
Location:
trunk/WebKitTools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r18469 r18513  
     12007-01-01  David Kilzer  <ddkilzer@webkit.org>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=12023
     6        svn-create-patch and friends should handle moved/copied files
     7
     8        * Scripts/svn-apply: Identify copied files and handle those before all other patches.
     9        * Scripts/svn-create-patch: Generate patches with subtle changes for copied files.
     10        (findMimeType($)): Added.
     11        (findModificationTime($)): Added.
     12        (findSourceFileAndRevision($)): Added.
     13        (generateDiff($$$)): Changed to use svn stat instead of svn diff.
     14        (isBinaryMimeType($)): Added.
     15        (manufacturePatchForAdditionWithHistory($$)): Added.
     16        * Scripts/svn-unapply: Identify copied files and handle those after unapplying all other patches.
     17
    1182006-12-29  Eric Seidel  <eric@eseidel.com>
    219
  • trunk/WebKitTools/Scripts/svn-apply

    r15477 r18513  
    4444#       the patch to today's date using $changeLogTimeZone.
    4545#   Handles binary files (requires patches made by svn-create-patch).
     46#   Handles copied and moved files (requires patches made by svn-create-patch).
    4647#
    4748# Missing features:
    4849#
    4950#   Handle property changes.
    50 #   Handle file moves (would require patches made by svn-create-patch).
     51#   Handle copied and moved directories (would require patches made by svn-create-patch).
    5152#   When doing a removal, check that old file matches what's being removed.
    5253#   Notice a patch that's being applied at the "wrong level" and make it work anyway.
     
    9495
    9596my %checkedDirectories;
     97my %copiedFiles;
    9698my @patches;
    9799my %versions;
    98100
     101my $copiedFromPath;
    99102my $indexPath;
    100103my $patch;
     
    105108        $indexPath = $1;
    106109        if ($patch) {
    107             push @patches, $patch;
     110            if (!$copiedFromPath) {
     111                push @patches, $patch;
     112            }
     113            $copiedFromPath = "";
    108114            $patch = "";
    109115        }
     
    113119        s/\S+$/$indexPath/ if /^diff/;
    114120        s/^--- \S+/--- $indexPath/;
     121        if (/^--- .+\(from (\S+):(\d+)\)$/) {
     122            $copiedFromPath = $1;
     123            $copiedFiles{$indexPath} = $copiedFromPath;
     124            $versions{$copiedFromPath} = $2 if ($2 != 0);
     125        }
     126        elsif (/^--- .+\(revision (\d+)\)$/) {
     127            $versions{$indexPath} = $1 if ($1 != 0);
     128        }
    115129        if (s/^\+\+\+ \S+/+++ $indexPath/) {
    116130            $indexPath = "";
    117131        }
    118132    }
    119     if (/^--- .+\(revision (\d+)\)$/) {
    120         $versions{$indexPath} = $1 if( $1 != 0 );
    121     }
    122133    $patch .= $_;
    123134    $patch .= "\n";
    124135}
    125136
    126 push @patches, $patch if $patch;
     137if ($patch && !$copiedFromPath) {
     138    push @patches, $patch;
     139}
    127140
    128141if ($merge) {
     
    131144        system "svn", "update", "-r", $versions{$file}, $file;
    132145    }
     146}
     147
     148# Handle copied and moved files first since moved files may have their source deleted before the move.
     149for my $file (keys %copiedFiles) {
     150    addDirectoriesIfNeeded(dirname($file));
     151    system "svn", "copy", $copiedFiles{$file}, $file;
    133152}
    134153
  • trunk/WebKitTools/Scripts/svn-create-patch

    r15393 r18513  
    3535#   Handles binary files (encoded as a base64 chunk of text).
    3636#   Sorts the diffs alphabetically by text files, then binary files.
     37#   Handles copied and moved files.
    3738#
    3839# Missing features:
    3940#
    40 #   Handle moved files.
     41#   Handle copied and moved directories.
    4142
    4243use strict;
     
    5455
    5556sub canonicalizePath($);
     57sub findMimeType($);
     58sub findModificationType($);
     59sub findSourceFileAndRevision($);
    5660sub fixChangeLogPatch($);
    57 sub generateDiff($);
     61sub generateDiff($$$);
    5862sub generateFileList($\%\%);
     63sub isBinaryMimeType($);
     64sub manufacturePatchForAdditionWithHistory($$);
    5965sub numericcmp($$);
    6066sub outputBinaryContent($);
     
    8086# Generate the diff for text files, then binary files, for easy reviewing
    8187for my $file (sort pathcmp keys %textFiles) {
    82     generateDiff($file);
     88    generateDiff($file, $textFiles{$file}, 0);
    8389}
    8490for my $file (sort pathcmp keys %binaryFiles) {
    85     generateDiff($file);
     91    generateDiff($file, $binaryFiles{$file}, 1);
    8692}
    8793
     
    106112    }
    107113    return ($#dirs >= 0) ? File::Spec->catdir(@dirs) : ".";
     114}
     115
     116sub findMimeType($)
     117{
     118    my ($file) = @_;
     119    open PROPGET, "svn propget svn:mime-type '$file' |" or die;
     120    my $mimeType = <PROPGET>;
     121    close PROPGET;
     122    chomp $mimeType if $mimeType;
     123    return $mimeType;
     124}
     125
     126sub findModificationType($)
     127{
     128    my ($stat) = @_;
     129    my $fileStat = substr($stat, 0, 1);
     130    my $propertyStat = substr($stat, 1, 1);
     131    if ($fileStat eq "A") {
     132        my $additionWithHistory = substr($stat, 3, 1);
     133        return $additionWithHistory eq "+" ? "additionWithHistory" : "addition";
     134    }
     135    return "modification" if ($fileStat eq "M" || $propertyStat eq "M");
     136    return "deletion" if ($fileStat eq "D");
     137    return undef;
     138}
     139
     140sub findSourceFileAndRevision($)
     141{
     142    my ($file) = @_;
     143    my $baseUrl;
     144    open INFO, "svn info . |" or die;
     145    while (<INFO>) {
     146        if (/^URL: (.+)/) {
     147            $baseUrl = $1;
     148            last;
     149        }
     150    }
     151    close INFO;
     152    my $sourceFile;
     153    my $sourceRevision;
     154    open INFO, "svn info '$file' |" or die;
     155    while (<INFO>) {
     156        if (/^Copied From URL: (.+)/) {
     157            $sourceFile = substr($1, length($baseUrl) + 1);
     158        } elsif (/^Copied From Rev: ([0-9]+)/) {
     159            $sourceRevision = $1;
     160        }
     161    }
     162    close INFO;
     163    return ($sourceFile, $sourceRevision);
    108164}
    109165
     
    159215}
    160216
    161 sub generateDiff($)
    162 {
    163     my ($file) = @_;
    164     my $errors = "";
    165     my $isBinary;
     217sub generateDiff($$$)
     218{
     219    my ($file, $modificationType, $isBinary) = @_;
    166220    my $patch;
     221    if ($modificationType eq "additionWithHistory") {
     222        manufacturePatchForAdditionWithHistory($file, $isBinary);
     223    }
    167224    open DIFF, "svn diff --diff-cmd diff -x -uNp '$file' |" or die;
    168225    while (<DIFF>) {
    169         $isBinary = 1 if (/^Cannot display: file marked as a binary type\.$/);
    170226        $patch .= $_;
    171227    }
    172228    close DIFF;
    173229    $patch = fixChangeLogPatch($patch) if basename($file) eq "ChangeLog";
    174     print $patch;
     230    print $patch if $patch;
    175231    if ($isBinary) {
    176         print "\n" if $patch =~ m/\n\S+$/m;
     232        print "\n" if ($patch && $patch =~ m/\n\S+$/m);
    177233        outputBinaryContent($file);
    178234    }
    179     print STDERR $errors;
    180235}
    181236
    182237sub generateFileList($\%\%)
    183238{
    184     my ($path, $textFiles, $binaryFiles) = @_;
    185     my $indexPath;
    186     my $isBinary;
    187     open DIFF, "svn diff --diff-cmd diff -x -uNp '$path' |" or die;
    188     while (<DIFF>) {
    189         if (/^Index: (.*)/) {
    190             my $newIndexPath = $1;
    191             if ($indexPath) {
    192                 if ($isBinary) {
    193                     $binaryFiles->{$indexPath} = 1;
    194                 } else {
    195                     $textFiles->{$indexPath} = 1;
    196                 }
    197             }
    198             $indexPath = $newIndexPath;
    199             $isBinary = 0;
    200         }
    201         if (/^Cannot display: file marked as a binary type\.$/) {
    202             $isBinary = 1;
    203         }
    204     }
    205     close DIFF;
    206     # Handle last patch
    207     if ($indexPath) {
    208         if ($isBinary) {
    209             $binaryFiles->{$indexPath} = 1;
     239    my ($statPath, $textFiles, $binaryFiles) = @_;
     240    open STAT, "svn stat '$statPath' |" or die;
     241    while (my $line = <STAT>) {
     242        chomp $line;
     243        my $stat = substr($line, 0, 7);
     244        my $path = substr($line, 7);
     245        my $modificationType = findModificationType($stat);
     246        if ($modificationType) {
     247            if (isBinaryMimeType($path)) {
     248                $binaryFiles->{$path} = $modificationType;
     249            } else {
     250                $textFiles->{$path} = $modificationType;
     251            }
    210252        } else {
    211             $textFiles->{$indexPath} = 1;
    212         }
     253            print STDERR $line, "\n";
     254        }
     255    }
     256    close STAT;
     257}
     258
     259sub isBinaryMimeType($)
     260{
     261    my ($file) = @_;
     262    my $mimeType = findMimeType($file);
     263    return 0 if (!$mimeType || substr($mimeType, 0, 5) eq "text/");
     264    return 1;
     265}
     266
     267sub manufacturePatchForAdditionWithHistory($$)
     268{
     269    my ($file, $isBinary) = @_;
     270    print "Index: ${file}\n";
     271    print "=" x 67, "\n";
     272    my ($sourceFile, $sourceRevision) = findSourceFileAndRevision($file);
     273    print "--- ${file}\t(revision ${sourceRevision})\t(from ${sourceFile}:${sourceRevision})\n";
     274    print "+++ ${file}\t(working copy)\n";
     275    if ($isBinary) {
     276        print "\nCannot display: file marked as a binary type.\n";
     277        my $mimeType = findMimeType($file);
     278        print "svn:mime-type = ${mimeType}\n\n";
     279    } else {
     280        print `svn cat -r${sourceRevision} ${sourceFile} | diff -u /dev/null - | tail +3`;
    213281    }
    214282}
  • trunk/WebKitTools/Scripts/svn-unapply

    r15477 r18513  
    4141#       the patch before it is applied (svn-apply sets it when applying a patch).
    4242#   Handles binary files (requires patches made by svn-create-patch).
     43#   Handles copied and moved files (requires patches made by svn-create-patch).
    4344#
    4445# Missing features:
    4546#
    4647#   Handle property changes.
    47 #   Handle file moves (would require patches made by svn-create-patch).
     48#   Handle copied and moved directories (would require patches made by svn-create-patch).
    4849#   Use version numbers in the patch file and do a 3-way merge.
    4950#   When reversing an addition, check that the file matches what's being removed.
     
    7778}
    7879
     80my @copiedFiles;
    7981my %directoriesToCheck;
    8082
     83my $copiedFromPath;
    8184my $indexPath;
    8285my $patch;
     
    8790        $indexPath = $1;
    8891        if ($patch) {
    89             patch($patch);
     92            if ($copiedFromPath) {
     93                push @copiedFiles, $patch;
     94            } else {
     95                patch($patch);
     96            }
     97            $copiedFromPath = "";
    9098            $patch = "";
    9199        }
     
    94102        # Fix paths on diff, ---, and +++ lines to match preceding Index: line.
    95103        s/^--- \S+/--- $indexPath/;
     104        if (/^--- .+\(from (\S+):\d+\)$/) {
     105            $copiedFromPath = $1;
     106        }
    96107        if (s/^\+\+\+ \S+/+++ $indexPath/) {
    97108            $indexPath = "";
     
    101112    $patch .= "\n";
    102113}
    103 patch($patch);
     114
     115if ($patch) {
     116    if ($copiedFromPath) {
     117        push @copiedFiles, $patch;
     118    } else {
     119        patch($patch);
     120    }
     121}
     122
     123# Handle copied and moved files last since they may have had post-copy changes that have now been unapplied
     124for $patch (@copiedFiles) {
     125    patch($patch);
     126}
    104127
    105128revertDirectories();
     
    181204    my $isBinary = 0;
    182205
    183     $addition = 1 if $patch =~ /\n--- .+\(revision 0\)\n/;
     206    $addition = 1 if ($patch =~ /\n--- .+\(revision 0\)\n/ || $patch =~ /\n@@ -0,0 .* @@/);
    184207    $deletion = 1 if $patch =~ /\n@@ .* \+0,0 @@/;
    185208    $isBinary = 1 if $patch =~ /\nCannot display: file marked as a binary type\./;
Note: See TracChangeset for help on using the changeset viewer.