public System.Collections.ICollection GetHistory(string szFile) { VersionControlServer sourceControl; Workspace workspace; GetPathAndScope(szFile, out sourceControl, out workspace); // Retrieve and print the label history for the file. VersionControlLabel[] labels = null; ChangeSetLabelObject[] ChangesetLabelObjects = new ChangeSetLabelObject[10000]; Item targetFile = null; System.Collections.IEnumerable history = null; System.Collections.SortedList slChangeSetsAndLabels = new System.Collections.SortedList(); System.Collections.SortedList slChangeSets = new System.Collections.SortedList(); try { targetFile = sourceControl.GetItem(szFile); //Query labels seems to return labels that correspond to the file and nothing filtered related the version spec //So we need to query everything and then filter ourselves. //Hint: The there is a TimeSpan here because doing that is slow. DateTime dtStart = DateTime.Now; labels = sourceControl.QueryLabels(null, szFile, null, true, szFile, VersionSpec.Latest); TimeSpan tsQueryLabels = DateTime.Now - dtStart; history = sourceControl.QueryHistory(szFile, VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 10000, true, false); TimeSpan tsAnotherTimeSpan = DateTime.Now - dtStart; } catch (TeamFoundationServerException e) { // We couldn't contact the server, the item wasn't found, // or there was some other problem reported by the server, // so we stop here. System.Windows.Forms.MessageBox.Show(e.Message); return(slChangeSets.Values); } if (labels.Length == 0) { Console.WriteLine("There are no labels for " + szFile); return(slChangeSets.Values); } else { //first, sort all the changesets into a list foreach (Changeset c in history) { ChangeSetLabels csl = new ChangeSetLabels(); csl.m_csChangeset = c; slChangeSets[c.ChangesetId] = csl; slChangeSetsAndLabels[c.CreationDate] = c; } foreach (VersionControlLabel l in labels) { slChangeSetsAndLabels[l.LastModifiedDate] = l; } } return(slChangeSetsAndLabels.Values); }
static void Main(string[] args) { // Check and get the arguments. String path, scope; VersionControlServer sourceControl; GetPathAndScope(args, out path, out scope, out sourceControl); // Retrieve and print the label history for the file. VersionControlLabel[] labels = null; Item targetFile = null; System.Collections.IEnumerable history = null; System.Collections.SortedList slChangeSets = new System.Collections.SortedList(); try { // The first three arguments here are null because we do not // want to filter by label name, scope, or owner. // Since we don't need the server to send back the items in // the label, we get much better performance by ommitting // those through setting the fourth parameter to false. DateTime dtStart = DateTime.Now; //scope = "$/PCSGlobal/DevTools/Authoring"; //string labelfilter = "RadAuthor_20060524*"; //VersionSpec vspec = VersionSpec.ParseSingleSpec("C23953", null); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, VersionSpec.Latest); labels = sourceControl.QueryLabels(null, scope, null, false, path, VersionSpec.Latest); //labels = sourceControl.QueryLabels(null, scope, null, true, path, VersionSpec.Latest); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, vspec); TimeSpan tsQueryLabels = DateTime.Now - dtStart; targetFile = sourceControl.GetItem(path); history = sourceControl.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.None, null, null, null, 1000, true, false); } catch (TeamFoundationServerException e) { // We couldn't contact the server, the item wasn't found, // or there was some other problem reported by the server, // so we stop here. Console.Error.WriteLine(e.Message); Environment.Exit(1); } if (labels.Length == 0) { Console.WriteLine("There are no labels for " + path); } else { foreach (Changeset c in history) { ChangeSetLabels csl = new ChangeSetLabels(); csl.m_csChangeset = c; slChangeSets[c.ChangesetId] = csl; VersionControlLabel[] vclChangeSetLabels = null; string s = c.ChangesetId.ToString(); VersionSpec vspec = new ChangesetVersionSpec(c.ChangesetId.ToString()); //VersionSpec vspec = VersionSpec.ParseSingleSpec("C" + c.ChangesetId.ToString(), null); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, VersionSpec.Latest); //labels = sourceControl.QueryLabels(labelfilter, scope, null, true, path, vspec); DateTime dtStart = DateTime.Now; vclChangeSetLabels = sourceControl.QueryLabels(null, scope, null, false, path, vspec); TimeSpan tsQueryLabels = DateTime.Now - dtStart; foreach (VersionControlLabel vclChangeSetLabel in vclChangeSetLabels) { VersionControlLabel[] vclEverything = null; vclEverything = sourceControl.QueryLabels(vclChangeSetLabel.Name, scope, null, false, path, vspec); //csl.m_alLabels.AddRange(vclEverything); } //csl.m_alLabels.AddRange(vclChangeSetLabels); } foreach (VersionControlLabel label in labels) { // Display the label's name and when it was last modified. Console.WriteLine("{0} ({1})", label.Name, label.LastModifiedDate.ToString("g")); foreach (Item item in label.Items) { if (item.ItemId != targetFile.ItemId) { //skip over any items that we don't care about continue; } ChangeSetLabels csl = slChangeSets[item.ChangesetId] as ChangeSetLabels; csl.m_alLabels.Add(label); } // For labels that actually have comments, display it. if (label.Comment.Length > 0) { Console.WriteLine(" Comment: " + label.Comment); } } //Reverse the order of everything as it is being displayed so that it looks like the VSS order System.Collections.ArrayList alReverseOrder = new System.Collections.ArrayList(slChangeSets.Values); alReverseOrder.Reverse(); foreach (ChangeSetLabels csl in alReverseOrder) { csl.m_alLabels.Reverse(); foreach (VersionControlLabel vcl in csl.m_alLabels) { Console.WriteLine(" Labeled: " + vcl.Name); } Console.WriteLine(" Checked-in: Changeset C" + csl.m_csChangeset.ChangesetId.ToString()); Console.WriteLine(" Comment: C" + csl.m_csChangeset.Comment.ToString()); } } }