Moving/Removing labels

If you are having a problem using Vault, post a message here.

Moderator: SourceGear

Post Reply
Eric Willeke

Moving/Removing labels

Post by Eric Willeke » Fri Oct 29, 2004 2:18 pm

Using the client API I'm attempting to either move a label from one version to another, or remove it entirely so I can add it again.

My code currently looks like one of these two options if you could tell me I'm on the right track or not it would be greatly appreciated.

Code: Select all

            VaultClientFile file = root.FindFileRecursive( filePath );
            file.Version = newVersion;
            
            VaultLabelPromotionItem item = new VaultLabelPromotionItem();
            VaultLabelPromotionItem [] items = new VaultLabelPromotionItem [] {item};

            item.ChangeType = VaultLabelPromotionChangeType.Delete;

            long labelId = GetLabelId( file, label );

            if( labelId != -1 )
            {
                DateTime lastDate = VaultDate.EmptyDate();
                int nIdxFailed = 0;
                string conflict = null;
                Client.PromoteLabelItems( file.FullPath, labelId, label, ref lastDate, items, out nIdxFailed, out conflict );
            }

            VaultLabelResult result = new VaultLabelResult();
            Client.AddLabel( file.FullPath, file.ObjVerID, label, "Adding label", ref result );
========OR===============

Code: Select all

            VaultClientFile file = root.FindFileRecursive( filePath );
            file.Version = newVersion;
            

            long labelId = GetLabelId( file, label );
            if( labelId == -1 )
            {
                VaultLabelResult result = new VaultLabelResult();
                Client.AddLabel( file.FullPath, file.ObjVerID, label, "Adding label", ref result );
                return;
            }

            VaultLabelPromotionItem item = new VaultLabelPromotionItem();
            VaultLabelPromotionItem [] items = new VaultLabelPromotionItem [] {item};

            item.ChangeType = VaultLabelPromotionChangeType.Modify;
            item.ItemName = file.Name;
            item.ItemPath = file.FullPath;
            item.Version = file.Version;
            item.ID = file.ID;

            DateTime lastDate = VaultDate.EmptyDate();
            int nIdxFailed = 0;
            string conflict = null;
            Client.PromoteLabelItems( file.FullPath, labelId, label, ref lastDate, items, out nIdxFailed, out conflict );

Eric Willeke

bump

Post by Eric Willeke » Thu Nov 04, 2004 8:11 am

+ Version = 2.0.6

sterwill
Posts: 256
Joined: Thu Nov 06, 2003 10:01 am
Location: SourceGear

Post by sterwill » Thu Nov 04, 2004 10:04 am

Although both approaches will work, the second one uses the promotion API specifically designed for this kind of thing. Are you having any problems getting your code working?
Shaw Terwilliger
SourceGear LLC
`echo sterwill5sourcegear6com | tr 56 @.`

Eric Willeke

Post by Eric Willeke » Thu Nov 04, 2004 10:58 am

Time for more background :)

Our vault repository is the result of a very recent transition from Rational Clear Case to Vault. One of our goals during the transition was to maintain our version history and labeling structure. I created a script that walked all of the clearcase versions and moved them individually into vault, so we have everything in vault with labels, comments, and versions intact. This all worked fine.

However, now that it's in vault, none of the label promotion works. I suspect it's because we didn't use labels by applying them to the base folder; rather, they were applied individually to each file.

One of our labels is used to track the currently approved file set, and as such the label gets promoted often. In the examples above, neither try is successfully removing the label or changing the associated version. The files don't even show up in the promotion window from the UI even though the folder has the same textual label as the files.

From your comment it seems the code looks correct, but it has no effect (but, no errors are thrown)

Thoughts?

Direct contact at: erwilleke at sep dot com.

sterwill
Posts: 256
Joined: Thu Nov 06, 2003 10:01 am
Location: SourceGear

Post by sterwill » Thu Nov 04, 2004 1:39 pm

Have you checked the return value of PromoteLabelItems? The Vault client API isn't as consistent as it should be with returning useful error codes (often it throws exceptions), but this function does return the server's status code. You can translate the number to a message with code like:

Code: Select all

int returnCode = SomeVaultFunction();

string returnCodeString = VaultConnection.GetSoapExceptionMessage(returnCode);
Shaw Terwilliger
SourceGear LLC
`echo sterwill5sourcegear6com | tr 56 @.`

Post Reply