Changeset 18513 in webkit
- Timestamp:
- Jan 1, 2007 8:13:43 PM (17 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r18469 r18513 1 2007-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 1 18 2006-12-29 Eric Seidel <eric@eseidel.com> 2 19 -
trunk/WebKitTools/Scripts/svn-apply
r15477 r18513 44 44 # the patch to today's date using $changeLogTimeZone. 45 45 # Handles binary files (requires patches made by svn-create-patch). 46 # Handles copied and moved files (requires patches made by svn-create-patch). 46 47 # 47 48 # Missing features: 48 49 # 49 50 # 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). 51 52 # When doing a removal, check that old file matches what's being removed. 52 53 # Notice a patch that's being applied at the "wrong level" and make it work anyway. … … 94 95 95 96 my %checkedDirectories; 97 my %copiedFiles; 96 98 my @patches; 97 99 my %versions; 98 100 101 my $copiedFromPath; 99 102 my $indexPath; 100 103 my $patch; … … 105 108 $indexPath = $1; 106 109 if ($patch) { 107 push @patches, $patch; 110 if (!$copiedFromPath) { 111 push @patches, $patch; 112 } 113 $copiedFromPath = ""; 108 114 $patch = ""; 109 115 } … … 113 119 s/\S+$/$indexPath/ if /^diff/; 114 120 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 } 115 129 if (s/^\+\+\+ \S+/+++ $indexPath/) { 116 130 $indexPath = ""; 117 131 } 118 132 } 119 if (/^--- .+\(revision (\d+)\)$/) {120 $versions{$indexPath} = $1 if( $1 != 0 );121 }122 133 $patch .= $_; 123 134 $patch .= "\n"; 124 135 } 125 136 126 push @patches, $patch if $patch; 137 if ($patch && !$copiedFromPath) { 138 push @patches, $patch; 139 } 127 140 128 141 if ($merge) { … … 131 144 system "svn", "update", "-r", $versions{$file}, $file; 132 145 } 146 } 147 148 # Handle copied and moved files first since moved files may have their source deleted before the move. 149 for my $file (keys %copiedFiles) { 150 addDirectoriesIfNeeded(dirname($file)); 151 system "svn", "copy", $copiedFiles{$file}, $file; 133 152 } 134 153 -
trunk/WebKitTools/Scripts/svn-create-patch
r15393 r18513 35 35 # Handles binary files (encoded as a base64 chunk of text). 36 36 # Sorts the diffs alphabetically by text files, then binary files. 37 # Handles copied and moved files. 37 38 # 38 39 # Missing features: 39 40 # 40 # Handle moved files.41 # Handle copied and moved directories. 41 42 42 43 use strict; … … 54 55 55 56 sub canonicalizePath($); 57 sub findMimeType($); 58 sub findModificationType($); 59 sub findSourceFileAndRevision($); 56 60 sub fixChangeLogPatch($); 57 sub generateDiff($ );61 sub generateDiff($$$); 58 62 sub generateFileList($\%\%); 63 sub isBinaryMimeType($); 64 sub manufacturePatchForAdditionWithHistory($$); 59 65 sub numericcmp($$); 60 66 sub outputBinaryContent($); … … 80 86 # Generate the diff for text files, then binary files, for easy reviewing 81 87 for my $file (sort pathcmp keys %textFiles) { 82 generateDiff($file );88 generateDiff($file, $textFiles{$file}, 0); 83 89 } 84 90 for my $file (sort pathcmp keys %binaryFiles) { 85 generateDiff($file );91 generateDiff($file, $binaryFiles{$file}, 1); 86 92 } 87 93 … … 106 112 } 107 113 return ($#dirs >= 0) ? File::Spec->catdir(@dirs) : "."; 114 } 115 116 sub 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 126 sub 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 140 sub 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); 108 164 } 109 165 … … 159 215 } 160 216 161 sub generateDiff($) 162 { 163 my ($file) = @_; 164 my $errors = ""; 165 my $isBinary; 217 sub generateDiff($$$) 218 { 219 my ($file, $modificationType, $isBinary) = @_; 166 220 my $patch; 221 if ($modificationType eq "additionWithHistory") { 222 manufacturePatchForAdditionWithHistory($file, $isBinary); 223 } 167 224 open DIFF, "svn diff --diff-cmd diff -x -uNp '$file' |" or die; 168 225 while (<DIFF>) { 169 $isBinary = 1 if (/^Cannot display: file marked as a binary type\.$/);170 226 $patch .= $_; 171 227 } 172 228 close DIFF; 173 229 $patch = fixChangeLogPatch($patch) if basename($file) eq "ChangeLog"; 174 print $patch ;230 print $patch if $patch; 175 231 if ($isBinary) { 176 print "\n" if $patch =~ m/\n\S+$/m;232 print "\n" if ($patch && $patch =~ m/\n\S+$/m); 177 233 outputBinaryContent($file); 178 234 } 179 print STDERR $errors;180 235 } 181 236 182 237 sub generateFileList($\%\%) 183 238 { 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 } 210 252 } else { 211 $textFiles->{$indexPath} = 1; 212 } 253 print STDERR $line, "\n"; 254 } 255 } 256 close STAT; 257 } 258 259 sub 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 267 sub 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`; 213 281 } 214 282 } -
trunk/WebKitTools/Scripts/svn-unapply
r15477 r18513 41 41 # the patch before it is applied (svn-apply sets it when applying a patch). 42 42 # Handles binary files (requires patches made by svn-create-patch). 43 # Handles copied and moved files (requires patches made by svn-create-patch). 43 44 # 44 45 # Missing features: 45 46 # 46 47 # 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). 48 49 # Use version numbers in the patch file and do a 3-way merge. 49 50 # When reversing an addition, check that the file matches what's being removed. … … 77 78 } 78 79 80 my @copiedFiles; 79 81 my %directoriesToCheck; 80 82 83 my $copiedFromPath; 81 84 my $indexPath; 82 85 my $patch; … … 87 90 $indexPath = $1; 88 91 if ($patch) { 89 patch($patch); 92 if ($copiedFromPath) { 93 push @copiedFiles, $patch; 94 } else { 95 patch($patch); 96 } 97 $copiedFromPath = ""; 90 98 $patch = ""; 91 99 } … … 94 102 # Fix paths on diff, ---, and +++ lines to match preceding Index: line. 95 103 s/^--- \S+/--- $indexPath/; 104 if (/^--- .+\(from (\S+):\d+\)$/) { 105 $copiedFromPath = $1; 106 } 96 107 if (s/^\+\+\+ \S+/+++ $indexPath/) { 97 108 $indexPath = ""; … … 101 112 $patch .= "\n"; 102 113 } 103 patch($patch); 114 115 if ($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 124 for $patch (@copiedFiles) { 125 patch($patch); 126 } 104 127 105 128 revertDirectories(); … … 181 204 my $isBinary = 0; 182 205 183 $addition = 1 if $patch =~ /\n--- .+\(revision 0\)\n/;206 $addition = 1 if ($patch =~ /\n--- .+\(revision 0\)\n/ || $patch =~ /\n@@ -0,0 .* @@/); 184 207 $deletion = 1 if $patch =~ /\n@@ .* \+0,0 @@/; 185 208 $isBinary = 1 if $patch =~ /\nCannot display: file marked as a binary type\./;
Note: See TracChangeset
for help on using the changeset viewer.