From 1b93544e164a6a46e983829298130853b30e35a8 Mon Sep 17 00:00:00 2001 From: Joel Reed Date: Wed, 27 Jun 2007 23:48:59 -0400 Subject: [PATCH] Implement basic label command --- ChangeLog | 1 + .../LabelItemSpec.cs | 9 ++++ .../LabelResult.cs | 2 +- .../Repository.cs | 50 ++++++++++++++++++++++ .../VersionControlLabel.cs | 14 ++++++ .../VersionControlServer.cs | 7 +-- tools/tf/LabelCommand.cs | 17 +++++--- 7 files changed, 91 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e560352..0eaf9bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,7 @@ # Compare file hashes when looking for modifications in tf online command. Previously just looked for files marked writable. # Add tf ls-modified /writable option. + # Implement basic label command 2007-06-08 Joel Reed diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/LabelItemSpec.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/LabelItemSpec.cs index 8b1c06b..b8b03a9 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/LabelItemSpec.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/LabelItemSpec.cs @@ -46,6 +46,15 @@ namespace Microsoft.TeamFoundation.VersionControl.Client this.exclude = exclude; } + internal void ToXml(XmlWriter writer, string element) + { + writer.WriteStartElement(element); + writer.WriteAttributeString("ex", exclude.ToString().ToLower()); + ItemSpec.ToXml(writer, "ItemSpec"); + Version.ToXml(writer, "Version"); + writer.WriteEndElement(); + } + public bool Exclude { get { return exclude; } diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/LabelResult.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/LabelResult.cs index a3f54e1..700ab13 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/LabelResult.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/LabelResult.cs @@ -48,7 +48,7 @@ namespace Microsoft.TeamFoundation.VersionControl.Client labelResult.label = reader.GetAttribute("label"); labelResult.scope = reader.GetAttribute("scope"); - string status = reader.GetAttribute("chg"); + string status = reader.GetAttribute("status"); labelResult.status = (LabelResultStatus) Enum.Parse(typeof(LabelResultStatus), status, true); return labelResult; diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs index 0c70881..da50c58 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/Repository.cs @@ -238,6 +238,56 @@ namespace Microsoft.TeamFoundation.VersionControl.Client this.Invoke("DeleteWorkspace", new object[] { workspaceName, ownerName}); } + public LabelResult[] LabelItem(Workspace workspace, VersionControlLabel label, + LabelItemSpec[] labelSpecs, LabelChildOption children) + { + Message msg = new Message(GetWebRequest (new Uri(Url)), "LabelItem"); + + msg.Body.WriteElementString("workspaceName", workspace.Name); + msg.Body.WriteElementString("workspaceOwner", workspace.OwnerName); + label.ToXml(msg.Body, "label"); + + msg.Body.WriteStartElement("labelSpecs"); + foreach (LabelItemSpec labelSpec in labelSpecs) + { + labelSpec.ToXml(msg.Body, "LabelItemSpec"); + } + msg.Body.WriteEndElement(); + + msg.Body.WriteElementString("children", children.ToString()); + + List labelResults = new List(); + List faillist = new List(); + + using (HttpWebResponse response = Invoke(msg)) + { + XmlReader results = msg.ResponseReader(response); + + while (results.Read()) + { + if (results.NodeType == XmlNodeType.Element) + { + switch (results.Name) + { + case "LabelResult": + labelResults.Add(LabelResult.FromXml(this, results)); + break; + case "Failure": + faillist.Add(Failure.FromXml(this, results)); + break; + } + } + } + } + + foreach (Failure failure in faillist) + { + versionControlServer.OnNonFatalError(workspace, failure); + } + + return labelResults.ToArray(); + } + public GetOperation[] Get(string workspaceName, string ownerName, GetRequest[] requests, bool force, bool noGet) { diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlLabel.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlLabel.cs index 06fcbca..b9594af 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlLabel.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlLabel.cs @@ -59,6 +59,7 @@ namespace Microsoft.TeamFoundation.VersionControl.Client this.ownerName = ownerName; this.scope = scope; this.comment = comment; + this.lastModifiedDate = new DateTime(1); } internal static VersionControlLabel FromXml(Repository repository, XmlReader reader) @@ -96,6 +97,19 @@ namespace Microsoft.TeamFoundation.VersionControl.Client return label; } + internal void ToXml(XmlWriter writer, string element) + { + writer.WriteStartElement(element); + writer.WriteAttributeString("date", LastModifiedDate.ToString("s")); + writer.WriteAttributeString("name", Name); + + if (!String.IsNullOrEmpty(OwnerName)) writer.WriteAttributeString("owner", OwnerName); + if (!String.IsNullOrEmpty(Scope)) writer.WriteAttributeString("scope", Scope); + + writer.WriteAttributeString("lid", LabelId.ToString()); + writer.WriteEndElement(); + } + public override string ToString() { StringBuilder sb = new StringBuilder(); diff --git a/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs b/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs index 1d6870d..5848954 100644 --- a/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs +++ b/class/Microsoft.TeamFoundation.VersionControl.Client/VersionControlServer.cs @@ -61,10 +61,11 @@ namespace Microsoft.TeamFoundation.VersionControl.Client } public LabelResult[] CreateLabel (VersionControlLabel label, - LabelItemSpec[] itemSpecs, - LabelChildOption options) + LabelItemSpec[] labelSpecs, + LabelChildOption childOption) { - return new LabelResult[1]; + Workspace workspace = GetWorkspace(labelSpecs[0].ItemSpec.Item); + return repository.LabelItem(workspace, label, labelSpecs, childOption); } public Workspace CreateWorkspace(string name, string owner) diff --git a/tools/tf/LabelCommand.cs b/tools/tf/LabelCommand.cs index 1dd22b6..5ac358e 100644 --- a/tools/tf/LabelCommand.cs +++ b/tools/tf/LabelCommand.cs @@ -50,7 +50,7 @@ class LabelCommand : Command } string labelName = Arguments[1]; - string itemPath = Arguments[2]; + string itemPath = Path.GetFullPath(Arguments[2]); // parse arguments LabelChildOption childOption = (LabelChildOption) Enum.Parse(typeof(LabelChildOption), Options.Child, true); @@ -58,13 +58,20 @@ class LabelCommand : Command ItemSpec itemSpec = new ItemSpec(itemPath, rtype); VersionControlLabel label = new VersionControlLabel(VersionControlServer, labelName, - Options.Owner, null, Options.Comment); + Owner, null, Options.Comment); List labelItemSpecs = new List(); - labelItemSpecs.Add(new LabelItemSpec(itemSpec, Version, false)); + Workspace workspace = GetWorkspaceFromCache(); - LabelResult[] result = VersionControlServer.CreateLabel(label, labelItemSpecs.ToArray(), - childOption); + labelItemSpecs.Add(new LabelItemSpec(itemSpec, new WorkspaceVersionSpec(workspace), false)); + LabelResult[] results = VersionControlServer.CreateLabel(label, labelItemSpecs.ToArray(), + childOption); + + foreach (LabelResult result in results) + { + Console.WriteLine("{0} label {1}@{2}", result.Status, result.Label, + result.Scope); + } } } -- 2.11.4.GIT