Reviewed by Darin.
- http://bugzilla.opendarwin.org/show_bug.cgi?id=9693
svn-apply should set ChangeLog date correctly when applying patches
* Scripts/svn-apply: Set the ChangeLog entry date using a configurable timezone
before applying the patch.
* Scripts/svn-unapply: Reset the ChangeLog entry date before unapplying the patch.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15279
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-07-09 David Kilzer <ddkilzer@kilzer.net>
+
+ Reviewed by Darin.
+
+ - http://bugzilla.opendarwin.org/show_bug.cgi?id=9693
+ svn-apply should set ChangeLog date correctly when applying patches
+
+ * Scripts/svn-apply: Set the ChangeLog entry date using a configurable timezone
+ before applying the patch.
+ * Scripts/svn-unapply: Reset the ChangeLog entry date before unapplying the patch.
+
2006-07-09 Darin Adler <darin@apple.com>
* Scripts/do-webcore-rename: Final version of this round of renaming for posterity.
# Paths from Index: lines are used rather than the paths on the patch lines, which
# makes patches generated by "cvs diff" work (increasingly unimportant since we
# use Subversion now).
-# ChangeLog patches use --fuzz=3 to prevent rejects.
+# ChangeLog patches use --fuzz=3 to prevent rejects, and the entry date is set in
+# the patch to today's date using $changeLogTimeZone.
# Handles binary files (requires patches made by svn-create-patch).
#
# Missing features:
use File::Spec;
use Getopt::Long;
use MIME::Base64;
+use POSIX qw(strftime);
sub addDirectoriesIfNeeded($);
sub applyPatch($$;$);
sub isDirectoryEmptyForRemoval($);
sub patch($);
sub removeDirectoriesIfNeeded();
+sub setChangeLogDate($);
sub svnStatus($);
+# Project time zone for Cupertino, CA, US
+my $changeLogTimeZone = "PST8PDT";
+
my $merge = 0;
my $showHelp = 0;
if (!GetOptions("merge!" => \$merge, "help!" => \$showHelp) || $showHelp) {
# Standard patch, patch tool can handle this.
if (basename($fullPath) eq "ChangeLog") {
my $changeLogDotOrigExisted = -f "${fullPath}.orig";
- applyPatch($patch, $fullPath, ["--fuzz=3"]);
+ applyPatch(setChangeLogDate($patch), $fullPath, ["--fuzz=3"]);
unlink("${fullPath}.orig") if (! $changeLogDotOrigExisted);
} else {
applyPatch($patch, $fullPath);
}
}
+sub setChangeLogDate($)
+{
+ my $patch = shift;
+ my $savedTimeZone = $ENV{'TZ'};
+ # Set TZ temporarily so that localtime() is in that time zone
+ $ENV{'TZ'} = $changeLogTimeZone;
+ my $newDate = strftime("%Y-%m-%d", localtime());
+ if (defined $savedTimeZone) {
+ $ENV{'TZ'} = $savedTimeZone;
+ } else {
+ delete $ENV{'TZ'};
+ }
+ $patch =~ s/(\n\+)\d{4}-[^-]{2}-[^-]{2}( )/$1$newDate$2/;
+ return $patch;
+}
+
sub svnStatus($)
{
my ($fullPath) = @_;
# Paths from Index: lines are used rather than the paths on the patch lines, which
# makes patches generated by "cvs diff" work (increasingly unimportant since we
# use Subversion now).
-# ChangeLog patches use --fuzz=3 to prevent rejects.
+# ChangeLog patches use --fuzz=3 to prevent rejects, and the entry date is reset in
+# the patch before it is applied (svn-apply sets it when applying a patch).
# Handles binary files (requires patches made by svn-create-patch).
#
# Missing features:
use warnings;
use Cwd;
+use Fcntl qw(:DEFAULT :seek);
use File::Basename;
use File::Spec;
use Getopt::Long;
sub revertDirectories();
sub svnStatus($);
sub unapplyPatch($$;$);
+sub unsetChangeLogDate($$);
my $showHelp = 0;
if (!GetOptions("help!" => \$showHelp) || $showHelp) {
# Standard patch, patch tool can handle this.
if (basename($fullPath) eq "ChangeLog") {
my $changeLogDotOrigExisted = -f "${fullPath}.orig";
- unapplyPatch($patch, $fullPath, ["--fuzz=3"]);
+ unapplyPatch(unsetChangeLogDate($fullPath, $patch), $fullPath, ["--fuzz=3"]);
unlink("${fullPath}.orig") if (! $changeLogDotOrigExisted);
} else {
unapplyPatch($patch, $fullPath);
my ($patch, $fullPath, $options) = @_;
$options = [] if (! $options);
my $command = "patch " . join(" ", "-p0", "-R", @{$options});
- open PATCH, "| $command" or die "Failed to patch $fullPath\n";
+ open PATCH, "| $command" or die "Failed to patch $fullPath: $!";
print PATCH $patch;
close PATCH;
}
+
+sub unsetChangeLogDate($$)
+{
+ my $fullPath = shift;
+ my $patch = shift;
+ my $newDate;
+ sysopen(CHANGELOG, $fullPath, O_RDONLY) or die "Failed to open $fullPath: $!";
+ sysseek(CHANGELOG, 0, SEEK_SET);
+ my $byteCount = sysread(CHANGELOG, $newDate, 10);
+ die "Failed reading $fullPath: $!" if !$byteCount || $byteCount != 10;
+ close(CHANGELOG);
+ $patch =~ s/(\n\+)\d{4}-[^-]{2}-[^-]{2}( )/$1$newDate$2/;
+ return $patch;
+}