5 // Joel Reed (joelwreed@gmail.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System
.Collections
;
32 using System
.Collections
.Generic
;
34 using Microsoft
.TeamFoundation
.Client
;
35 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
36 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
38 internal sealed class DiffItemNull
: IDiffItem
42 public DiffItemNull ()
46 public string GetFile ()
51 public bool IsTemporary
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
)
96 if (change
.Item
.ItemType
== ItemType
.Folder
) continue;
97 string p
= change
.Item
.ServerItem
.Substring(2);
101 Console
.WriteLine(p
);
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
))
138 if (!String
.IsNullOrEmpty(tnameB
))