TFS2010 - Merging Paths

Given the set of changes to c and given that c contains merge operations, I would like to get a list of all the sets of changes that have been merged and listed in c.

For instance:

  • Changelog 1 contains some changes for some files.
  • Changelog 2 contains some changes for some other files.
  • Change 3 is a merge of change sets 1 + 2 with the parent branch.

Now I would like to get a set of changes 1 + 2 from a changeet 3 request that replaces it.

I want to do this using the TFS API. I came across the versionControlServer.TrackMerges method , but I don’t understand what the ItemIdentifiers should know, which this method should expect. Unfortunately, I cannot find an example of how to use this method. Also I'm not sure if this is really correct.

+5
source share
2 answers

Well, it took me a lot of time, but I think I found out how to do it. This is the code that will find all the parent sets of changes:

/// <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;
}

Edit:

, "", "VersionSpec.Latest" : "new ChangesetVersionSpec (changeset.ChangesetId)" , .

+9

, Ben Clark-Robinson , API TrackMerges():

:

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)
0

All Articles