Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programatically lookup code churn info for individual files within a changeset in TFS 2010?

Tags:

c#

.net

tfs

tfs-sdk

I need to be able to programatically lookup code churn info (lines added, changed, deleted) for individual files within a changeset in TFS 2010. The program that I need to do this is in is a desktop client application.

Anyone know how to do this? Do you have sample code you'd like to share?

like image 440
EVal Avatar asked Jun 21 '11 20:06

EVal


1 Answers

Here is a starting point:

        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://WhateverServerUrl");
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
        VersionControlServer VsServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
        IBuildDetail build = buildServer.GetAllBuildDetails(new Uri("http://WhateverBuildUrl"));

        List<IChangesetSummary> associatedChangesets = InformationNodeConverters.GetAssociatedChangesets(build);


        foreach (IChangesetSummary changeSetData in associatedChangesets)
        {
            Changeset changeSet = VsServer.GetChangeset(changeSetData.ChangesetId);
            foreach (Change change in changeSet.Changes)
            {
                bool a = change.Item.IsContentDestroyed;
                long b = change.Item.ContentLength;
            }
        } 

Changeset has the following:

    public Change[] Changes { get; set; }
    public int ChangesetId { get; set; }
    public CheckinNote CheckinNote { get; set; }
    public string Comment { get; set; }
    public string Committer { get; set; }
    public DateTime CreationDate { get; set; }
    public string Owner { get; set; }

Change has the following:

    public ChangeType ChangeType { get; }
    public Item Item { get; }
    public ReadOnlyCollection<MergeSource> MergeSources { get; }

Item has the following:

    public Uri ArtifactUri { get; }
    public Uri ArtifactUriLatestItemVersion { get; }
    public int ChangesetId { get; }
    public DateTime CheckinDate { get; }
    public static IComparer Comparer { get; }
    public long ContentLength { get; }
    public int DeletionId { get; }
    public int Encoding { get; }
    public byte[] HashValue { get; }
    public bool IsBranch { get; }
    public bool IsContentDestroyed { get; }
    public int ItemId { get; }
    public Stream DownloadFile();
    public void DownloadFile(string localFileName);
like image 69
Mike Veigel Avatar answered Sep 28 '22 11:09

Mike Veigel