Sourcesafe API magic

What is wrong with the following code?

IVSSItem item;
IVSSVersions versions = item.get_Versions(0);

for(int versionIndex=0;versionIndex<item.Count;++versionIndex)
{
    IVSSVersion version = versions[versionIndex];
}

The .Count returns the total number of actions on a item including includes labels, rollbacks, and checkins. However, the indexer ONLY gives access to the actual versions of an item. This is strange behaviour as normally you expect that the indexer range is the same as the .Count property.

However, the indexer has a base of 1 instead of 0 (zero) which is the reason to investigate how these interface are actually behaving as I had weird results.

The correct way to only retrieve actual versions is to do this is the following:

// This will iterate through the actual versions
IVSSItem item;
IVSSVersions versions = item.get_Versions(0);
for (int c = item.VersionNumber; c>0; –c)
{
    IVSSVersion version = versions;
}
 

What is done here is to replace the IVSSVersions.Count with IVSSItem.VersionNumber

Retrieving all actions: 

// This will also retrieve labels!!
// First item returned is the latest action performed!
foreach (IVSSVersion v in item.get_Versions(0))
{
    // …
}

 

IVSSVersions versions = item.get_Versions(0); 

for(int versionIndex=0;versionIndex<item.Count;++versionIndex)

{

IVSSVersion version = versions[versionIndex]; 

                 // This will also retrieve labels!!
                // First item returned is the latest action performed!
                foreach (IVSSVersion v in item.get_Versions(0))
                {
                    break;
                }

                // This will iterate through the actual versions
                IVSSVersions versions = item.get_Versions(0);
                for (int c = item.VersionNumber; c > 0; –c)
                {
                    IVSSVersion version = versions;
                }

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta