Reputation: 9477
Lets say I have an Item-Id or ServerItem (path). I need to know, where this Item has been moved
Current and old locations. How do I acchieve this with given Information on Serverside ?
Visual Studio can display all locations when you display the history of an item.
I tried versioncontrol.QueryHistory, however this only returns the history of the current itemid. Moving a file does change the itemid but i dont know how to get the different ids.
Querying merges doesnt seem to work either.
Lets say I query for ItemId 1234, i want the result to be something like this:
- ItemId 1789 ServerItem $/somwhere/path1/hadTobeRenamedAsWell.cs //newest
- ItemId 1234 ServerItem $/somwhere/path2/item.cs
- ItemId 1200 ServerItem $/somwhere/path3/item.cs
- ItemId 1001 ServerItem $/somwhere/path4/item.cs // oldest
If this doesnt work serverside, does it on clientside?
This is the method i use to obtain the Items
private static TeamFoundationDataReader queryVersionControl(
TeamFoundationRequestContext requestContext,
TeamFoundationVersionControlService versionConrol,
IEnumerable<string> items,
string workspaceName,
string workspaceOwnername)
{
return versionConrol.QueryItems(requestContext,
workspaceName,
workspaceOwnername,
items.Select(i => new ItemSpec(i, RecursionType.None)).ToArray(),
new LatestVersionSpec(),
DeletedState.Any,
ItemType.File,
false,
0);
}
Upvotes: 1
Views: 1034
Reputation: 1377
Here is a simple method that should return the results you are looking for if you provide the current path to the file.
/// <summary>
/// Writes out the history of changes to a file.
/// </summary>
/// <param name="path">The path to a file similar to $/FabrikamFiber/Main/FabrikamFiber.CallCenter/FabrikamFiber.CallCenter.sln</param>
private static void _GetHistory(string path)
{
using (TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false, new UICredentialsProvider()))
{
if (tpp.ShowDialog() == DialogResult.OK)
{
TfsTeamProjectCollection projectCollection = tpp.SelectedTeamProjectCollection;
VersionControlServer server = projectCollection.GetService<VersionControlServer>();
Item item = server.GetItem(path);
int changeId = item.DeletionId != 0 ? item.ChangesetId - 1 : item.ChangesetId;
ChangesetVersionSpec versionCurrent = new ChangesetVersionSpec(changeId);
ChangesetVersionSpec versionFrom = new ChangesetVersionSpec(1);
IEnumerable changesets = server.QueryHistory(path, versionCurrent, 0, RecursionType.None, null, versionFrom, LatestVersionSpec.Latest, int.MaxValue, true, false);
foreach(Changeset changeset in changesets)
{
Item info = changeset.Changes[0].Item;
Console.WriteLine(string.Format("ItemId {0} ServerItem {1}", info.ItemId, info.ServerItem));
}
}
}
}
Upvotes: 3