/// <summary> /// Visual compare current text document with the latest version in Version Control. /// </summary> private void CompareDocumentWithLatestVersion() { Item item = _marginCore.VersionControlItem; VersionControlServer vcs = item.VersionControlServer; ITextDocument textDoc = _marginCore.TextDocument; IDiffItem source = Difference.CreateTargetDiffItem(vcs, item.ServerItem, VersionSpec.Latest, 0, VersionSpec.Latest); var target = new DiffItemLocalFile(textDoc.FilePath, textDoc.Encoding.CodePage, textDoc.LastContentModifiedTime, false); Difference.VisualDiffItems(vcs, source, target); }
void ShowPendingChanges(Workspace workspace, string[] paths) { PendingChange[] pendingChanges = workspace.GetPendingChanges(paths, RecursionType.Full, true); if (pendingChanges.Length == 0) { Console.WriteLine("No pending changes."); Environment.Exit((int)ExitCode.PartialSuccess); } string cwd = Environment.CurrentDirectory; foreach (PendingChange change in pendingChanges) { string p = change.LocalItem; if (p.StartsWith(cwd)) { p = p.Substring(cwd.Length + 1); } if (OptionBrief) { Driver.WriteLine(CanonicalPath(p)); continue; } IDiffItem a = new DiffItemNull(); IDiffItem b = new DiffItemNull(); string tname = null; if (!change.IsAdd) { tname = Path.GetTempFileName(); change.DownloadBaseFile(tname); a = new DiffItemLocalFile(tname, change.Encoding, change.CreationDate, true); } if (!change.IsDelete) { b = new DiffItemLocalFile(change.LocalItem, change.Encoding, change.CreationDate, false); } Difference.DiffFiles(VersionControlServer, a, b, GetDiffOptions(), p, true); if (!String.IsNullOrEmpty(tname)) { File.Delete(tname); } } }
public void ShowOldFiles(Workspace workspace, string path) { // process command options ItemSpec itemSpec = new ItemSpec(path, RecursionType.Full); List <ItemSpec> itemSpecs = new List <ItemSpec>(); itemSpecs.Add(itemSpec); ExtendedItem[][] items = workspace.GetExtendedItems(itemSpecs.ToArray(), DeletedState.NonDeleted, ItemType.Any); foreach (ExtendedItem[] itemArray in items) { foreach (ExtendedItem item in itemArray) { if (item.IsLatest) { continue; } string p = item.LocalItem.Substring(path.Length); if (OptionBrief) { Driver.WriteLine(p); continue; } IDiffItem a = new DiffItemNull(); IDiffItem b = new DiffItemNull(); if ((item.ChangeType & ChangeType.Add) != ChangeType.Add) { a = new DiffItemLocalFile(item.LocalItem, item.Encoding, DateTime.Now, false); } if ((item.ChangeType & ChangeType.Delete) != ChangeType.Delete) { b = new DiffItemVersionedFile(VersionControlServer, item.ItemId, item.VersionLatest, item.LocalItem); } Difference.DiffFiles(VersionControlServer, a, b, GetDiffOptions(), p, true); } } }
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 <int> ids = new List <int>(); foreach (Change change in changeset.Changes) { ids.Add(change.Item.ItemId); } // find items in prior changeset Item[] items = vcs.GetItems(ids.ToArray(), changesetId - 1, true); SortedList <int, Item> itemList = new SortedList <int, Item>(); 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); } } }
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); } // only looking for modifications, not deletes or adds string fname = Path.Combine(itemPath, serverItem); if (!File.Exists(fname)) { continue; } if (FileAttributes.ReadOnly == (File.GetAttributes(fname) & FileAttributes.ReadOnly)) { continue; } using (FileStream fileStream = new FileStream(fname, FileMode.Open, FileAccess.Read)) { string localHash = Convert.ToBase64String(md5.ComputeHash(fileStream)); string itemHash = Convert.ToBase64String(item.HashValue); if (itemHash == localHash) { continue; } } string p = fname.Substring(path.Length + 1); if (OptionBrief) { Driver.WriteLine(CanonicalPath(p)); 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); Difference.DiffFiles(VersionControlServer, a, b, GetDiffOptions(), p, true); if (!String.IsNullOrEmpty(tnameA)) { File.Delete(tnameA); } } }