Welcome to MSDN Blogs Sign in | Join | Help

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

            }

        }

    }

}

 

Published Friday, November 04, 2005 3:28 PM by jmanning

Comments

# Links to code samples

Saturday, August 12, 2006 10:51 AM by Buck Hodges
I recently had to put together a list of links to code samples.&amp;nbsp; This isn't even close to comprehensive,...

# VSTS resources on MSDN

Thursday, January 25, 2007 6:20 AM by Nam, Seungho's Blog

MOC Curriculum : Course 2631A Optimizing the Software Development Lifecycle with Microsoft Visual Studio

# Links to code samples

Saturday, September 06, 2008 11:44 AM by Buck Hodges

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

# James Manning s blog Scanning history for the changesets that had | Insomnia Cure

Anonymous comments are disabled
 
Page view tracker