From 1a6f62eac61c197b5a10bce9a1a04540064487fa Mon Sep 17 00:00:00 2001 From: Joel Reed Date: Mon, 25 Jun 2007 13:29:09 -0400 Subject: [PATCH] Add tf diff /modified option to show locally modified files as a unified diff. Can be used to review changes before using the online command. --- ChangeLog | 3 +++ docs/tf.txt | 6 ++++-- tools/tf/DiffCommand.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9e78f8..e306fe0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,9 @@ # Add /added, /modified, /deleted flags to Online command to show just additions, just modifications, or just deletions respectively. These flags may be combined. With no flags, all changes are shown. + # Add tf diff /modified option to show locally modified files as a + unified diff. Can be used to review changes before using the online + command. 2007-06-08 Joel Reed diff --git a/docs/tf.txt b/docs/tf.txt index 219af45..c484336 100644 --- a/docs/tf.txt +++ b/docs/tf.txt @@ -60,9 +60,11 @@ COMMANDS Pend a delete against a file or files from the repository. To commit, you must issue a checkin command. -*diff [ /old ]*:: +*diff [ /old | /modified ]*:: Show pending changes as a diff. With /old, shows changes from current - workspace to latest on the server as a diff. With a changeset id, like + workspace to latest on the server as a diff. With /modified, shows + changes to writable workspace files as a diff - another way to preview + changes before using the *online* command. With a changeset id, like C12278, the command will show you a diff of the files changed in that changeset. diff --git a/tools/tf/DiffCommand.cs b/tools/tf/DiffCommand.cs index cdf4e0e..214512f 100644 --- a/tools/tf/DiffCommand.cs +++ b/tools/tf/DiffCommand.cs @@ -100,6 +100,51 @@ class DiffCommand : Command } } + public void ShowModifiedFiles(Workspace workspace, string path) + { + char[] charsToTrim = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}; + string itemPath = path.TrimEnd(charsToTrim); + + workspace.RefreshMappings(); + string serverPath = workspace.GetServerItemForLocalItem(itemPath); + + // pull item list based on WorkspaceVersion. otherwise might get + // new items on server that haven't been pulled yet in the list returned + WorkspaceVersionSpec version = new WorkspaceVersionSpec(workspace); + + // get item list from TFS server + ItemSpec itemSpec = new ItemSpec(itemPath, RecursionType.Full); + ItemSet itemSet = VersionControlServer.GetItems(itemSpec, version, DeletedState.NonDeleted, ItemType.Any, true); + Item[] items = itemSet.Items; + + foreach (Item item in items) + { + if (item.ItemType != ItemType.File) continue; + if (item.ServerItem.Length == serverPath.Length) continue; + string serverItem = item.ServerItem.Remove(0, serverPath.Length+1); + + // server item paths are separated with '/', but on windows the file list below has '\' separated paths + if (Path.DirectorySeparatorChar != '/') + serverItem = serverItem.Replace('/', Path.DirectorySeparatorChar); + + string fname = Path.Combine(itemPath, serverItem); + if (FileAttributes.ReadOnly == (File.GetAttributes(fname) & FileAttributes.ReadOnly)) + continue; + + string tnameA = Path.GetTempFileName(); + item.DownloadFile(tnameA); + IDiffItem a = new DiffItemLocalFile(tnameA, item.Encoding, DateTime.Now, false); + + IDiffItem b = new DiffItemLocalFile(fname, item.Encoding, DateTime.Now, false); + + string p = fname.Substring(path.Length); + Difference.DiffFiles(VersionControlServer, a, b, + GetDiffOptions(), p, true); + + if (!String.IsNullOrEmpty(tnameA)) DeleteReadOnlyFile(tnameA); + } + } + public void ShowOldFiles(Workspace workspace, string path) { // process command options @@ -197,6 +242,12 @@ class DiffCommand : Command Environment.Exit(0); } + if (Options.Modified) + { + ShowModifiedFiles(workspace, path); + Environment.Exit(0); + } + if (File.Exists(path) || Directory.Exists(path)) ShowPendingChanges(workspace, path); else -- 2.11.4.GIT