Page 1 of 1
Equivalent of VSSItem.IsDifferent
Posted: Sun May 03, 2009 2:40 pm
by stanyork
I found ServerOperations.ProcessCommandDiff - but this seems to invoke the UI tool to display differences. A closer match would be a function that allows me to determine if the ProcessCommandCheckIn() method will use the "UnchangedHandler"
Yes, I'm sure your "is different" determination is far fancier and rule driven and all -- but when push comes to shove, ProcessCommandCheckin() decides wheter or not to treat the file as Unchanged.
The old VSS API's VSSItem object included an IsDifferent() function that compared the local working copy to the specific history or current repository version of the file to which the VSSItem points. This allowed our build code to determine if a get latest was needed and the version number of the local file on the hard drive before the get latest.
Anything similar?
Re: Equivalent of VSSItem.IsDifferent
Posted: Sun May 03, 2009 7:14 pm
by shannon
You'll need a VaultClientFile object to do this (use the methods in RepositoryUtil to find it) and also the WorkingFolder for that file...get it with ServerOperations.client.ClientInstance.GetWorkingFolder(VaultClientFile). Then you can use these methods, using your WorkingFolder object:
wf.IsModified(VaultClientFile) (beware this will return true if the file doesn't exist)
wf.GetDisplayVersion(VaultClientFile)
Let me know if that isn't quite what you're looking for.
Re: Equivalent of VSSItem.IsDifferent
Posted: Mon May 04, 2009 8:45 am
by stanyork
This was very, very helpful -- but
Does this only compare the current local copy to the latest revision -- or can I vary the version comparison by first setting
vcf.Version = history-versionnumber
and then
wf.IsModified(vcf)
Re: Equivalent of VSSItem.IsDifferent
Posted: Mon May 04, 2009 8:53 am
by shannon
It's going to tell you if it was modified since the last get, whether that get was a historical version or the latest version.
Re: Equivalent of VSSItem.IsDifferent
Posted: Mon May 04, 2009 12:05 pm
by stanyork
So, what is the difference between wf.IsModified() and wf.IsReallyModified () ?
Re: Equivalent of VSSItem.IsDifferent
Posted: Mon May 04, 2009 12:11 pm
by shannon
IsModified(vcf) does a comparison of the file's last modified date to the get date - unless the detect modified files with CRCs is on, then it does a CRC check.
IsModified(vcf, true, true) will force a CRC check.
IsReallyModified(vcf) does a byte by byte comparison.
Re: Equivalent of VSSItem.IsDifferent
Posted: Wed May 06, 2009 9:46 am
by stanyork
Good news - I have our Build engine working using your API.
Bad news - I could not get your wcf.IsModified to return an honest answer in any flavor
I have pasted a bunch of code below. My IsDifferent fucntion is part of a class that encapsulates VaultClientFile and VaultClientFolder and helped me reduce the amount of external code changes. You'll see that in my IsDifferent(), I ended up "Getting" a copy of the file from Vault to a temp (non-working) folder and calculating an MD5 hash and comparing it to the MD5 hash I also calculate on the copy that *is* in the working folder. This logic works very well -- but clearly adds some overhead I'd prefer to avoid.
I remain surprized that the IsModified and IsReallyModified functions do not work. You'll see I have code that runs three variations of your functions and store the results to write a trace message along with the md5 result. Time and again the output is
Vault
UserList.ascx.vb Modified Check
True, CRC
True, RM
True; MD5
False
And the correct answer is FALSE -- the working file is a non-modified copy of the current file in the repository.
Code: Select all
Public Function IsDifferent(ByVal thanFN As String) As Boolean
Dim testm1 As Boolean
Dim testm3 As Boolean
Dim testrm As Boolean
Dim ReliableMD5 As Boolean
If ActiveVersion = LatestVersion Then
'notesay: pretty much everything returns TRUE: Return SCFolder.IsModified(_vaultClientFile [,true,true])
testm1 = SCFolder.IsModified(_vaultClientFile)
testm3 = SCFolder.IsModified(_vaultClientFile, True, True)
testrm = SCFolder.IsReallyModified(_vaultClientFile)
End If
If _WorkPath Is Nothing OrElse _WorkPath.Length = 0 Then _WorkPath = System.IO.Path.GetTempPath
Dim tempfn As String = UtilityToolkit.Strings.AddBS(_WorkPath) & "tempfile.vss"
Dim scHash As String
Dim lfHash As String
Try
GetTempCopy(tempfn) ' gets a local, non-working copy of the "ActiveVersion" of this file
scHash = UtilityToolkit.IO.HashForFile(tempfn)
lfHash = UtilityToolkit.IO.HashForFile(thanFN)
If ActiveVersion = LatestVersion Then Debug.WriteLine(String.Format("Vault {0} Modified Check {1}, CRC {2}, RM {3}; MD5 {4}", Name, testm1, testm3, testrm, ReliableMD5))
Return (scHash <> lfHash)
Finally
If System.IO.File.Exists(tempfn) Then System.IO.File.Delete(tempfn)
End Try
Return True
End Function
Public Function IsDifferent() As Boolean
Return IsDifferent(LocalSpec)
End Function
Public Function GetTempCopy(ByVal toLocalFn As String) As Boolean
Dim options As New VaultClientIntegrationLib.GetOptions
If System.IO.File.Exists(toLocalFn) Then System.IO.File.Delete(toLocalFn)
options.MakeWritable = MakeWritableType.MakeAllFilesWritable
options.Recursive = False
options.SetFileTime = SetFileTimeType.Modification
options.Merge = MergeType.OverwriteWorkingCopy
options.PerformDeletions = PerformDeletionsType.DoNotRemoveWorkingCopy
Dim toLocation As String = System.IO.Path.GetDirectoryName(toLocalFn)
toLocalFn = System.IO.Path.GetFileName(toLocalFn)
If System.IO.File.Exists(toLocation & "\" & vssItem.Name) Then System.IO.File.Delete(toLocation & "\" & vssItem.Name)
Dim scFN As String = me.SCFileSpec
Dim getVersion As Integer = CInt(me.ActiveVersion)
Try
vssItem = Nothing
GetOperations.ProcessCommandGetVersionToLocationOutsideWorkingFolder(scFN, getVersion, options, toLocation)
Me.SelectItem(scFN) ' the need to select after the get is a surprize -- without this the vcf object is corrupt
System.IO.File.Move(toLocation & "\" & vssItem.Name, toLocation & "\" & toLocalFn)
Catch gv As VaultClientOperationsLib.GetLatestVersionFailedException
Debug.WriteLine(gv.Message)
Throw New ApplicationException(String.Format("GetLatestVersionFailedException attempting to Get {0} v{1} to {2}", _
scFN, getVersion, toLocation))
Catch ex As Exception
Debug.WriteLine(ex.Message)
Throw New ApplicationException(String.Format("GetTempCopy caused {3} attempting to Get {0} v{1} to {2}", _
scFN, getVersion, toLocation, ex.ToString))
End Try
Return True
End Function
Public Shared Function HashForStream(ByVal inStream As System.IO.Stream) As String
Dim hashedBytes As [Byte]() = CType(CryptoConfig.CreateFromName("MD5"), HashAlgorithm).ComputeHash(inStream)
Dim hashedText As String = BitConverter.ToString(hashedBytes)
Return hashedText
End Function
Re: Equivalent of VSSItem.IsDifferent
Posted: Wed May 06, 2009 10:19 am
by shannon
When you look at the properties of the file in the gui client, do the local and remote version and date/time match? Does it show a status of current?
Re: Equivalent of VSSItem.IsDifferent
Posted: Wed May 06, 2009 11:00 am
by stanyork
Indeed, the status in the vault client is displayed as "Unknown" -- quite likely because the working folder (D:\SpitfireBuild) is reused for a couple of versions of our product. If the status is None (blank in the UI), then your IsModified can return false.
So, is there some API call I should make after setting the working folder for the root project so that all the working file statuses get updated?
A recursive get latest will not work for my needs because then our build engine fails to rebuild some dependant modules because the recursive get hides the changes.
As an alternative, is there a CRC method (or would you care to share your CRC algorithm) -- because the vcf.FileCRC is available for every version...if I can compute the FileCRC for what I have on disk this would be a terrific alternative.
Re: Equivalent of VSSItem.IsDifferent
Posted: Wed May 06, 2009 11:28 am
by shannon
You can use the VaultLib.FileCRC32 class to compute CRCs.
Re: Equivalent of VSSItem.IsDifferent
Posted: Wed May 06, 2009 5:35 pm
by mmoayyed
I have a question on the topic. The above method pointed out using the WorkingFolder object works, but it compares the file with whatever happens to be in the working directory.
If I remember right, the IsDifferent method of VSSItem allowed the item to be compared with any local file. How is this possible with the Vault API ?
I think this might be possible with DoWorkingFileDiff method. If so, could you please provide a short example of how the parameters are set ?
Thanks.
Re: Equivalent of VSSItem.IsDifferent
Posted: Wed May 06, 2009 5:40 pm
by shannon
DoWorkingFileDiff is going to launch a diff application to compare. You'd have to use calculate the CRC for the local file and compare it with the one from the object.
Re: Equivalent of VSSItem.IsDifferent
Posted: Thu May 07, 2009 10:58 am
by mmoayyed
OK, thanks.
Could you also please elaborate on the return values of the call GetCRC() inside the FileCRC32 class ?
Re: Equivalent of VSSItem.IsDifferent
Posted: Thu May 07, 2009 11:33 am
by shannon
It returns the CRC checksum of the file - like VaultClientFile.FileCRC