Scanning history for the changesets that had policy override - simple usage of QueryHistory

This needs references to Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.VersionControl.Client.dll - it's intentionally simple and you can easily change the loop to include more information as desired, it's just to show usage of the API mainly.

Note that since we (intentionally) go backwards in our changesets via the IEnumerable, the order of the output will be reverse chronological.

For those wondering "why IEnumerable?" - it's mainly because the query (in general) could match thousands (even millions, of course) changesets.  We don't hammer the server with getting them all in a single call (that'd take awhile to build up and send back to the client), so as you probably notice from the http traffic we get the matching changesets back in chunks from the server.  This means a better user experience (as you don't have to wait forever for the whole collection) while still maintaining an easy-to-use API.  We considered using IEnumerable<Changeset> for this situation but we wanted to make things easier for some code that needed to interact with Everett.

D:\task1\vset\SCM\SourceControl\CommandLine>getoverridechangesets dogfood .
Changeset 7662 had 2 policy failures and an override comment of "new branch"

using System;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.VersionControl.Client;

class Program

{

    static void Main(string[] args)

    {

        if (args.Length == 0)

        {

            Console.Error.WriteLine("Usage: GetOverrideChangesets <server> [path]");

            Environment.Exit(1);

        }

        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0]);

        VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

        string path = args.Length == 1 ? "$/" : args[1];

        IEnumerable changesets = vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, null, null, null, int.MaxValue, false, false);

        foreach (Changeset changeset in changesets)

        {

            if (changeset.PolicyOverride.PolicyFailures.Length > 0)

            {

                Console.WriteLine("Changeset {0} had {1} policy failure(s) and an override comment of \"{2}\"",

                                changeset.ChangesetId,

                                  changeset.PolicyOverride.PolicyFailures.Length,

                                  changeset.PolicyOverride.Comment);

            }

        }

    }

}

Comments

  • Anonymous
    August 12, 2006
    I recently had to put together a list of links to code samples.&amp;nbsp; This isn't even close to comprehensive,...

  • Anonymous
    January 24, 2007
    MOC Curriculum : Course 2631A Optimizing the Software Development Lifecycle with Microsoft Visual Studio

  • Anonymous
    September 06, 2008
    I recently had to put together a list of links to code samples. This isn't even close to comprehensive,

  • Anonymous
    June 09, 2009
    PingBack from http://insomniacuresite.info/story.php?id=3880