diff options
Diffstat (limited to 'WebKitTools/Scripts/svn-apply')
-rwxr-xr-x | WebKitTools/Scripts/svn-apply | 125 |
1 files changed, 12 insertions, 113 deletions
diff --git a/WebKitTools/Scripts/svn-apply b/WebKitTools/Scripts/svn-apply index 19c8c56..7d14e3a 100755 --- a/WebKitTools/Scripts/svn-apply +++ b/WebKitTools/Scripts/svn-apply @@ -74,15 +74,12 @@ use VCSUtils; sub addDirectoriesIfNeeded($); sub applyPatch($$;$); sub checksum($); -sub fixChangeLogPatch($); -sub gitdiff2svndiff($); sub handleBinaryChange($$); sub isDirectoryEmptyForRemoval($); sub patch($); sub removeDirectoriesIfNeeded(); sub setChangeLogDateAndReviewer($$); sub removeEOL($); -sub svnStatus($); # These should be replaced by an scm class/module: sub scmKnowsOfFile($); @@ -178,8 +175,9 @@ if ($merge) { die "--merge is currently only supported for SVN" unless isSVN(); # How do we handle Git patches applied to an SVN checkout here? for my $file (sort keys %versions) { - print "Getting version $versions{$file} of $file\n"; - system "svn", "update", "-r", $versions{$file}, $file; + my $version = $versions{$file}; + print "Getting version $version of $file\n"; + system("svn", "update", "-r", $version, $file) == 0 or die "Failed to run svn update -r $version $file."; } } @@ -258,74 +256,6 @@ sub checksum($) return $checksum; } -sub fixChangeLogPatch($) -{ - my $patch = shift; - my $contextLineCount = 3; - - return $patch if $patch !~ /\n@@ -1,(\d+) \+1,(\d+) @@\r?\n( .*\r?\n)+(\+.*\r?\n)+( .*\r?\n){$contextLineCount}$/m; - my ($oldLineCount, $newLineCount) = ($1, $2); - return $patch if $oldLineCount <= $contextLineCount; - - # The diff(1) command is greedy when matching lines, so a new ChangeLog entry will - # have lines of context at the top of a patch when the existing entry has the same - # date and author as the new entry. This nifty loop alters a ChangeLog patch so - # that the added lines ("+") in the patch always start at the beginning of the - # patch and there are no initial lines of context. - my $newPatch; - my $lineCountInState = 0; - my $oldContentLineCountReduction = $oldLineCount - $contextLineCount; - my $newContentLineCountWithoutContext = $newLineCount - $oldLineCount - $oldContentLineCountReduction; - my ($stateHeader, $statePreContext, $stateNewChanges, $statePostContext) = (1..4); - my $state = $stateHeader; - foreach my $line (split(/\n/, $patch)) { - $lineCountInState++; - if ($state == $stateHeader && $line =~ /^@@ -1,$oldLineCount \+1,$newLineCount @\@$/) { - $line = "@@ -1,$contextLineCount +1," . ($newLineCount - $oldContentLineCountReduction) . " @@"; - $lineCountInState = 0; - $state = $statePreContext; - } elsif ($state == $statePreContext && substr($line, 0, 1) eq " ") { - $line = "+" . substr($line, 1); - if ($lineCountInState == $oldContentLineCountReduction) { - $lineCountInState = 0; - $state = $stateNewChanges; - } - } elsif ($state == $stateNewChanges && substr($line, 0, 1) eq "+") { - # No changes to these lines - if ($lineCountInState == $newContentLineCountWithoutContext) { - $lineCountInState = 0; - $state = $statePostContext; - } - } elsif ($state == $statePostContext) { - if (substr($line, 0, 1) eq "+" && $lineCountInState <= $oldContentLineCountReduction) { - $line = " " . substr($line, 1); - } elsif ($lineCountInState > $contextLineCount && substr($line, 0, 1) eq " ") { - next; # Discard - } - } - $newPatch .= $line . "\n"; - } - - return $newPatch; -} - -sub gitdiff2svndiff($) -{ - $_ = shift @_; - if (m#^diff --git a/(.+) b/(.+)#) { - return "Index: $1"; - } elsif (m/^new file.*/) { - return ""; - } elsif (m#^index [0-9a-f]{7}\.\.[0-9a-f]{7} [0-9]{6}#) { - return "==================================================================="; - } elsif (m#^--- a/(.+)#) { - return "--- $1"; - } elsif (m#^\+\+\+ b/(.+)#) { - return "+++ $1"; - } - return $_; -} - sub handleBinaryChange($$) { my ($fullPath, $contents) = @_; @@ -334,7 +264,7 @@ sub handleBinaryChange($$) # The last line is allowed to have up to two '=' characters at the end (to signify padding). if ($contents =~ m#((\n[A-Za-z0-9+/]{76})*\n[A-Za-z0-9+/]{2,74}?[A-Za-z0-9+/=]{2}\n)#) { # Addition or Modification - open FILE, ">", $fullPath or die; + open FILE, ">", $fullPath or die "Failed to open $fullPath."; print FILE decode_base64($1); close FILE; if (!scmKnowsOfFile($fullPath)) { @@ -373,6 +303,7 @@ sub patch($) unless ($patch =~ m|^Index: ([^\r\n]+)|) { my $separator = '-' x 67; warn "Failed to find 'Index:' in:\n$separator\n$patch\n$separator\n"; + die unless $force; return; } my $fullPath = $1; @@ -413,7 +344,7 @@ sub patch($) unlink("$fullPath.orig") if -e "$fullPath.orig" && checksum($fullPath) eq checksum("$fullPath.orig"); scmAdd($fullPath); # What is this for? - system "svn", "stat", "$fullPath.orig" if isSVN() && -e "$fullPath.orig"; + system("svn", "stat", "$fullPath.orig") if isSVN() && -e "$fullPath.orig"; } } } @@ -455,38 +386,6 @@ sub removeEOL($) return $line; } -sub svnStatus($) -{ - my ($fullPath) = @_; - my $svnStatus; - open SVN, "svn status --non-interactive --non-recursive '$fullPath' |" or die; - if (-d $fullPath) { - # When running "svn stat" on a directory, we can't assume that only one - # status will be returned (since any files with a status below the - # directory will be returned), and we can't assume that the directory will - # be first (since any files with unknown status will be listed first). - my $normalizedFullPath = File::Spec->catdir(File::Spec->splitdir($fullPath)); - while (<SVN>) { - # Input may use a different EOL sequence than $/, so avoid chomp. - $_ = removeEOL($_); - my $normalizedStatPath = File::Spec->catdir(File::Spec->splitdir(substr($_, 7))); - if ($normalizedFullPath eq $normalizedStatPath) { - $svnStatus = "$_\n"; - last; - } - } - # Read the rest of the svn command output to avoid a broken pipe warning. - local $/ = undef; - <SVN>; - } - else { - # Files will have only one status returned. - $svnStatus = removeEOL(<SVN>) . "\n"; - } - close SVN; - return $svnStatus; -} - # This could be made into a more general "status" call, except svn and git # have different ideas about "moving" files which might get confusing. sub scmWillDeleteFile($) @@ -524,10 +423,10 @@ sub scmCopy($$) { my ($source, $destination) = @_; if (isSVN()) { - system "svn", "copy", $source, $destination; + system("svn", "copy", $source, $destination) == 0 or die "Failed to svn copy $source $destination."; } elsif (isGit()) { - system "cp", $source, $destination; - system "git", "add", $destination; + system("cp", $source, $destination) == 0 or die "Failed to copy $source $destination."; + system("git", "add", $destination) == 0 or die "Failed to git add $destination."; } } @@ -535,9 +434,9 @@ sub scmAdd($) { my ($path) = @_; if (isSVN()) { - system "svn", "add", $path; + system("svn", "add", $path) == 0 or die "Failed to svn add $path."; } elsif (isGit()) { - system "git", "add", $path; + system("git", "add", $path) == 0 or die "Failed to git add $path."; } } @@ -555,6 +454,6 @@ sub scmRemove($) close SVN; print $svnOutput if $svnOutput; } elsif (isGit()) { - system "git", "rm", "--force", $path; + system("git", "rm", "--force", $path) == 0 or die "Failed to git rm --force $path."; } } |