Unanswered Find a specific file in all "Branches" (TFS2010)

  • Wednesday, February 29, 2012 4:14 PM
     
      Has Code

    Hello,

    I want to extract the following Information from the TFS2010.

    Sorry if I sound a bit strange but I do not know how to explain my problem exactly.

    All places in the ProjectCollection where a given File is located including all branched Versions of that file.

    The problem is in my current code this is only working if speaking of hole branch.

    Lets say there is a given structur

    $

    + TestProject

    |         +Main  <- Branch

    |                  +Part1  <- Folder Containing File Test1.cs

    |         +Development <- Branch (Branched from $/TestProject/Main)

    |                   +Part1 <- Folder Containing File Test1.cs

    + TestProject2

    |

    |         +Main <- Branch

    |                  +Part1 <- Folder Containing File Test1.cs (Branched from $/TestProject/Main/Part1)

    |                  +Part2 <- Folder Containing File Test1.cs (only same Name but other file)

    |         +Development  <- Branch (Branched from $/TestProject2/Main)

    |                  +Part1 <- Folder Containing File Test1.cs

    |                  +Part2 <- Folder Containing File Test1.cs (only same Name but other file)

    Example 1 (working so far):

    Get all Locations of $/TestProject2/Development/Part2/Test1.cs

    Returns

    $/TestProject2/Main/Part2/Test1.cs

    $/TestProject2/Development/Part2/Test1.cs

    Example 2:

    Get all Locations of $/TestProject/Development/Part1/Test1.cs

    Returns

    $/TestProject/Main/Part1/Test1.cs

    $/TestProject/Development/Part1/Test1.cs

    but should return

    $/TestProject/Main/Part1/Test1.cs

    $/TestProject/Development/Part1/Test1.cs

    $/TestProject2/Main/Part1/Test1.cs

    $/TestProject2/Development/Part1/Test1.cs

    I hope this somehow understandable.
    Can somebody help me with this?

    My code so far.

    var item = versionControl.GetItem("$TestProject/Main/Part1/Test1.cs");
    			BranchObject[] allBranches = versionControl.QueryRootBranchObjects(RecursionType.Full);
    			BranchObject foundBranch = null;
    			string relativePath = string.Empty;
    			foreach (BranchObject branch in allBranches)
    			{
    				if (item.ServerItem.Contains(branch.Properties.RootItem.Item))
    				{
    					foundBranch = branch;
    					relativePath = item.ServerItem.Replace(branch.Properties.RootItem.Item, string.Empty);
    					break;
    				}
    			}
    			if (foundBranch != null)
    			{
    				while (foundBranch.Properties.ParentBranch != null)
    				{
    					foundBranch = versionControl.QueryBranchObjects(foundBranch.Properties.ParentBranch, RecursionType.None)[0];
    				}
    				List<BranchObject> erg = GetAllRelatedBranches(foundBranch, versionControl);
    				foreach (var branch in erg)
    				{
    					var newitem = versionControl.GetItem(branch.Properties.RootItem.Item + relativePath);
    					listBox1.Items.Add(branch.Properties.RootItem.Item);
    					if (newitem != null)
    					{
    						listBox1.Items.Add(string.Format("   {0} ({1} - {4}){2}{3}", newitem.ServerItem, newitem.ChangesetId,
    							newitem.DeletionId != 0 ? " DELETED" : string.Empty, newitem.ServerItem == item.ServerItem ? " CURRENT" : string.Empty,
    														 newitem.CheckinDate));
    					}
    					else
    					{
    						listBox1.Items.Add("NOT PRESENT");
    					}
    				}
    			}


All Replies

  • Wednesday, March 07, 2012 1:02 AM
     
     

    You might have better luck with the (older) VersionControlServer.GetBranchHistory API.

    If you want to stay with this approach, I would say:

    1. Start by forming the relative path ("Part1/Test1.cs")
    2. Do a QueryRootBranchObjects(RecursionType.None) -- this returns all branch objects that have no parent
    3. Loop on the results -- take each branch object's root item and check to see if the item you want exists there. You can use VersionControlServer.ServerItemExists(branch.Properties.RootItem.Item + relativePath) as the condition
    4. If it does, then call QueryBranchObjects on the branch object, with RecursionType.Full. Iterate on each branch object and do your GetItem call on that item.

  • Friday, April 13, 2012 4:22 PM
     
     

    Can you clarify please. I assume you ? was to find files in all branches but not in all Projects, correct?


    Arun Sangal Software Configuration Management Denver USA

  • Monday, April 16, 2012 4:15 PM
     
     

    I want to find all Versions of a file that exists in the Collection. The Problem so far ist that there are 2 ways to create a additional Version of a File.

    1) Make a Branch

    2) Branch an Directory that exists inside a branch (In that case no Branch is created because branches cannot contain branches.)

    If you know ClearCase you know the TreeView for sure. Thats what I want to do:

    Draw a tree-graph of all Projects and all Branches (starting from the Collection) that contains the specified file. In this graph all Projects and Branches are shown that contains that file and the actual Version of the file that is checked in.

    If that is working I whant to add all branch and merge operations in that graph.