public ListBranches ( ) : Tuple
|
||
return | Tuple
|
public Tuple<List<Objects.Branch>, List<KeyValuePair<Guid, Guid>>, Dictionary<Guid, Objects.Version>> ListBranches()
{
ReceivedData = false;
if (Workspace == null)
return null;
if (string.IsNullOrEmpty(RemoteDomain))
{
Printer.PrintError("#x#Error:##\n Remote vault is not yet initialized. No branches on server.");
return null;
}
try
{
if (SharedInfo.CommunicationProtocol < SharedNetwork.Protocol.Versionr32)
{
Printer.PrintError("#e#Server does not support multi-branch queries.");
return null;
}
ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.ListBranches, Identifier = 1 }, ProtoBuf.PrefixStyle.Fixed32);
var queryResult = ProtoBuf.Serializer.DeserializeWithLengthPrefix<NetCommand>(Connection.GetStream(), ProtoBuf.PrefixStyle.Fixed32);
if (queryResult.Type == NetCommandType.Error)
{
Printer.PrintError("Couldn't get branch list - error: {0}", queryResult.AdditionalPayload);
return null;
}
BranchList list = Utilities.ReceiveEncrypted<BranchList>(SharedInfo);
Dictionary<Guid, Objects.Version> importantVersions = new Dictionary<Guid, Objects.Version>();
foreach (var x in list.ImportantVersions)
importantVersions[x.ID] = x;
return new Tuple<List<Branch>, List<KeyValuePair<Guid, Guid>>, Dictionary<Guid, Objects.Version>>(list.Branches.ToList(), list.Heads.ToList(), importantVersions);
}
catch (Exception e)
{
Printer.PrintError("Error: {0}", e);
Close();
return null;
}
}
protected override bool RunInternal(Client client, RemoteCommandVerbOptions options) { PullVerbOptions localOptions = options as PullVerbOptions; bool objects = true; if (localOptions.PullAll) objects = false; if (localOptions.List) { var branches = client.ListBranches(); if (branches == null) return false; Printer.PrintMessage("Displaying remote branches:"); foreach (var x in branches.Item1) { if (!localOptions.Deleted && x.Terminus.HasValue) continue; string tipmarker = ""; if (x.ID == client.Workspace.CurrentBranch.ID) tipmarker = " #w#*<current>##"; Printer.PrintMessage("#b#{1}## - #c#{0}##{2}", x.ID, x.Name, tipmarker); string heading = string.Empty; var localBranch = client.Workspace.GetBranch(x.ID); if (x.Terminus.HasValue) { var terminus = branches.Item3[x.Terminus.Value]; bool present = client.Workspace.GetVersion(x.Terminus.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { if (localBranch.Terminus.Value != x.Terminus.Value) presentMarker += " #w#(ahead)##"; } if (localBranch != null && !localBranch.Terminus.HasValue) presentMarker += " #w#(not locally deleted)##"; if (localBranch == null) presentMarker += " #w#(not synchronized)##"; Printer.PrintMessage(" #e#(deleted)## - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker); } foreach (var z in branches.Item2.Where(y => y.Key == x.ID)) { bool present = client.Workspace.GetVersion(z.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { var localHeads = client.Workspace.GetBranchHeads(localBranch); if (localHeads.Count == 1 && localHeads[0].Version != z.Value) presentMarker += " #w#(ahead)##"; } if (localBranch != null && localBranch.Terminus.HasValue) presentMarker += " #e#(locally deleted)##"; if (localBranch == null) presentMarker += " #w#(not synchronized)##"; var head = branches.Item3[z.Value]; Printer.PrintMessage(" #s#(head)## - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker); } } return true; } if (!client.Pull(localOptions.PullObjects.HasValue ? localOptions.PullObjects.Value : objects, localOptions.RemoteBranch, localOptions.PullAll)) return false; if (localOptions.Update) { client.Workspace.Update(); } return true; }