OLD | NEW |
1 # Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
reserved. | 1 # Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
reserved. |
2 # Copyright (C) 2009, 2010 Chris Jerdonek (chris.jerdonek@gmail.com) | 2 # Copyright (C) 2009, 2010 Chris Jerdonek (chris.jerdonek@gmail.com) |
3 # Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved. | 3 # Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved. |
4 # Copyright (C) 2012 Daniel Bates (dbates@intudata.com) | 4 # Copyright (C) 2012 Daniel Bates (dbates@intudata.com) |
5 # | 5 # |
6 # Redistribution and use in source and binary forms, with or without | 6 # Redistribution and use in source and binary forms, with or without |
7 # modification, are permitted provided that the following conditions | 7 # modification, are permitted provided that the following conditions |
8 # are met: | 8 # are met: |
9 # | 9 # |
10 # 1. Redistributions of source code must retain the above copyright | 10 # 1. Redistributions of source code must retain the above copyright |
11 # notice, this list of conditions and the following disclaimer. | 11 # notice, this list of conditions and the following disclaimer. |
12 # 2. Redistributions in binary form must reproduce the above copyright | 12 # 2. Redistributions in binary form must reproduce the above copyright |
13 # notice, this list of conditions and the following disclaimer in the | 13 # notice, this list of conditions and the following disclaimer in the |
14 # documentation and/or other materials provided with the distribution. | 14 # documentation and/or other materials provided with the distribution. |
15 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 15 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
16 # its contributors may be used to endorse or promote products derived | 16 # its contributors may be used to endorse or promote products derived |
17 # from this software without specific prior written permission. | 17 # from this software without specific prior written permission. |
18 # | 18 # |
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 { | 449 { |
450 my ($colors, $string) = @_; | 450 my ($colors, $string) = @_; |
451 | 451 |
452 if (-t STDOUT) { | 452 if (-t STDOUT) { |
453 return colored([$colors], $string); | 453 return colored([$colors], $string); |
454 } else { | 454 } else { |
455 return $string; | 455 return $string; |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 sub adjustPathForRecentRenamings($) | 459 sub adjustPathForRecentRenamings($) |
460 { | 460 { |
461 my ($fullPath) = @_; | 461 my ($fullPath) = @_; |
462 | 462 |
463 $fullPath =~ s|WebCore/webaudio|WebCore/Modules/webaudio|g; | 463 $fullPath =~ s|WebCore/webaudio|WebCore/Modules/webaudio|g; |
464 $fullPath =~ s|JavaScriptCore/wtf|WTF/wtf|g; | 464 $fullPath =~ s|JavaScriptCore/wtf|WTF/wtf|g; |
465 $fullPath =~ s|test_expectations.txt|TestExpectations|g; | 465 $fullPath =~ s|test_expectations.txt|TestExpectations|g; |
466 | 466 |
467 return $fullPath; | 467 return $fullPath; |
468 } | 468 } |
469 | 469 |
470 sub canonicalizePath($) | 470 sub canonicalizePath($) |
471 { | 471 { |
472 my ($file) = @_; | 472 my ($file) = @_; |
473 | 473 |
474 # Remove extra slashes and '.' directories in path | 474 # Remove extra slashes and '.' directories in path |
475 $file = File::Spec->canonpath($file); | 475 $file = File::Spec->canonpath($file); |
476 | 476 |
477 # Remove '..' directories in path | 477 # Remove '..' directories in path |
478 my @dirs = (); | 478 my @dirs = (); |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 # Notice, we keep processing until we hit end-of-file or some | 1170 # Notice, we keep processing until we hit end-of-file or some |
1171 # line that does not resemble $svnPropertyStartRegEx, such as | 1171 # line that does not resemble $svnPropertyStartRegEx, such as |
1172 # the empty line that precedes the start of the binary contents | 1172 # the empty line that precedes the start of the binary contents |
1173 # of a patch, or the start of the next diff (e.g. "Index:"). | 1173 # of a patch, or the start of the next diff (e.g. "Index:"). |
1174 my $propertyHashRef; | 1174 my $propertyHashRef; |
1175 while (defined($_) && /$svnPropertyStartRegEx/) { | 1175 while (defined($_) && /$svnPropertyStartRegEx/) { |
1176 ($propertyHashRef, $_) = parseSvnProperty($fileHandle, $_); | 1176 ($propertyHashRef, $_) = parseSvnProperty($fileHandle, $_); |
1177 if ($propertyHashRef->{name} eq "svn:executable") { | 1177 if ($propertyHashRef->{name} eq "svn:executable") { |
1178 # Notice, for SVN properties, propertyChangeDelta is always non-zero | 1178 # Notice, for SVN properties, propertyChangeDelta is always non-zero |
1179 # because a property can only be added or removed. | 1179 # because a property can only be added or removed. |
1180 $footer{executableBitDelta} = $propertyHashRef->{propertyChangeDelta
}; | 1180 $footer{executableBitDelta} = $propertyHashRef->{propertyChangeDelta
}; |
1181 } | 1181 } |
1182 } | 1182 } |
1183 | 1183 |
1184 return(\%footer, $_); | 1184 return(\%footer, $_); |
1185 } | 1185 } |
1186 | 1186 |
1187 # Parse the next SVN property from the given file handle, and advance the handle
so the last | 1187 # Parse the next SVN property from the given file handle, and advance the handle
so the last |
1188 # line read is the first line after the property. | 1188 # line read is the first line after the property. |
1189 # | 1189 # |
1190 # This subroutine dies if the first line is not a valid start of an SVN property
, | 1190 # This subroutine dies if the first line is not a valid start of an SVN property
, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 # this subroutine because the diff(1) command is greedy when matching | 1509 # this subroutine because the diff(1) command is greedy when matching |
1510 # lines. A new ChangeLog entry with the same date and author as the | 1510 # lines. A new ChangeLog entry with the same date and author as the |
1511 # previous will match and cause the diff to have lines of starting | 1511 # previous will match and cause the diff to have lines of starting |
1512 # context. | 1512 # context. |
1513 # | 1513 # |
1514 # This subroutine has unit tests in VCSUtils_unittest.pl. | 1514 # This subroutine has unit tests in VCSUtils_unittest.pl. |
1515 # | 1515 # |
1516 # Returns $changeLogHashRef: | 1516 # Returns $changeLogHashRef: |
1517 # $changeLogHashRef: a hash reference representing a change log patch. | 1517 # $changeLogHashRef: a hash reference representing a change log patch. |
1518 # patch: a ChangeLog patch equivalent to the given one, but with the | 1518 # patch: a ChangeLog patch equivalent to the given one, but with the |
1519 # newest ChangeLog entry inserted at the top of the file, if possible
. | 1519 # newest ChangeLog entry inserted at the top of the file, if possible
. |
1520 sub fixChangeLogPatch($) | 1520 sub fixChangeLogPatch($) |
1521 { | 1521 { |
1522 my $patch = shift; # $patch will only contain patch fragments for ChangeLog. | 1522 my $patch = shift; # $patch will only contain patch fragments for ChangeLog. |
1523 | 1523 |
1524 $patch =~ s|test_expectations.txt:|TestExpectations:|g; | 1524 $patch =~ s|test_expectations.txt:|TestExpectations:|g; |
1525 | 1525 |
1526 $patch =~ /(\r?\n)/; | 1526 $patch =~ /(\r?\n)/; |
1527 my $lineEnding = $1; | 1527 my $lineEnding = $1; |
1528 my @lines = split(/$lineEnding/, $patch); | 1528 my @lines = split(/$lineEnding/, $patch); |
1529 | 1529 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 # This subroutine has unit tests in VCSUtils_unittest.pl. | 1653 # This subroutine has unit tests in VCSUtils_unittest.pl. |
1654 sub generatePatchCommand($) | 1654 sub generatePatchCommand($) |
1655 { | 1655 { |
1656 my ($passedArgsHashRef) = @_; | 1656 my ($passedArgsHashRef) = @_; |
1657 | 1657 |
1658 my $argsHashRef = { # Defaults | 1658 my $argsHashRef = { # Defaults |
1659 ensureForce => 0, | 1659 ensureForce => 0, |
1660 shouldReverse => 0, | 1660 shouldReverse => 0, |
1661 options => [] | 1661 options => [] |
1662 }; | 1662 }; |
1663 | 1663 |
1664 # Merges hash references. It's okay here if passed hash reference is undefin
ed. | 1664 # Merges hash references. It's okay here if passed hash reference is undefin
ed. |
1665 @{$argsHashRef}{keys %{$passedArgsHashRef}} = values %{$passedArgsHashRef}; | 1665 @{$argsHashRef}{keys %{$passedArgsHashRef}} = values %{$passedArgsHashRef}; |
1666 | 1666 |
1667 my $ensureForce = $argsHashRef->{ensureForce}; | 1667 my $ensureForce = $argsHashRef->{ensureForce}; |
1668 my $shouldReverse = $argsHashRef->{shouldReverse}; | 1668 my $shouldReverse = $argsHashRef->{shouldReverse}; |
1669 my $options = $argsHashRef->{options}; | 1669 my $options = $argsHashRef->{options}; |
1670 | 1670 |
1671 if (! $options) { | 1671 if (! $options) { |
1672 $options = []; | 1672 $options = []; |
1673 } else { | 1673 } else { |
1674 $options = [@{$options}]; # Copy to avoid side effects. | 1674 $options = [@{$options}]; # Copy to avoid side effects. |
1675 } | 1675 } |
1676 | 1676 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 | 1982 |
1983 die "$fullPath: unexpected size of the first chunk (expected $binaryChunkExp
ectedSize but was $binaryChunkActualSize" if ($binaryChunkType eq "literal" and
$binaryChunkExpectedSize != $binaryChunkActualSize); | 1983 die "$fullPath: unexpected size of the first chunk (expected $binaryChunkExp
ectedSize but was $binaryChunkActualSize" if ($binaryChunkType eq "literal" and
$binaryChunkExpectedSize != $binaryChunkActualSize); |
1984 die "$fullPath: unexpected size of the second chunk (expected $reverseBinary
ChunkExpectedSize but was $reverseBinaryChunkActualSize" if ($reverseBinaryChunk
Type eq "literal" and $reverseBinaryChunkExpectedSize != $reverseBinaryChunkActu
alSize); | 1984 die "$fullPath: unexpected size of the second chunk (expected $reverseBinary
ChunkExpectedSize but was $reverseBinaryChunkActualSize" if ($reverseBinaryChunk
Type eq "literal" and $reverseBinaryChunkExpectedSize != $reverseBinaryChunkActu
alSize); |
1985 | 1985 |
1986 return ($binaryChunkType, $binaryChunk, $reverseBinaryChunkType, $reverseBin
aryChunk); | 1986 return ($binaryChunkType, $binaryChunk, $reverseBinaryChunkType, $reverseBin
aryChunk); |
1987 } | 1987 } |
1988 | 1988 |
1989 sub readByte($$) | 1989 sub readByte($$) |
1990 { | 1990 { |
1991 my ($data, $location) = @_; | 1991 my ($data, $location) = @_; |
1992 | 1992 |
1993 # Return the byte at $location in $data as a numeric value. | 1993 # Return the byte at $location in $data as a numeric value. |
1994 return ord(substr($data, $location, 1)); | 1994 return ord(substr($data, $location, 1)); |
1995 } | 1995 } |
1996 | 1996 |
1997 # The git binary delta format is undocumented, except in code: | 1997 # The git binary delta format is undocumented, except in code: |
1998 # - https://github.com/git/git/blob/master/delta.h:get_delta_hdr_size is the sou
rce | 1998 # - https://github.com/git/git/blob/master/delta.h:get_delta_hdr_size is the sou
rce |
1999 # of the algorithm in decodeGitBinaryPatchDeltaSize. | 1999 # of the algorithm in decodeGitBinaryPatchDeltaSize. |
2000 # - https://github.com/git/git/blob/master/patch-delta.c:patch_delta is the sour
ce | 2000 # - https://github.com/git/git/blob/master/patch-delta.c:patch_delta is the sour
ce |
2001 # of the algorithm in applyGitBinaryPatchDelta. | 2001 # of the algorithm in applyGitBinaryPatchDelta. |
2002 sub decodeGitBinaryPatchDeltaSize($) | 2002 sub decodeGitBinaryPatchDeltaSize($) |
2003 { | 2003 { |
2004 my ($binaryChunk) = @_; | 2004 my ($binaryChunk) = @_; |
2005 | 2005 |
2006 # Source and destination buffer sizes are stored in 7-bit chunks at the | 2006 # Source and destination buffer sizes are stored in 7-bit chunks at the |
2007 # start of the binary delta patch data. The highest bit in each byte | 2007 # start of the binary delta patch data. The highest bit in each byte |
2008 # except the last is set; the remaining 7 bits provide the next | 2008 # except the last is set; the remaining 7 bits provide the next |
2009 # chunk of the size. The chunks are stored in ascending significance | 2009 # chunk of the size. The chunks are stored in ascending significance |
2010 # order. | 2010 # order. |
2011 my $cmd; | 2011 my $cmd; |
2012 my $size = 0; | 2012 my $size = 0; |
2013 my $shift = 0; | 2013 my $shift = 0; |
2014 for (my $i = 0; $i < length($binaryChunk);) { | 2014 for (my $i = 0; $i < length($binaryChunk);) { |
2015 $cmd = readByte($binaryChunk, $i++); | 2015 $cmd = readByte($binaryChunk, $i++); |
2016 $size |= ($cmd & 0x7f) << $shift; | 2016 $size |= ($cmd & 0x7f) << $shift; |
2017 $shift += 7; | 2017 $shift += 7; |
2018 if (!($cmd & 0x80)) { | 2018 if (!($cmd & 0x80)) { |
2019 return ($size, $i); | 2019 return ($size, $i); |
2020 } | 2020 } |
2021 } | 2021 } |
2022 } | 2022 } |
2023 | 2023 |
2024 sub applyGitBinaryPatchDelta($$) | 2024 sub applyGitBinaryPatchDelta($$) |
2025 { | 2025 { |
2026 my ($binaryChunk, $originalContents) = @_; | 2026 my ($binaryChunk, $originalContents) = @_; |
2027 | 2027 |
2028 # Git delta format consists of two headers indicating source buffer size | 2028 # Git delta format consists of two headers indicating source buffer size |
2029 # and result size, then a series of commands. Each command is either | 2029 # and result size, then a series of commands. Each command is either |
2030 # a copy-from-old-version (the 0x80 bit is set) or a copy-from-delta | 2030 # a copy-from-old-version (the 0x80 bit is set) or a copy-from-delta |
2031 # command. Commands are applied sequentially to generate the result. | 2031 # command. Commands are applied sequentially to generate the result. |
2032 # | 2032 # |
2033 # A copy-from-old-version command encodes an offset and size to copy | 2033 # A copy-from-old-version command encodes an offset and size to copy |
2034 # from in subsequent bits, while a copy-from-delta command consists only | 2034 # from in subsequent bits, while a copy-from-delta command consists only |
2035 # of the number of bytes to copy from the delta. | 2035 # of the number of bytes to copy from the delta. |
2036 | 2036 |
2037 # We don't use these values, but we need to know how big they are so that | 2037 # We don't use these values, but we need to know how big they are so that |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2146 @result = split(/[\r\n]+/, $diffOutput); | 2146 @result = split(/[\r\n]+/, $diffOutput); |
2147 } | 2147 } |
2148 | 2148 |
2149 chdir $cwd; | 2149 chdir $cwd; |
2150 | 2150 |
2151 return @result; | 2151 return @result; |
2152 } | 2152 } |
2153 | 2153 |
2154 | 2154 |
2155 1; | 2155 1; |
OLD | NEW |