tags:

views:

42

answers:

4

Given a particular path of folder in tfs, I need to recursively find all files and folders within the folder for a given changeset. In other words, i need to get the transitive closure of a path in tfs for a given changeset. The problem I'm facing in doing so is listing the contents of a particular folder within tfs.. How would this be possible in C# ?

A: 

You can use the changeset webservice to get an XML document that contains all of the changed items for a particular changeset. Then just loop through the list of changed items and see if they are in the path you are looking for.

Here's the URL to the changeset webservice:

http://your_tfs_server/VersionControl/Changeset.aspx?artifactMoniker=your_changeset_number&webView=true

David
can I just do a VersionControlServer.getItems() and loop thro the derived array. I'm just trying it out now...
Sidd
Downvoted (sorry David). You should not use the webservice to do this under any (normal) circumstances. These are internal and can change without notice.
Robaticus
A: 

Something like this might be more what you're looking for. This gets all changes in a changeset and iterates through them, identifying the ones in the given path. This could be shortened with a linq query, but I'm leaving it a bit more expanded to give the gist of what I'm trying to say:

    TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080");
    VersionControlServer vcs = tfs.GetService<VersionControlServer>();

    Changeset cs = vcs.GetChangeset(6284868);

    foreach (Change change in cs.Changes)
    {
        if (change.Item.ServerItem.StartsWith("$/Application Common/Dev/src"))
        {
            System.Diagnostics.Debug.WriteLine(string.Format("Changeset {0}, file {1}, changes {2}",
                cs.ChangesetId, change.Item.ServerItem, change.ChangeType.ToString()));
        }
    }
Robaticus
Thanks.. But I don't need the items in a particular changeset. I need all files and folder under a given folder in tfs.
Sidd
Then you can use GetItems() ... your question does mention changeset, though.
Robaticus
A: 

I think something like this would work..


    TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080");   
    VersionControlServer vcs = tfs.GetService();   
    ItemSet items;

    items = vcs.GetItems(tfsPath, RecursionType.Full);

If you have any other ideas, please post them..

Sidd
+1  A: 

I'm assuming you want 'folder contents as of changeset X' and not 'folder contents that were part of changeset X'

GetItems is the right call to use, just pass in a version spec for the changeset you're interested in.

http://msdn.microsoft.com/en-US/library/bb138911.aspx

so, assuming you already have a reference to the VersionControlServer instance:

var myFolderAtChangeset17 = versionControlServer.GetItems("$/MyFolder", new ChangesetVersionSpec(17), RecursionType.Full);

If I misunderstood and you happen to want to 'folder contents that were part of changeset X', there's a few different ways of doing it, but getting the changeset with GetChangeset and just filtering the Changes is pretty simple.

James Manning
I wasn't aware of the version spec. This is what I wanted. Thanks...
Sidd