+2005-06-11 Darin Adler <darin@apple.com>
+
+ - added first cuts at some cvs scripts
+
+ cvs-abandon is for throwing away changes; discards any local changes, reverting to the state in CVS
+ cvs-create-patch is for making patches; runs cvs diff with all the right options and handles added/deleted files
+ cvs-apply is for applying patches; runs patch and cvs add and cvs rm
+ cvs-unapply is for unapplying patches; does the opposite of cvs-apply
+
+ An argument against these is "waste of time if we switch to Subversion", but they should be good for a while.
+
+ * Scripts/cvs-abandon: Added.
+ * Scripts/cvs-apply: Added.
+ * Scripts/cvs-create-patch: Added.
+ * Scripts/cvs-unapply: Added.
+
2005-06-09 Darin Adler <darin@apple.com>
Reviewed by Maciej.
--- /dev/null
+#!/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.
+
+# Figure out the underlying cvs versions.
+# Overwrite each file with the underlying cvs version.
+
+use strict;
+use Getopt::Long;
+
+my $verbose = 0;
+GetOptions("verbose|v!" => \$verbose);
+
+my @changedFiles = ();
+my @addedFiles = ();
+my @removedFiles = ();
+
+print STDERR "Running cvs -n update to find changed, added, or removed files.\n" if $verbose;
+open UPDATE, "cvs -qn update @ARGV 2> /dev/stdout |" or die "The cvs update failed: $!.\n";
+while (<UPDATE>) {
+ if (/^[CM] (.+)$/) {
+ print STDERR "Found changed file $1.\n" if $verbose;
+ push @changedFiles, $1;
+ } elsif (/^A (.+)$/) {
+ print STDERR "Found added file: $1\n" if $verbose;
+ push @addedFiles, $1;
+ } elsif (/^R (.+)$/) {
+ print STDERR "Found removed file: $1\n" if $verbose;
+ push @removedFiles, $1;
+ }
+
+ print unless /^[A-Z] ./ || /^cvs server: New directory/;
+}
+close UPDATE;
+
+my $startDir = `pwd`;
+chomp $startDir;
+
+sub getDirAndBase
+{
+ my ($file) = @_;
+ return ($1, $2) if $file =~ m|^(.+)/([^/]+)$|;
+ $file !~ m|/| or die "Could not parse file name $file.\n";
+ return (".", $file);
+}
+
+for my $file (@changedFiles) {
+ my ($dir, $base) = getDirAndBase($file);
+
+ my $version = "";
+ open ENTRIES, "$dir/CVS/Entries" or die "Could not open $dir/CVS/Entries.\n";
+ while (<ENTRIES>) {
+ $version = $1 if m|^/$base/([.0-9]+)/|;
+ }
+ close ENTRIES;
+ $version or die "Could not find version for $file.\n";
+
+ print STDERR "Reverting file $file to version $version.\n" if $verbose;
+ chdir $dir or die;
+ system "cvs -q update -r $version -p $base > $base" and die "cvs update failed on $file.\n";
+ chdir $startDir or die;
+}
+
+for my $file (@removedFiles) {
+ my ($dir, $base) = getDirAndBase($file);
+
+ print STDERR "Re-adding file $file.\n" if $verbose;
+ chdir $dir or die;
+ system "cvs", "add", $base and die "cvs add failed on $file.\n";
+ chdir $startDir or die;
+}
+
+for my $file (@addedFiles) {
+ my ($dir, $base) = getDirAndBase($file);
+
+ print STDERR "Removing file $file.\n" if $verbose;
+ chdir $dir or die;
+ system "cvs", "rm", "-f", $base and die "cvs rm failed on $file.\n";
+ chdir $startDir or die;
+}
--- /dev/null
+#!/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 doing a removal, doesn't check that old file matches what's being removed.
+
+use strict;
+
+my $startDir = `pwd`;
+chomp $startDir;
+
+my $indexPath;
+my $patch;
+while (<>) {
+ 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 /^diff/;
+ s/^--- \S+/--- $indexPath/;
+ s/^\+\+\+ \S+/+++ $indexPath/;
+ }
+ $patch .= $_;
+}
+patch($patch);
+
+sub patch
+{
+ my ($patch) = @_;
+ if ($patch !~ /\ndiff -N/) {
+ # Standard patch, patch tool can handle this.
+ open PATCH, "| patch -p0" 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;
+ my $prefix = $1;
+ my $base = $3;
+ chdir $prefix if $prefix;
+
+ if ($patch =~ /\n@@ .* \+0,0 @@/) {
+ # Deletion.
+ system "cvs", "rm", "-f", $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 "cvs", "add", "$base";
+ }
+
+ chdir $startDir if $prefix;
+ }
+}
--- /dev/null
+#!/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 but improved "cvs diff" script for Web Kit Open Source Project, used to make patches.
+
+# Differences from standard "cvs diff":
+#
+# Always passes "-N" to diff so it will include deleted and added files.
+# Always passes "-u" to diff so it will use unified diff format.
+# Always passes "-p" to diff so it will try to include function names.
+# Other command line options are not supported.
+# Works in mixed CVS root situations like the mix of internal and open source CVS repositories
+# for Apple's Safari and WebKit team, by doing a separate cvs invocation for each directory.
+# Fixes diff output paths so they will work with the "patch" tool.
+#
+# Missing feature:
+#
+# Handle binary files (some text form of the binary file).
+
+use strict;
+
+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 =~ /'/;
+
+ 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;
+ }
+ }
+}
+
+# Function to generate a diff.
+sub diff
+{
+ my ($path) = @_;
+ my $errors = "";
+ open DIFF, "cvs diff -lNpu '$path' |" or die;
+ my $indexPath;
+ while (<DIFF>) {
+ $indexPath = $1 if /^Index: (.*)/;
+ if ($indexPath) {
+ # Fix paths on diff, ---, and +++ lines to match preceding Index: line.
+ s/\S+$/$indexPath/ if /^diff/;
+ s/^--- \S+/--- $indexPath/;
+ s/^\+\+\+ \S+/+++ $indexPath/;
+ }
+ if (/^\?/) {
+ $errors .= $_;
+ } else {
+ print;
+ }
+ }
+ close DIFF;
+ print STDERR $errors;
+}
+
+# Generate the diff for each passed file or directory.
+for my $path (sort keys %paths) {
+ my $prefix = $path eq "." ? "" : "$path/";
+ if (-d $path) {
+ for my $CVS (`find '$path' -name CVS`) {
+ chomp $CVS;
+ die "can't handle files named CVS like \"$CVS\"\n" if !-d $CVS;
+ my $dir = $CVS;
+ $dir =~ s|/CVS$||;
+ diff($dir);
+ }
+ } else {
+ diff($path);
+ }
+}
--- /dev/null
+#!/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;
+
+my $startDir = `pwd`;
+chomp $startDir;
+
+my $indexPath;
+my $patch;
+while (<>) {
+ 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 /^diff/;
+ s/^--- \S+/--- $indexPath/;
+ s/^\+\+\+ \S+/+++ $indexPath/;
+ }
+ $patch .= $_;
+}
+patch($patch);
+
+sub patch
+{
+ my ($patch) = @_;
+ if ($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.
+
+ $patch =~ m|^Index: (([^/\n]*/)+)([^/\n]+)| or die;
+ my $prefix = $1 || ".";
+ my $base = $3;
+
+ # Change directory down into the directory in question.
+ chdir $prefix or die;
+
+ if ($patch =~ /\n@@ .* \+0,0 @@/) {
+ # Reverse a deletion.
+ system "cvs", "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 "cvs", "rm", "-f", $base;
+ }
+
+ chdir $startDir or die;
+ }
+}