11<# PSScriptInfo
2- .VERSION 1.0.1
2+ .VERSION 1.0.2
33.AUTHOR Roman Kuzmin
44.COPYRIGHT (c) Roman Kuzmin
5- .TAGS Git Diff Compare Merge
5+ .TAGS Git Diff Patch Compare Merge
66.GUID 964fe648-2547-4062-a2ce-6a0756b50223
77.PROJECTURI https://github.com/nightroman/PowerShelf
88.LICENSEURI http://www.apache.org/licenses/LICENSE-2.0
1515. Description
1616 The script is designed for diff and patch files created by git. It expands
1717 the specified diff file into directories "a" and "b" (original and changes)
18- with pieces of files provided by the diff.
18+ with pieces of files stored in the diff.
1919
2020 Then you can use your diff tool of choice in order to compare the
2121 directories "a" and "b", i.e. to visualize the original diff file.
2222
2323 The following diff lines are recognized and processed:
2424
25- | --- a/... | "a/..." | /dev/null ~ file "a"
26- | +++ b/... | "b/..." | /dev/null ~ file "b"
27- | @@... ~ chunk header
28- | ... ~ common line
29- | -... ~ "a" line
30- | +... ~ "b" line
25+ --- a/... | "a/..." | /dev/null ~ file "a"
26+ +++ b/... | "b/..." | /dev/null ~ file "b"
27+ @@... ~ chunk header
28+ ... ~ common line
29+ -... ~ "a" line
30+ +... ~ "b" line
3131
3232 Other lines are ignored.
3333
@@ -58,15 +58,15 @@ $Root = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Root)
5858
5959$RootA = Join-Path $Root a
6060$RootB = Join-Path $Root b
61- if (Test-Path - LiteralPath $RootA ) {throw " The path '$RootA ' exists. Remove it or specify a different root." }
62- if (Test-Path - LiteralPath $RootB ) {throw " The path '$RootB ' exists. Remove it or specify a different root." }
61+ if (Test-Path - LiteralPath $RootA ) {throw " The item '$RootA ' exists. Remove it or specify a different root." }
62+ if (Test-Path - LiteralPath $RootB ) {throw " The item '$RootB ' exists. Remove it or specify a different root." }
6363$null = [System.IO.Directory ]::CreateDirectory($RootA )
6464$null = [System.IO.Directory ]::CreateDirectory($RootB )
6565
6666$fileA = ' '
6767$fileB = ' '
68- $linesA = [System.Collections.Generic.List [string ]]@ ( )
69- $linesB = [System.Collections.Generic.List [string ]]@ ( )
68+ $linesA = [Activator ]::CreateInstance([ System.Collections.Generic.List [string ]])
69+ $linesB = [Activator ]::CreateInstance([ System.Collections.Generic.List [string ]])
7070
7171function Write-A {
7272 if ($fileA ) {
@@ -88,9 +88,10 @@ $regexOctets = [regex]'(\\\d\d\d)+'
8888
8989$decodeOctets = {
9090 $x = $args [0 ].Value
91- $a = [System.Collections.Generic.List [byte ]]@ ()
92- for ($i = 1 ; $i -lt $x.Length ; $i += 4 ) {
93- $a.Add ([byte ][Convert ]::ToInt32($x.Substring ($i , 3 ), 8 ))
91+ $n = $x.Length / 4
92+ $a = [Activator ]::CreateInstance([byte []], $n )
93+ for ($i = 0 ; $i -lt $n ; ++ $i ) {
94+ $a [$i ] = [Convert ]::ToByte($x.Substring ($i * 4 + 1 , 3 ), 8 )
9495 }
9596 [System.Text.Encoding ]::UTF8.GetString($a )
9697}
0 commit comments