From 06161cc61480f2634f3ad63679a6b3bb06152988 Mon Sep 17 00:00:00 2001 From: "Joel W. Reed" Date: Wed, 15 Aug 2007 14:14:06 -0400 Subject: [PATCH] changesetview --- tools/tf/ChangesetView.cs | 34 ++++++++++++++++++- tools/tf/DiffCommand.cs | 80 ++----------------------------------------- tools/tf/DiffItemNull.cs | 85 ++++++++++++++++++++++++++++++++++++++++++++++ tools/tf/RepositoryView.cs | 5 +-- 4 files changed, 122 insertions(+), 82 deletions(-) diff --git a/tools/tf/ChangesetView.cs b/tools/tf/ChangesetView.cs index 17a04a7..f1f6aa6 100644 --- a/tools/tf/ChangesetView.cs +++ b/tools/tf/ChangesetView.cs @@ -1,7 +1,9 @@ using System; +using System.IO; using System.Collections; using System.Collections.Generic; using System.Net; +using System.Text; using Gtk; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.VersionControl.Common; @@ -36,6 +38,20 @@ public class ChangesetView : Gtk.VPaned Add2(view); } + protected DiffOptions GetDiffOptions(StreamWriter writer) + { + DiffOptions options = new DiffOptions(); + options.UseThirdPartyTool = false; + options.Flags = DiffOptionFlags.EnablePreambleHandling; + options.OutputType = DiffOutputType.Unified; + options.TargetEncoding = Encoding.UTF8; + options.SourceEncoding = Encoding.UTF8; + options.StreamWriter = writer; + options.StreamWriter.AutoFlush = true; + + return options; + } + void OnSelectionChanged (object o, EventArgs args) { TreeIter iter; @@ -44,7 +60,23 @@ public class ChangesetView : Gtk.VPaned if (!((TreeSelection)o).GetSelected (out model, out iter)) return; string cid = (string) model.GetValue (iter, 0); - textBuffer.Text = cid; + ChangesetVersionSpec versionSpec = new ChangesetVersionSpec(cid); + + Console.WriteLine("Making diff"); + string tname = System.IO.Path.GetTempFileName(); + using (StreamWriter sw = new StreamWriter(tname)) + { + DiffHelper.ShowChangeset(driver.VersionControlServer, versionSpec, + false, GetDiffOptions(sw)); + } + Console.WriteLine("done!"); + + using (StreamReader sr = new StreamReader(tname)) + { + textBuffer.Text = sr.ReadToEnd(); + } + + File.Delete(tname); } public void Update(string path, int stopAfter) diff --git a/tools/tf/DiffCommand.cs b/tools/tf/DiffCommand.cs index 52a7f41..6b5a6fc 100644 --- a/tools/tf/DiffCommand.cs +++ b/tools/tf/DiffCommand.cs @@ -42,82 +42,6 @@ class DifferenceCommand : Command return options; } - public void ShowChangeset(Workspace workspace, ChangesetVersionSpec versionSpec) - { - int changesetId = versionSpec.ChangesetId; - Changeset changeset = VersionControlServer.GetChangeset(changesetId, true, true); - - // fetch all items in one fell swoop - List ids = new List(); - foreach (Change change in changeset.Changes) - { - // skip folders - if (change.Item.ItemType == ItemType.Folder) continue; - ids.Add(change.Item.ItemId); - } - - // find items in prior changeset - Item[] items = VersionControlServer.GetItems(ids.ToArray(), changesetId-1, true); - SortedList itemList = new SortedList(); - foreach (Item item in items) - { - // itemId of 0 means a null item, IOW file was added in this changeset - // and missing in prior changeset - if (item.ItemId == 0) continue; - itemList.Add(item.ItemId, item); - } - - foreach (Change change in changeset.Changes) - { - // skip folders - if (change.Item.ItemType == ItemType.Folder) continue; - string p = change.Item.ServerItem.Substring(2); - - if (OptionBrief) - { - Console.WriteLine(CanonicalPath(p)); - continue; - } - - IDiffItem a = new DiffItemNull(); - IDiffItem b = new DiffItemNull(); - - string tnameA = null; - string tnameB = null; - - if (((change.ChangeType & ChangeType.Add) != ChangeType.Add) && - (itemList.ContainsKey(change.Item.ItemId))) - { - Item itemA = itemList[change.Item.ItemId]; - - tnameA = Path.GetTempFileName(); - itemA.DownloadFile(tnameA); - - a = new DiffItemLocalFile(tnameA, itemA.Encoding, - changeset.CreationDate, true); - } - - if ((change.ChangeType & ChangeType.Delete) != ChangeType.Delete) - { - tnameB = Path.GetTempFileName(); - change.Item.DownloadFile(tnameB); - - b = new DiffItemLocalFile(tnameB, change.Item.Encoding, - changeset.CreationDate, true); - } - - DiffOptions diffOpts = GetDiffOptions(); - diffOpts.TargetLabel = versionSpec.DisplayString; - Difference.DiffFiles(VersionControlServer, a, b, diffOpts, p, true); - - if (!String.IsNullOrEmpty(tnameA)) - File.Delete(tnameA); - - if (!String.IsNullOrEmpty(tnameB)) - File.Delete(tnameB); - } - } - public void ShowModifiedFiles(Workspace workspace, string path) { char[] charsToTrim = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}; @@ -292,7 +216,9 @@ class DifferenceCommand : Command { VersionSpec versionSpec = VersionSpec.ParseSingleSpec(Arguments[0], OwnerFromString(OptionOwner)); if (versionSpec is ChangesetVersionSpec) - ShowChangeset(workspace, versionSpec as ChangesetVersionSpec); + DiffHelper.ShowChangeset(VersionControlServer, + versionSpec as ChangesetVersionSpec, + OptionBrief, GetDiffOptions()); } } } diff --git a/tools/tf/DiffItemNull.cs b/tools/tf/DiffItemNull.cs index 5ccd4d8..cdc27dd 100644 --- a/tools/tf/DiffItemNull.cs +++ b/tools/tf/DiffItemNull.cs @@ -1,5 +1,10 @@ using System; +using System.IO; +using System.Collections; +using System.Collections.Generic; using System.Text; +using Microsoft.TeamFoundation.Client; +using Microsoft.TeamFoundation.VersionControl.Common; using Microsoft.TeamFoundation.VersionControl.Client; public sealed class DiffItemNull : IDiffItem @@ -31,3 +36,83 @@ public sealed class DiffItemNull : IDiffItem return Encoding.UTF8.CodePage; } } + +class DiffHelper +{ + static public void ShowChangeset(VersionControlServer vcs, + ChangesetVersionSpec versionSpec, + bool brief, DiffOptions diffOpts) + { + int changesetId = versionSpec.ChangesetId; + Changeset changeset = vcs.GetChangeset(changesetId, true, true); + + // fetch all items in one fell swoop + List ids = new List(); + foreach (Change change in changeset.Changes) + { + // skip folders + if (change.Item.ItemType == ItemType.Folder) continue; + ids.Add(change.Item.ItemId); + } + + // find items in prior changeset + Item[] items = vcs.GetItems(ids.ToArray(), changesetId-1, true); + SortedList itemList = new SortedList(); + foreach (Item item in items) + { + // itemId of 0 means a null item, IOW file was added in this changeset + // and missing in prior changeset + if (item.ItemId == 0) continue; + itemList.Add(item.ItemId, item); + } + + foreach (Change change in changeset.Changes) + { + // skip folders + if (change.Item.ItemType == ItemType.Folder) continue; + string p = change.Item.ServerItem.Substring(2); + + if (brief) + { + Console.WriteLine(p); + continue; + } + + IDiffItem a = new DiffItemNull(); + IDiffItem b = new DiffItemNull(); + + string tnameA = null; + string tnameB = null; + + if (((change.ChangeType & ChangeType.Add) != ChangeType.Add) && + (itemList.ContainsKey(change.Item.ItemId))) + { + Item itemA = itemList[change.Item.ItemId]; + + tnameA = Path.GetTempFileName(); + itemA.DownloadFile(tnameA); + + a = new DiffItemLocalFile(tnameA, itemA.Encoding, + changeset.CreationDate, true); + } + + if ((change.ChangeType & ChangeType.Delete) != ChangeType.Delete) + { + tnameB = Path.GetTempFileName(); + change.Item.DownloadFile(tnameB); + + b = new DiffItemLocalFile(tnameB, change.Item.Encoding, + changeset.CreationDate, true); + } + + diffOpts.TargetLabel = versionSpec.DisplayString; + Difference.DiffFiles(vcs, a, b, diffOpts, p, true); + + if (!String.IsNullOrEmpty(tnameA)) + File.Delete(tnameA); + + if (!String.IsNullOrEmpty(tnameB)) + File.Delete(tnameB); + } + } +} \ No newline at end of file diff --git a/tools/tf/RepositoryView.cs b/tools/tf/RepositoryView.cs index 81427f3..84c34a5 100644 --- a/tools/tf/RepositoryView.cs +++ b/tools/tf/RepositoryView.cs @@ -30,13 +30,10 @@ public class RepositoryView : Gtk.TreeView string path = itemStore.GetValue(args.Iter, 1).ToString() + "/*"; Console.WriteLine(path); - Gtk.TreeIter children; - bool has_children = itemStore.IterChildren(out children, args.Iter); - int indx = 0; Microsoft.TeamFoundation.VersionControl.Client.Item[] items = ItemsForPath(path); if (items.Length == 0) - SetRowValue(args.Iter, indx, " - permission denied - ", ""); + SetRowValue(args.Iter, indx, " - item list not available - ", ""); foreach (Microsoft.TeamFoundation.VersionControl.Client.Item item in items) { -- 2.11.4.GIT