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 static 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); } }