add.license.preamble
[tfs.git] / class / Gtk.TeamFoundation / DiffItemNull.cs
blobcede64c17bc2bed8c3660793bffb220245e4b4e3
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 internal sealed class DiffItemNull : IDiffItem
40 private string label;
42 public DiffItemNull ()
46 public string GetFile ()
48 return "";
51 public bool IsTemporary
53 get { return true; }
56 public string Label
58 get { return label; }
59 set { label = value; }
62 public int GetEncoding()
64 return Encoding.UTF8.CodePage;
68 internal class DiffHelper
70 static public void ShowChangeset(VersionControlServer vcs,
71 ChangesetVersionSpec versionSpec,
72 bool brief, DiffOptions diffOpts)
74 int changesetId = versionSpec.ChangesetId;
75 Changeset changeset = vcs.GetChangeset(changesetId, true, true);
77 // fetch all items in one fell swoop
78 List<int> ids = new List<int>();
79 foreach (Change change in changeset.Changes)
80 ids.Add(change.Item.ItemId);
82 // find items in prior changeset
83 Item[] items = vcs.GetItems(ids.ToArray(), changesetId-1, true);
84 SortedList<int, Item> itemList = new SortedList<int, Item>();
85 foreach (Item item in items)
87 // itemId of 0 means a null item, IOW file was added in this changeset
88 // and missing in prior changeset
89 if (item.ItemId == 0) continue;
90 itemList.Add(item.ItemId, item);
93 foreach (Change change in changeset.Changes)
95 // skip folders
96 if (change.Item.ItemType == ItemType.Folder) continue;
97 string p = change.Item.ServerItem.Substring(2);
99 if (brief)
101 Console.WriteLine(p);
102 continue;
105 IDiffItem a = new DiffItemNull();
106 IDiffItem b = new DiffItemNull();
108 string tnameA = null;
109 string tnameB = null;
111 if (((change.ChangeType & ChangeType.Add) != ChangeType.Add) &&
112 (itemList.ContainsKey(change.Item.ItemId)))
114 Item itemA = itemList[change.Item.ItemId];
116 tnameA = Path.GetTempFileName();
117 itemA.DownloadFile(tnameA);
119 a = new DiffItemLocalFile(tnameA, itemA.Encoding,
120 changeset.CreationDate, true);
123 if ((change.ChangeType & ChangeType.Delete) != ChangeType.Delete)
125 tnameB = Path.GetTempFileName();
126 change.Item.DownloadFile(tnameB);
128 b = new DiffItemLocalFile(tnameB, change.Item.Encoding,
129 changeset.CreationDate, true);
132 diffOpts.TargetLabel = versionSpec.DisplayString;
133 Difference.DiffFiles(vcs, a, b, diffOpts, p, true);
135 if (!String.IsNullOrEmpty(tnameA))
136 File.Delete(tnameA);
138 if (!String.IsNullOrEmpty(tnameB))
139 File.Delete(tnameB);