[webkit-changes] cvs commit: WebKitTools/Scripts svn-apply svn-create-patch svn-unapply

Timothy thatcher at opensource.apple.com
Wed Jan 4 13:10:39 PST 2006


thatcher    06/01/04 13:10:39

  Modified:    .        ChangeLog
  Added:       Scripts  svn-apply svn-create-patch svn-unapply
  Log:
          Reviewed by Darin.
          Created by Eric.
          Tweaked and tested by me.
  
          New scripts to work with Subversion when the switch happens.
          These will replace cvs-apply, cvs-unapply, and cvs-create-patch.
  
          * Scripts/svn-apply: Added.
          * Scripts/svn-create-patch: Added.
          * Scripts/svn-unapply: Added.
  
  Revision  Changes    Path
  1.137     +13 -0     WebKitTools/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKitTools/ChangeLog,v
  retrieving revision 1.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- ChangeLog	30 Dec 2005 07:04:10 -0000	1.136
  +++ ChangeLog	4 Jan 2006 21:10:38 -0000	1.137
  @@ -1,3 +1,16 @@
  +2006-01-04  Timothy Hatcher  <timothy at apple.com>
  +
  +        Reviewed by Darin.
  +        Created by Eric.
  +        Tweaked and tested by me.
  +
  +        New scripts to work with Subversion when the switch happens.
  +        These will replace cvs-apply, cvs-unapply, and cvs-create-patch.
  +
  +        * Scripts/svn-apply: Added.
  +        * Scripts/svn-create-patch: Added.
  +        * Scripts/svn-unapply: Added.
  +
   2005-12-30  Eric Seidel  <eseidel at apple.com>
   
           Reviewed by mjs.
  
  
  
  1.1                  WebKitTools/Scripts/svn-apply
  
  Index: svn-apply
  ===================================================================
  #!/usr/bin/perl -w
  
  # Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  #
  # 1.  Redistributions of source code must retain the above copyright
  #     notice, this list of conditions and the following disclaimer. 
  # 2.  Redistributions in binary form must reproduce the above copyright
  #     notice, this list of conditions and the following disclaimer in the
  #     documentation and/or other materials provided with the distribution. 
  # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  #     its contributors may be used to endorse or promote products derived
  #     from this software without specific prior written permission. 
  #
  # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  # "patch" script for WebKit Open Source Project, used to apply patches.
  
  # Differences from invoking "patch -p0":
  #
  #   Handles added files (does a svn add).
  #   Handles removed files (does a svn rm).
  #   Has mode where it will roll back to svn version numbers in the patch file so svn can do a 3-way merge.
  #
  # Missing features:
  #
  #   Handle binary files.
  #   When doing a removal, doesn't check that old file matches what's being removed.
  #   Notice a patch that's being applied at the "wrong level" and make it work anyway.
  
  use strict;
  use Cwd;
  use Getopt::Long;
  
  my $merge = 0;
  GetOptions("merge" => \$merge); 
  
  my $startDir = getcwd();
  
  my @patches;
  my %versions;
  
  my $indexPath;
  my $patch;
  while (<>) {
      s/\r//g;
      chomp;
      if (/^Index: (.+)/) {
          $indexPath = $1;
          if ($patch) {
              push @patches, $patch;
              $patch = "";
          }
      }
      if ($indexPath) {
          # Fix paths on diff, ---, and +++ lines to match preceding Index: line.
          s/\S+$/$indexPath/ if /^diff/;
          s/^--- \S+/--- $indexPath/;
          if (s/^\+\+\+ \S+/+++ $indexPath/) {
              $indexPath = "";
          }
      }
      if (/^--- .+\(revision (\d+)\)$/) {
          $versions{$indexPath} = $1 if( $1 != 0 );
      }
      $patch .= $_;
      $patch .= "\n";
  }
  
  push @patches, $patch if $patch;
  
  if ($merge) {
      for my $file (sort keys %versions) {
          print "Getting version $versions{$file} of $file\n";
          $file =~ m|^(([^/\n]*/)*)([^/\n]+)$| or die;
          my ($prefix, $base) = ($1, $3);
          if ($prefix) {
              chdir $prefix or die;
          }
          system "svn update -r $versions{$file} $base";
          chdir $startDir;
      }
  }
  
  for $patch (@patches) {
      patch($patch);
  }
  
  sub patch
  {
      my ($patch) = @_;
      return if !$patch;
  
      $patch =~ m|^Index: ((([^/\n]*/)*)([^/\n]+))| or die "Failed to find Index: in \"$patch\"\n";
      my ($fullpath, $prefix, $base) = ($1, $2, $4);
  
      my $previousRevision = 0;
  	if($patch =~ /\n--- .+\(revision (\d+)\)\n/) { 
  	    $previousRevision = $1;
  	}
  
      if ($previousRevision != 0 || $patch !~ /\ndiff -N/) {
          # Standard patch, patch tool can handle this.
          open PATCH, "| patch -p0" or die "Failed to patch $fullpath\n";
          print PATCH $patch;
          close PATCH;
      } else {
          # Either a deletion or an addition.
  
          # Change directory down into the directory in question.
          chdirAddingDirectoriesIfNeeded($prefix);
  
          if ($patch =~ /\n@@ .* \+0,0 @@/) {
              # Deletion.
              system "svn", "rm", $base;
          } else {
              # Addition.
              my $file = $patch;
              if ($file !~ s/^(.*\n)*@@[^\n]+@@\n//) {
                  # Empty file.
                  $file = "";
              } else {
                  # Non-empty file: Remove leading + signs.
                  $file =~ s/^\+//;
                  $file =~ s/\n\+/\n/g;
              }
              open FILE, ">", $base or die;
              print FILE $file;
              close FILE;
              system "svn", "add", "$base";
          }
  
          chdir $startDir if $prefix;
      }
  }
  
  sub chdirAddingDirectoriesIfNeeded
  {
      my $path = shift;
      my @dirs = split('/', $path);
      while (my $dir = shift @dirs) {
          if (!-x $dir) {
              mkdir $dir or die "Failed create required directory: $dir for path: $path\n";
              system "svn", "add", "$dir";
          }
          chdir $dir or die "Failed to chdir to $dir\n";
      }
  }
  
  
  1.1                  WebKitTools/Scripts/svn-create-patch
  
  Index: svn-create-patch
  ===================================================================
  #!/usr/bin/perl -w
  
  # Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  #
  # 1.  Redistributions of source code must retain the above copyright
  #     notice, this list of conditions and the following disclaimer. 
  # 2.  Redistributions in binary form must reproduce the above copyright
  #     notice, this list of conditions and the following disclaimer in the
  #     documentation and/or other materials provided with the distribution. 
  # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  #     its contributors may be used to endorse or promote products derived
  #     from this software without specific prior written permission. 
  #
  # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  # Simplified and improved "svn diff" script for WebKit Open Source Project, used to make patches.
  
  # Differences from standard "svn diff":
  #
  #   Always passes "-p" to diff so it will try to include function names.
  #   Other command line options are not supported.
  #
  # Missing feature:
  #
  #   Handle binary files (some text form of the binary file).
  #   Handle moved files.
  
  use strict;
  use Cwd;
  use Getopt::Long;
  use Time::gmtime;
  use File::stat;
  use POSIX qw(:errno_h);
  use Config;
  
  my $startDir = getcwd();
  my %paths;
  
  # Create list of paths to diff.
  if (!@ARGV) {
      $paths{"."} = 1;
  } else {
      for my $file (@ARGV) {
          die "can't handle absolute paths like \"$file\"\n" if $file =~ m|^/|;
          die "can't handle empty string path\n" if $file eq "";
          die "can't handle path with ' in the name like \"$file\"\n" if $file =~ /'/; # ' (keep Xcode syntax highlighting happy)
  
          my $untouchedFile = $file;
          
          # Add a leading and trailing slash to simplify logic below.
          $file = "/$file/";
  
          # Remove repeated slashes.
          $file =~ s|//+|/|g;
  
          # Remove meaningless sequences involving ".".
          $file =~ s|/\./|/|g;
  
          # Remove meaningless sequences involving "..".
          $file =~ s|/[^./]/\.\./|/|g;
          $file =~ s|/[^/]+[^./]/\.\./|/|g;
          $file =~ s|/[^./][^/]+/\.\./|/|g;
          die "can't handle paths with .. like \"$untouchedFile\"\n" if $file =~ m|/\.\./|;
  
          # Remove the leading and trailing slash.
          $file =~ s|^/(.*)/$|$1|;
  
          $paths{$file} = 1;
      }
  }
  
  # Remove any paths that also have a parent listed.
  for my $path (keys %paths) {
      my $parent = $path;
      while ($parent =~ s|/+[^/]+$||) {
          if ($paths{$parent}) {
              delete $paths{$path};
              last;
          }
      }
  }
  
  sub getDirAndBase
  {
      my ($path) = @_;
      if (-d $path) {
          $path =~ s|/+$||;
          return ($path, ".");
      }
      return ($1, $2) if $path =~ m|^(.+)/([^/]+)$|;
      $path !~ m|/| or die "Could not parse path name $path.\n";
      return (".", $path);
  }
  
  # Function to generate a diff.
  sub diff
  {
      my ($path) = @_;
      my ($dir, $base) = getDirAndBase($path);
      my $errors = "";
      chdir $dir or die;
      open DIFF, "svn diff --diff-cmd diff -x -uNp  '$base' |" or die;
      my $indexPath;
      while (<DIFF>) {
          if (/^Index: (.*)/) {
              $indexPath = $1;
              if ($dir ne ".") {
                  $indexPath = "$dir/$indexPath";
                  $indexPath = getWebKitRelativePath($indexPath);
                  s/Index: .*/Index: $indexPath/;
              }
          }
          if ($indexPath) {
              # Fix paths on diff, ---, and +++ lines to match preceding Index: line.
              s/\S+$/$indexPath/ if /^diff/;
              s/^--- \S+/--- $indexPath/;
              s/^\+\+\+ \S+/+++ $indexPath/;
          }
          print;
      }
      close DIFF;
      chdir $startDir or die;
      print STDERR $errors;
  }
  
  # Generate the diff for each passed file or directory.
  for my $path (sort keys %paths) {
      diff($path);
  }
  
  
  
  1.1                  WebKitTools/Scripts/svn-unapply
  
  Index: svn-unapply
  ===================================================================
  #!/usr/bin/perl -w
  
  # Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  #
  # 1.  Redistributions of source code must retain the above copyright
  #     notice, this list of conditions and the following disclaimer. 
  # 2.  Redistributions in binary form must reproduce the above copyright
  #     notice, this list of conditions and the following disclaimer in the
  #     documentation and/or other materials provided with the distribution. 
  # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  #     its contributors may be used to endorse or promote products derived
  #     from this software without specific prior written permission. 
  #
  # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  # "patch" script for Web Kit Open Source Project, used to apply patches.
  
  # Differences from invoking "patch -p0":
  #
  #   Paths from Index: lines are used rather than the paths on the patch lines, which makes
  #       patches generated by "cvs diff" work.
  #   Handles added files (does a cvs add). 
  #   Handles removed files (does a cvs rm). 
  #
  # Missing features:
  #
  #   Use CVS version numbers in the patch file and do a 3-way merge.
  #   Handle binary files.
  #   When reversing an addition, doesn't check that file matches what's being removed.
  
  use strict;
  use Cwd;
  
  my $startDir = getcwd();
  
  my $indexPath;
  my $patch;
  while (<>) {
      s/\r//g;
      chomp;
      if (/^Index: (.*)/) {
          $indexPath = $1;
          if ($patch) {
              patch($patch);
              $patch = "";
          }
      }
      if ($indexPath) {
          # Fix paths on diff, ---, and +++ lines to match preceding Index: line.
          s/^--- \S+/--- $indexPath/;
          if (s/^\+\+\+ \S+/+++ $indexPath/) {
              $indexPath = "";
          }
      }
      $patch .= $_;
      $patch .= "\n";
  }
  patch($patch);
  
  sub patch
  {
      my ($patch) = @_;
      return if !$patch;
  
      my $previousRevision = 0;
  	if($patch =~ /\n--- .+\(revision (\d+)\)\n/) { 
  	    $previousRevision = $1;
  	}
  
      if ($previousRevision != 0 || $patch !~ /\ndiff -N/) {
          # Standard patch, patch tool can handle this.
          open PATCH, "| patch -p0 -R" or die;
          print PATCH $patch;
          close PATCH;
      } else {
          # Either a deletion or an addition.
  
          # Change directory down into the directory in question.
          $patch =~ m|^Index: (([^/\n]*/)*)([^/\n]+)| or die "Failed to find Index: in patch";
          my $prefix = $1;
          my $base = $3;
          if ($prefix) {
              chdir $prefix or die "Failed to chdir to $prefix";
          }
  
          if ($patch =~ /\n@@ .* \+0,0 @@/) {
              # Reverse a deletion.
              system "svn", "add", "$base";
              my $file = $patch;
              if ($file !~ s/^(.*\n)*@@[^\n]+@@\n//) {
                  # Empty file.
                  $file = "";
              } else {
                  # Non-empty file: Remove leading - signs.
                  $file =~ s/^-//;
                  $file =~ s/\n-/\n/g;
              }
              open FILE, ">", $base or die;
              print FILE $file;
              close FILE;
          } else {
              # Reverse an addition.
              system "svn", "rm", "--force", $base;
          }
  
          chdir $startDir or die;
      }
  }
  
  
  



More information about the webkit-changes mailing list