root.node
[tfs.git] / tools / tf / DiffItemNull.cs
blobcdc27dd51d76fe1e75f6404ec54474f428f4f5be
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Text;
6 using Microsoft.TeamFoundation.Client;
7 using Microsoft.TeamFoundation.VersionControl.Common;
8 using Microsoft.TeamFoundation.VersionControl.Client;
10 public sealed class DiffItemNull : IDiffItem
12 private string label;
14 public DiffItemNull ()
18 public string GetFile ()
20 return "";
23 public bool IsTemporary
25 get { return true; }
28 public string Label
30 get { return label; }
31 set { label = value; }
34 public int GetEncoding()
36 return Encoding.UTF8.CodePage;
40 class DiffHelper
42 static public void ShowChangeset(VersionControlServer vcs,
43 ChangesetVersionSpec versionSpec,
44 bool brief, DiffOptions diffOpts)
46 int changesetId = versionSpec.ChangesetId;
47 Changeset changeset = vcs.GetChangeset(changesetId, true, true);
49 // fetch all items in one fell swoop
50 List<int> ids = new List<int>();
51 foreach (Change change in changeset.Changes)
53 // skip folders
54 if (change.Item.ItemType == ItemType.Folder) continue;
55 ids.Add(change.Item.ItemId);
58 // find items in prior changeset
59 Item[] items = vcs.GetItems(ids.ToArray(), changesetId-1, true);
60 SortedList<int, Item> itemList = new SortedList<int, Item>();
61 foreach (Item item in items)
63 // itemId of 0 means a null item, IOW file was added in this changeset
64 // and missing in prior changeset
65 if (item.ItemId == 0) continue;
66 itemList.Add(item.ItemId, item);
69 foreach (Change change in changeset.Changes)
71 // skip folders
72 if (change.Item.ItemType == ItemType.Folder) continue;
73 string p = change.Item.ServerItem.Substring(2);
75 if (brief)
77 Console.WriteLine(p);
78 continue;
81 IDiffItem a = new DiffItemNull();
82 IDiffItem b = new DiffItemNull();
84 string tnameA = null;
85 string tnameB = null;
87 if (((change.ChangeType & ChangeType.Add) != ChangeType.Add) &&
88 (itemList.ContainsKey(change.Item.ItemId)))
90 Item itemA = itemList[change.Item.ItemId];
92 tnameA = Path.GetTempFileName();
93 itemA.DownloadFile(tnameA);
95 a = new DiffItemLocalFile(tnameA, itemA.Encoding,
96 changeset.CreationDate, true);
99 if ((change.ChangeType & ChangeType.Delete) != ChangeType.Delete)
101 tnameB = Path.GetTempFileName();
102 change.Item.DownloadFile(tnameB);
104 b = new DiffItemLocalFile(tnameB, change.Item.Encoding,
105 changeset.CreationDate, true);
108 diffOpts.TargetLabel = versionSpec.DisplayString;
109 Difference.DiffFiles(vcs, a, b, diffOpts, p, true);
111 if (!String.IsNullOrEmpty(tnameA))
112 File.Delete(tnameA);
114 if (!String.IsNullOrEmpty(tnameB))
115 File.Delete(tnameB);