Diff script for ZIP files
Daniel Sahlberg via TortoiseSVN-dev <[email protected]> Wed, 11 Sep 2024 01:10:50 -0700 (PDT)
| Newsgroups | gmane.comp.version-control.subversion.tortoisesvn.devel |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_33304_866397636.1726042250993
Content-Type: multipart/alternative;
boundary="----=_Part_33305_65891984.1726042250993"
------=_Part_33305_65891984.1726042250993
Content-Type: text/plain; charset="UTF-8"
Hi,
I've got a usecase where I'm committing ZIP files to the repository. It is
usefull for me to compare the contents of the ZIP file (filenames, date and
time suffice, not contents of the individual files).
I've created a diff script, below, inspired by the existing diff scripts.
Does the code make sense? Can we include it in the standard setup? If the
response is positive, I'll commit it and do the necessary changes to the
installation and default settings.
[[[
'
' TortoiseSVN Diff script for ZIP files
'
' Last commit by:
' $Author: $
' $Date: $
' $Rev: $
'
' Authors:
' Daniel Sahlberg, 2024
'
Set Arguments = WScript.Arguments
If Arguments.Count < 2 Then
MsgBox "Usage: [CScript | WScript] diff-zip.vbs base.zip new.zip",
vbCritical, "Invalid arguments"
WScript.Quit 1
End If
Set ShellApplication = CreateObject("Shell.Application")
Set WScriptShell = CreateObject("WScript.Shell")
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Function ReadZip(pathToZipFile)
Set Folder = ShellApplication.NameSpace(pathToZipFile)
If Folder Is Nothing Then
MsgBox "Can't read " & pathToZipFile, vbCritical, "Invalid zip file"
Else
Set Items = Folder.Items
FileName = FileSystemObject.GetSpecialFolder(2) & "\" &
FileSystemObject.GetTempName()
' 2 = ForWriting
' -1 = Opens the file as Unicode
Set File = FileSystemObject.OpenTextFile(FileName, 2, True, -1)
If File Is Nothing Then
MsgBox("Can't open " & File & " for writing")
Else
File.WriteLine(pathToZipFile)
File.WriteLine("")
MaxLength = 0
For i = 0 To Items.Count-1
If Len(Items.Item(i).Name) > MaxLength Then MaxLength =
Len(Items.Item(i).Name)
Next
MaxLength = MaxLength+1
For i = 0 To Items.Count-1
Set Item = Items.Item(i)
File.WriteLine(Item.Name & String(MaxLength-Len(Item.Name), " ") &
Item.ModifyDate & String(10-Len(Item.Size), " ") & Item.Size)
Next
File.WriteLine("")
File.WriteLine(Items.Count & " items")
File.Close()
ReadZip = FileName
End if
End if
End Function
BaseFile = ReadZip(Arguments(0))
NewFile = ReadZip(Arguments(1))
If BaseFile = "" Or NewFile = "" Then
WScript.Quit 1
End If
WScriptShell.Run """TortoiseMerge.exe"" /readonly /base:""" & BaseFile &
""" /basename:""" & Arguments(0) & """ /mine:""" & NewFile & """
/minename:""" & Arguments(1) & """", 0, True
FileSystemObject.DeleteFile BaseFile
FileSystemObject.DeleteFile NewFile
WScript.Quit 0
]]]
Another option would be to have TortoiseMerge learn to read ZIP files and
generating the directory listing internally, but it seems to be more work
and I don't know if we have a library already that can read ZIP files or if
we'd have to include additional dependencies.
Kind regards,
Daniel
--
You received this message because you are subscribed to the Google Groups "TortoiseSVN-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/tortoisesvn-dev/52fb40fe-89ce-466a-81a8-6aa161a4d88bn%40googlegroups.com.
------=_Part_33305_65891984.1726042250993
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hi,<div><br /></div><div>I've got a usecase where I'm committing ZIP files =
to the repository. It is usefull for me to compare the contents of the ZIP =
file (filenames, date and time suffice, not contents of the individual file=
s).</div><div><br /></div><div>I've created a diff script, below, inspired =
by the existing diff scripts. Does the code make sense? Can we include it i=
n the standard setup? If the response is positive, I'll commit it and do th=
e necessary changes to the installation and default settings.</div><div><br=
/></div><div>[[[</div><div>'<br />' TortoiseSVN Diff script for ZIP files<=
br />'<br />' Last commit by:<br />' $Author: $<br />' $Date: $<br />' $Rev=
: $<br />'<br />' Authors:<br />' Daniel Sahlberg, 2024<br />'<br /><br />S=
et Arguments =3D WScript.Arguments<br />If Arguments.Count < 2 Then<br /=
><span style=3D"white-space: pre;"> </span>MsgBox "Usage: [CScript | WScrip=
t] diff-zip.vbs base.zip new.zip", vbCritical, "Invalid arguments"<br /><sp=
an style=3D"white-space: pre;"> </span>WScript.Quit 1<br />End If<br /><br =
/>Set ShellApplication =3D CreateObject("Shell.Application")<br />Set WScri=
ptShell =3D CreateObject("WScript.Shell")<br />Set FileSystemObject =3D Cre=
ateObject("Scripting.FileSystemObject")<br /><br />Function ReadZip(pathToZ=
ipFile)<br /><span style=3D"white-space: pre;"> </span>Set Folder =3D Shell=
Application.NameSpace(pathToZipFile)<br /><span style=3D"white-space: pre;"=
> </span>If Folder Is Nothing Then<br /><span style=3D"white-space: pre;"> =
</span>MsgBox "Can't read " & pathToZipFile, vbCritical, "Invalid zip =
file"<br /><span style=3D"white-space: pre;"> </span>Else<br /><span style=
=3D"white-space: pre;"> </span>Set Items =3D Folder.Items<br /><span style=
=3D"white-space: pre;"> </span>FileName =3D FileSystemObject.GetSpecialFol=
der(2) & "\" & FileSystemObject.GetTempName()<br /><span style=3D"w=
hite-space: pre;"> </span>' 2 =3D ForWriting<br /><span style=3D"white-spa=
ce: pre;"> </span>' -1 =3D Opens the file as Unicode<br /><span style=3D"w=
hite-space: pre;"> </span>Set File =3D FileSystemObject.OpenTextFile(FileN=
ame, 2, True, -1)<br /><span style=3D"white-space: pre;"> </span>If File I=
s Nothing Then<br /><span style=3D"white-space: pre;"> </span>MsgBox("Can=
't open " & File & " for writing")<br /><span style=3D"white-space:=
pre;"> </span>Else<br /><span style=3D"white-space: pre;"> </span>File.=
WriteLine(pathToZipFile)<br /><span style=3D"white-space: pre;"> </span>F=
ile.WriteLine("")<br /><span style=3D"white-space: pre;"> </span>MaxLengt=
h =3D 0<br /><span style=3D"white-space: pre;"> </span>For i =3D 0 To Ite=
ms.Count-1<br /><span style=3D"white-space: pre;"> </span>If Len(Items.I=
tem(i).Name) > MaxLength Then MaxLength =3D Len(Items.Item(i).Name)<br /=
><span style=3D"white-space: pre;"> </span>Next<br /><span style=3D"white=
-space: pre;"> </span>MaxLength =3D MaxLength+1<br /><span style=3D"white=
-space: pre;"> </span>For i =3D 0 To Items.Count-1<br /><span style=3D"wh=
ite-space: pre;"> </span>Set Item =3D Items.Item(i)<br /><span style=3D"=
white-space: pre;"> </span>File.WriteLine(Item.Name & String(MaxLeng=
th-Len(Item.Name), " ") & Item.ModifyDate & String(10-Len(Item.Size=
), " ") & Item.Size)<br /><span style=3D"white-space: pre;"> </span>N=
ext<br /><span style=3D"white-space: pre;"> </span>File.WriteLine("")<br =
/><span style=3D"white-space: pre;"> </span>File.WriteLine(Items.Count &a=
mp; " items")<br /><span style=3D"white-space: pre;"> </span>File.Close()=
<br /><span style=3D"white-space: pre;"> </span>ReadZip =3D FileName<br /=
><span style=3D"white-space: pre;"> </span>End if<br /><span style=3D"whit=
e-space: pre;"> </span>End if<br />End Function<br /><br />BaseFile =3D Rea=
dZip(Arguments(0))<br />NewFile =3D ReadZip(Arguments(1))<br /><br />If Bas=
eFile =3D "" Or NewFile =3D "" Then<br /><span style=3D"white-space: pre;">=
</span>WScript.Quit 1<br />End If<br /><br />WScriptShell.Run """TortoiseM=
erge.exe"" /readonly /base:""" & BaseFile & """ /basename:""" &=
Arguments(0) & """ /mine:""" & NewFile & """ /minename:""" &am=
p; Arguments(1) & """", 0, True<br /><br />FileSystemObject.DeleteFile =
BaseFile<br />FileSystemObject.DeleteFile NewFile<br /><br />WScript.Quit 0=
<br /></div><div>]]]</div><div><br /></div><div>Another option would be to =
have TortoiseMerge learn to read ZIP files and generating the directory lis=
ting internally, but it seems to be more work and I don't know if we have a=
library already that can read ZIP files or if we'd have to include additio=
nal dependencies.</div><div><br /></div><div>Kind regards,</div><div>Daniel=
</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;TortoiseSVN-dev" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">tor=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/tortoisesvn-dev/52fb40fe-89ce-466a-81a8-6aa161a4d88bn%40googlegr=
oups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/=
d/msgid/tortoisesvn-dev/52fb40fe-89ce-466a-81a8-6aa161a4d88bn%40googlegroup=
s.com</a>.<br />
------=_Part_33305_65891984.1726042250993--
------=_Part_33304_866397636.1726042250993--