首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TFS2010 -轨道合并

TFS2010 -轨道合并
EN

Stack Overflow用户
提问于 2012-03-01 10:06:50
回答 2查看 3.8K关注 0票数 5

给定一个变更集c,并且c包含合并操作,我想得到所有已合并并导致c的变更集的列表。

例如,

  • Changeset 1包含一些文件的编辑。
  • Changeset 2包含一些其他文件的编辑。
  • Changeset 3是变更集1+2到父分支的合并。

现在,我想从请求变更集3获得变更集1+2,后者将包含的变更集合并在一起。

我想使用TFS API来完成这个任务。我遇到了versionControlServer.TrackMerges方法,但是我不明白这个方法所期望的ItemIdentifiers应该是什么。不幸的是,我找不到如何使用这种方法的例子。而且我也不确定这是否真的是正确的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-01 13:57:52

好吧,我花了很长时间,但我想我知道怎么做了。这是将查找所有“父”变更集的代码:

代码语言:javascript
复制
/// <summary>
/// Gets the changesets which have resulted in the given changeset due
/// to a merge operation.
/// </summary>
/// <param name="changeset">The changeset.</param>
/// <param name="versionControlServer">The version control server.</param>
/// <returns>
/// A list of all changesets that have resulted into the given changeset.
/// </returns>
public static List<Changeset> GetMergedChangesets(Changeset changeset, VersionControlServer versionControlServer)
{
    // remember the already covered changeset id's
    Dictionary<int, bool> alreadyCoveredChangesets = new Dictionary<int, bool>();

    // initialize list of parent changesets
    List<Changeset> parentChangesets = new List<Changeset>();

    // go through each change inside the changeset
    foreach(Change change in changeset.Changes)
    {
        // query for the items' history
        var queryResults = versionControlServer.QueryMergesExtended(
                                new ItemSpec(change.Item.ServerItem, RecursionType.Full),
                                new ChangesetVersionSpec(changeset.ChangesetId),
                                null,
                                null);

        // go through each changeset in the history
        foreach (var result in queryResults)
        {
            // only if the target-change is the given changeset, we have a hit
            if (result.TargetChangeset.ChangesetId == changeset.ChangesetId)
            {
                // if that hit has already been processed elsewhere, then just skip it
                if (!alreadyCoveredChangesets.ContainsKey(result.SourceChangeset.ChangesetId))
                {
                    // otherwise add it
                    alreadyCoveredChangesets.Add(result.SourceChangeset.ChangesetId, true);
                    parentChangesets.Add(versionControlServer.GetChangeset(result.SourceChangeset.ChangesetId));
                }
            }
        }
    }

    return parentChangesets;
}

编辑:

我刚刚意识到上面的代码中有一个小的"bug“,我过去常常在查询中写"VersionSpec.Latest”,但是:"new (changeset.ChangesetId)“会更好,因为一旦删除了源分支,就会跟踪变更集。

票数 9
EN

Stack Overflow用户

发布于 2015-03-27 08:31:35

我认为本·克拉克-罗宾逊的这个页面回答了如何使用TrackMerges() API的最初问题:

下面是一个经过验证的示例:

代码语言:javascript
复制
using tfvcc = Microsoft.TeamFoundation.VersionControl.Client;

var sourcePath = "$/projectName/branchObjectName1"; 
var targetPath = "$/projectName/branchObjectName2";

versionCtl.TrackMerges(
    sourceChangesetIds: new[] { 1000 },
    sourceItem: new tfvcc.ItemIdentifier(sourcePath),
    targetItems: new[] { new tfvcc.ItemIdentifier(targetPath) },
    pathFilter: null)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9514204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档