简体   繁体   中英

TFS API Changeset branch

I've trying to extract the branch history from a changeset, following this article. However, I've noticed that a Changeset has a property called IsBranch, which is not the way that the article describes to check whether the changeset is a branch.

What is the difference between the following checks:

VersionControlServer vcs = tpc.GetService<VersionControlServer>();
Changeset cs = vcs.GetChangeset(changeset.ChangesetId);

Console.WriteLine("Changeset: {0}", cs.ChangesetId);

// Get History
foreach (var change in cs.Changes)
{
     if (change.Item.IsBranch)
     {
     }

And

VersionControlServer vcs = tpc.GetService<VersionControlServer>();
Changeset cs = vcs.GetChangeset(changeset.ChangesetId);

Console.WriteLine("Changeset: {0}", cs.ChangesetId);

// Get History
foreach (var change in cs.Changes)
{
     if ((change.ChangeType & ChangeType.Branch) == ChangeType.Branch)                    
     {
     }

The IsBranch property of the Item class is new in 2010, so the second way is the way that you would have done it in previous versions of TFS.

2010 Class Members

2008 Class Members

To get TFS to set the value for the item.IsBranch property you need to tell the VersionControlServer that you want the item's branch info by passing the GetItemsOptions.IncludeBranchInfo flag when calling GetItem() .

Example:

using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri))
{
    tfs.EnsureAuthenticated();
    var vcs = tfs.GetService<VersionControlServer>();
    var item = vcs.GetItem("$/Proj/Main/", VersionSpec.Latest, DeletedState.Any, GetItemsOptions.IncludeBranchInfo);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM