Unexpected behavior from Vault API

This forum is now locked, since Gold Support is no longer offered.

Moderator: SourceGear

Posts: 48
Joined: Tue Apr 20, 2004 3:23 pm

Unexpected behavior from Vault API

Post by dking513 » Fri Apr 08, 2005 1:18 pm

I have written a custom client that uses the vault API.
I am finding that setting the version property of a source vault file has unexpected consequences. Let's use the following scenario:

I have a document foo.doc that is currently on version 10.
I want to get a earlier version of this document.
I want to save this prior version to a location other than my working folder.

1. Use OptimisticFindFile to find foo.doc. This returns a VaultClientFile object
2. Set the Version property of this file object to the desired version.
3. Call GetByDisplayVersionToNonWorkingFolder (passing the modified File object) to get the desired version file to the desired location.
4. Exit function. File object has local scope and is cleaned up, the ClientInstance object is global and stays open.

The unexpected consquence:
* The code described above works just fine.
* Now let's say I perform another OptimisticFindFile call to fetch foo.doc again. The VaultClientFile that it returns me STILL has the Version property set to whatever I had set it to previously. This is not what I expected.
*It is easy to add a step in the code to reset the Version back to the original version after I do the get, but I am curious about the design rationale for this. Why does the VaultClientFile object store my previous version value? And where does it store this - is it writing it back to the server? Or storing it in local cache? Why doesn't OptimisticFindFile return a File object with the latest values? There is no .LatestVersion property to compare to the .Version property so this is confusing.

As I said, this was an easy workaround once I realized what was going on. But it has made me realize that perhaps my understanding in this area is lacking, so please feel free to clue me in. I notice that in your command line client (ProcessCommandGetVersion) you perform the same steps I am, but do not ever set the version number back to the original value. Why is this safe in this case?

Dave King

Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear

Post by jeremy_sg » Mon Apr 11, 2005 8:23 am

The thing that the command line client is doing that you are not is

Code: Select all

vcfile = new VaultClientFile(_ci.TreeCache.Repository.Root.FindFileRecursive(strReposItem));
It's creating a new object, as opposed to using the one that is in the tree cache. Any changes to the new object are not updated in the tree cache. You can find out more about the tree cache at http://support.sourcegear.com/viewtopic.php?t=6

Posts: 48
Joined: Tue Apr 20, 2004 3:23 pm


Post by dking513 » Mon Apr 11, 2005 2:49 pm

Thanks. That completely clears it up.