How to branch a file using API
Moderator: SourceGear
How to branch a file using API
I have a bunch of file which are individually shared and I want to write a C# program to branch them all, but I'm not sure how to do it.
I've tried using ChangeSetItem_CopyBranch but this doesn't seem to work.
Here's my non-working function:
public static void BranchFile(ClientInstance ciUser, VaultClientFile vcFile)
{
if (ciUser.TreeCache.IsShared(vcFile.ID))
{
string[] discoveredPaths;
long labelID = 0;
VaultClientTreeObject vcTreeObject;
long rootID;
if (ciUser.GetByLabel_GetStructure(vcFile.FullPath, "6.2r1", ref labelID, null, out discoveredPaths, out vcTreeObject, out rootID))
{
ChangeSetItemColl csic = new ChangeSetItemColl();
ChangeSetItem_CopyBranch csi = new ChangeSetItem_CopyBranch(DateTime.Now, "", String.Empty, vcFile.FullPath, vcFile.FullPath, vcTreeObject.ObjVerID);
csic.Add(csi);
ciUser.InternalChangeSet_Append(csic);
ciUser.Commit(csic));
}
}
}
Sorry for the poor formating.
Thanks,
Jerry
I've tried using ChangeSetItem_CopyBranch but this doesn't seem to work.
Here's my non-working function:
public static void BranchFile(ClientInstance ciUser, VaultClientFile vcFile)
{
if (ciUser.TreeCache.IsShared(vcFile.ID))
{
string[] discoveredPaths;
long labelID = 0;
VaultClientTreeObject vcTreeObject;
long rootID;
if (ciUser.GetByLabel_GetStructure(vcFile.FullPath, "6.2r1", ref labelID, null, out discoveredPaths, out vcTreeObject, out rootID))
{
ChangeSetItemColl csic = new ChangeSetItemColl();
ChangeSetItem_CopyBranch csi = new ChangeSetItem_CopyBranch(DateTime.Now, "", String.Empty, vcFile.FullPath, vcFile.FullPath, vcTreeObject.ObjVerID);
csic.Add(csi);
ciUser.InternalChangeSet_Append(csic);
ciUser.Commit(csic));
}
}
}
Sorry for the poor formating.
Thanks,
Jerry
Do you want to unshare the files, or to branch them to a different location? If you want to unshare them, you should use the ChangeSetItem_ShareBranch type. I'm not honestly sure if ChangeSetItem_CopyBranch will work on a shared item.
The problem is that the term "branch" is overloaded - it can be both unshare a share, and branch a file/folder to a different location, hence the two different change item types.
Also, I'm not sure what the GetByLabel_GetStructure is trying to accomplish. If you already know the file, it shouldn't be necessary.
If this doesn't help, I'll need more info on the error you are getting.
The problem is that the term "branch" is overloaded - it can be both unshare a share, and branch a file/folder to a different location, hence the two different change item types.
Also, I'm not sure what the GetByLabel_GetStructure is trying to accomplish. If you already know the file, it shouldn't be necessary.
If this doesn't help, I'll need more info on the error you are getting.
Hi Dan,
I guess I'm not sure exactly which operation I need. Let me describe in more detail what I want to accomplish and hopefully that will give you enough information to point me in the right direction.
I have two directories, A and B, and a file in A called foo.cpp. At some point, foo.cpp was shared into directory B, so now there's a A/foo.cpp and a B/foo.cpp. I want to break the connection between them so there's now an A/foo.cpp and a B/foo.cpp, but changes to one will not affect the other.
To me, to "unshare" foo.cpp seems to imply that it will no longer exist in B (the reverse operation of a share), but perhaps, in fact, that is the term for what I am trying to accomplish? In the API help file, it says something like "TODO: explain the difference between ShareBranch and CopyBranch".
About the GetByLabel_GetStructure, oops - that's leftover code from the code I'm reusing, which used to be involved in a Pin operation.
-Jerry
I guess I'm not sure exactly which operation I need. Let me describe in more detail what I want to accomplish and hopefully that will give you enough information to point me in the right direction.
I have two directories, A and B, and a file in A called foo.cpp. At some point, foo.cpp was shared into directory B, so now there's a A/foo.cpp and a B/foo.cpp. I want to break the connection between them so there's now an A/foo.cpp and a B/foo.cpp, but changes to one will not affect the other.
To me, to "unshare" foo.cpp seems to imply that it will no longer exist in B (the reverse operation of a share), but perhaps, in fact, that is the term for what I am trying to accomplish? In the API help file, it says something like "TODO: explain the difference between ShareBranch and CopyBranch".
About the GetByLabel_GetStructure, oops - that's leftover code from the code I'm reusing, which used to be involved in a Pin operation.
-Jerry
Thanks Dan, that did the trick. Now I'm _almost_ there - I just have one problem left. To iterate through all the files, I have this code:
foreach (VaultClientFile vcFile in vcFolder.Files)
{
BranchFile(ciUser, vcFile);
}
After the first ShareBranch however, I get an exception because vcFolder collection has changed so it can't enumerate any more. If this is more of a programming question, I understand, but I figured I'd ask here in case it was something simple (since I'm not that experienced with C#).
-Jerry
foreach (VaultClientFile vcFile in vcFolder.Files)
{
BranchFile(ciUser, vcFile);
}
After the first ShareBranch however, I get an exception because vcFolder collection has changed so it can't enumerate any more. If this is more of a programming question, I understand, but I figured I'd ask here in case it was something simple (since I'm not that experienced with C#).
-Jerry
Hmm. Since the file in the folder is now branched, the folder struct may no longer be valid.
One thing you can do is collect (append) all the share branch commands into a single change set, and then commit them all at the same time. You might want to do this anyway, as it would be quicker to send a bunch of commands at once rather than doing them individually.
One thing you can do is collect (append) all the share branch commands into a single change set, and then commit them all at the same time. You might want to do this anyway, as it would be quicker to send a bunch of commands at once rather than doing them individually.
Dan (or anyone),
The program I made seems to be working as expected. However, one of the other users here has started to have a major problem since I started doing the ShareBranching. I don't know if it is related, or just a coincidence. In the Vault client on his machine, he cannot see _any_ files. I stopped running my branch program. He rebooted. Still can't see any files. If I log in under my Vault account on his machine, I can see files, but when he logs in, nothing. I checked in the administrator, and he has the same permissions (r/w) as everyone else.
When he logs into vault, it sees and displays the directory structure, but spends almost no time retrieving the repository information, unlike other systems where it takes a few seconds.
Could this be related to the ShareBranch? Any suggestions on what to try?
-Jerry
The program I made seems to be working as expected. However, one of the other users here has started to have a major problem since I started doing the ShareBranching. I don't know if it is related, or just a coincidence. In the Vault client on his machine, he cannot see _any_ files. I stopped running my branch program. He rebooted. Still can't see any files. If I log in under my Vault account on his machine, I can see files, but when he logs in, nothing. I checked in the administrator, and he has the same permissions (r/w) as everyone else.
When he logs into vault, it sees and displays the directory structure, but spends almost no time retrieving the repository information, unlike other systems where it takes a few seconds.
Could this be related to the ShareBranch? Any suggestions on what to try?
-Jerry
Have the user delete (or rename) the client side cache:
http://support.sourcegear.com/viewtopic.php?t=6
http://support.sourcegear.com/viewtopic.php?t=6
Linda Bauer
SourceGear
Technical Support Manager
SourceGear
Technical Support Manager