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.
30 using System
.Collections
;
31 using System
.Collections
.Generic
;
34 using Microsoft
.TeamFoundation
.Client
;
35 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
36 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
38 [Command("history", "Display changelog history for specified file.", "hist")]
39 class HistoryCommand
: Command
41 public HistoryCommand(Driver driver
, string[] args
): base(driver
, args
)
45 public override void Run()
47 bool defaultCwdSetting
= Settings
.Current
.GetAsBool("History.DefaultToCwd");
48 string path
= Environment
.CurrentDirectory
;
50 if (Arguments
.Length
> 1) path
= Arguments
[1];
51 else if (!defaultCwdSetting
)
53 Console
.WriteLine("The history command takes exactly one item.");
57 if (!VersionControlPath
.IsServerItem(path
)) path
= Path
.GetFullPath(path
);
59 RecursionType rtype
= Options
.Recursive
? RecursionType
.Full
: RecursionType
.None
;
60 bool histSetting
= Settings
.Current
.GetAsBool("History.Recursive");
61 if (histSetting
) rtype
= RecursionType
.Full
;
62 bool detailed
= Options
.Format
.Equals("detailed", StringComparison
.InvariantCultureIgnoreCase
);
64 IEnumerable changeSets
= VersionControlServer
.QueryHistory(path
, VersionSpec
.Latest
, 0, rtype
, null,
65 null, null, Options
.StopAfter
, detailed
, false, false);
67 int maxId
= 2, maxOwner
= 5, maxDate
= 6;
68 foreach (Changeset changeSet
in changeSets
)
70 string id
= Convert
.ToString(changeSet
.ChangesetId
);
71 if (id
.Length
> maxId
) maxId
= id
.Length
;
73 string date
= changeSet
.CreationDate
.ToString("d");
74 if (date
.Length
> maxDate
) maxDate
= date
.Length
;
76 // domain is stripped on output
77 int ownerNameLen
= changeSet
.Owner
.Length
;
78 int slash
= changeSet
.Owner
.IndexOf('\\');
79 if (-1 != slash
) ownerNameLen
= changeSet
.Owner
.Length
- slash
;
81 if (ownerNameLen
> maxOwner
)
83 maxOwner
= ownerNameLen
;
87 int maxComment
= WindowWidth
- maxId
- maxOwner
- maxDate
- 5;
89 foreach (Changeset changeSet
in changeSets
)
91 string comment
= "none";
92 if (changeSet
.Comment
!= null)
94 if (changeSet
.Comment
.Length
> maxComment
)
95 comment
= changeSet
.Comment
.Remove(maxComment
);
97 comment
= changeSet
.Comment
;
100 // domain is stripped on output
101 string owner
= changeSet
.Owner
;
102 int slash
= changeSet
.Owner
.IndexOf('\\');
105 owner
= changeSet
.Owner
.Substring(slash
+1);
108 string line
= String
.Format("{0} {1} {2} {3}",
109 Convert
.ToString(changeSet
.ChangesetId
).PadRight(maxId
),
110 owner
.PadRight(maxOwner
),
111 changeSet
.CreationDate
.ToString("d").PadRight(maxDate
),
114 Console
.WriteLine(line
);
115 if (!detailed
) continue;
117 foreach (Change change
in changeSet
.Changes
)
119 Console
.WriteLine(" " + change
.ChangeType
.ToString().ToLower() + " " + change
.Item
.ServerItem
);