add.DirectoryMenu
[tfs.git] / class / Gtk.TeamFoundation / DiffItemNull.cs
blobbc9c4c9c1e1c08fce86706eca83396d33276d546
1 //
2 // DiffItemNull.cs
3 //
4 // Authors:
5 // Joel Reed (joelwreed@gmail.com)
6 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.IO;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Text;
34 using Microsoft.TeamFoundation.Client;
35 using Microsoft.TeamFoundation.VersionControl.Common;
36 using Microsoft.TeamFoundation.VersionControl.Client;
38 namespace Gtk.TeamFoundation
40 internal sealed class DiffItemNull : IDiffItem
42 private string label;
44 public DiffItemNull ()
48 public string GetFile ()
50 return "";
53 public bool IsTemporary
55 get { return true; }
58 public string Label
60 get { return label; }
61 set { label = value; }
64 public int GetEncoding()
66 return Encoding.UTF8.CodePage;
70 public class DiffHelper
72 static public void ShowChangeset(VersionControlServer vcs,
73 ChangesetVersionSpec versionSpec,
74 bool brief, DiffOptions diffOpts)
76 int changesetId = versionSpec.ChangesetId;
77 Changeset changeset = vcs.GetChangeset(changesetId, true, true);
79 // fetch all items in one fell swoop
80 List<int> ids = new List<int>();
81 foreach (Change change in changeset.Changes)
82 ids.Add(change.Item.ItemId);
84 // find items in prior changeset
85 Microsoft.TeamFoundation.VersionControl.Client.Item[] items = vcs.GetItems(ids.ToArray(), changesetId-1, true);
86 SortedList<int, Microsoft.TeamFoundation.VersionControl.Client.Item> itemList = new SortedList<int, Microsoft.TeamFoundation.VersionControl.Client.Item>();
87 foreach (Microsoft.TeamFoundation.VersionControl.Client.Item item in items)
89 // itemId of 0 means a null item, IOW file was added in this changeset
90 // and missing in prior changeset
91 if (item.ItemId == 0) continue;
92 itemList.Add(item.ItemId, item);
95 foreach (Change change in changeset.Changes)
97 // skip folders
98 if (change.Item.ItemType == ItemType.Folder) continue;
99 string p = change.Item.ServerItem.Substring(2);
101 if (brief)
103 Console.WriteLine(p);
104 continue;
107 IDiffItem a = new DiffItemNull();
108 IDiffItem b = new DiffItemNull();
110 string tnameA = null;
111 string tnameB = null;
113 if (((change.ChangeType & ChangeType.Add) != ChangeType.Add) &&
114 (itemList.ContainsKey(change.Item.ItemId)))
116 Microsoft.TeamFoundation.VersionControl.Client.Item itemA = itemList[change.Item.ItemId];
118 tnameA = Path.GetTempFileName();
119 itemA.DownloadFile(tnameA);
121 a = new DiffItemLocalFile(tnameA, itemA.Encoding,
122 changeset.CreationDate, true);
125 if ((change.ChangeType & ChangeType.Delete) != ChangeType.Delete)
127 tnameB = Path.GetTempFileName();
128 change.Item.DownloadFile(tnameB);
130 b = new DiffItemLocalFile(tnameB, change.Item.Encoding,
131 changeset.CreationDate, true);
134 diffOpts.TargetLabel = versionSpec.DisplayString;
135 Difference.DiffFiles(vcs, a, b, diffOpts, p, true);
137 if (!String.IsNullOrEmpty(tnameA))
138 File.Delete(tnameA);
140 if (!String.IsNullOrEmpty(tnameB))
141 File.Delete(tnameB);