optimist123

My task is to (using the API) analyze all changesets that are commited between a date range and report on the files in the changeset and the differences between them and their previous revision. I'm not seeing how to determine or get the previous revision of a file. Can someone tell me how to

Re: Team Foundation Server - Version Control how to get contents of previous revision

Richard Berg MSFT

Pseudocode:
Item myItem = versionControlServer.GetItem("$/.../myItem.txt", new ChangesetVersionSpec(1234))
myItem.DownloadFile(@"c:\temp\myItem.txt")

You should also look at the ThreeWayMerge class so that you don't need to roll your own diff code.




Re: Team Foundation Server - Version Control how to get contents of previous revision

optimist123

Richard, thanks for the reply but that's not quite what my problem is. My fault - I didn't phrase the problem well. I know how to get the contents of "a" revision, but given an Item (I call QueryHistory and get all changesets, then iterate though them and their Change[]s. So, looking at a particular Change.Item, I can see the latest item version and of course I have the changeset id. What can I do to find the previous revision for that particular item, when all I see is the Latest Or...another way...how to find the previous changeset that that Item was in Right now, I have to resort to looping from the current changeset id down to 1 until I find the next changeset where GetItem() doesn't return null when I try to get an item with that changeset id. Not a very efficient way.

I will check out the ThreeWayMerge code - all I really need is lines added and lines deleted, if it can provide that, great.





Re: Team Foundation Server - Version Control how to get contents of previous revision

Bill Tutt - MSFT

The TFS warehoue contains code churn information. Would this be good enough data to use

Bill






Re: Team Foundation Server - Version Control how to get contents of previous revision

Eugene Zakhareyev

If you have an item and a version, you can do QueryHistory on that item specifying maxCount parameter as 2 (and perhaps versionTo for the range); then you will have current and previous version of the item. I think that question was raised several times already (just unable to find a forum thread on that).

Regards, Eugene