Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions src/Mercurial.Net/PersistentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ public void Execute(IMercurialCommand command)

var commandParts = arguments.ToArray();

string commandEncoded = string.Join("\0", commandParts.Select(p => p.Trim('"')).ToArray());
int length = commandEncoded.Length;
var commandBuffer = new StringBuilder();
commandBuffer.Append("runcommand\n");
commandBuffer.Append((char)((length >> 24) & 0xff));
commandBuffer.Append((char)((length >> 16) & 0xff));
commandBuffer.Append((char)((length >> 8) & 0xff));
commandBuffer.Append((char)(length & 0xff));
commandBuffer.Append(commandEncoded);

string commandArguments = null;
if (command.Observer != null)
{
Expand All @@ -139,23 +129,13 @@ public void Execute(IMercurialCommand command)
_codec.GetString(error.GetBuffer(), 0, (int)error.Length),
resultCode);

if (resultCode == 0 || !string.IsNullOrEmpty(result.Output))
if (command.Observer != null)
{
if (command.Observer != null)
{
command.Observer.Output(result.Output);
command.Observer.ErrorOutput(result.Error);
command.Observer.Executed(command.Command, commandArguments, resultCode, result.Output, result.Error);
}
command.After(resultCode, result.Output, result.Error);
return;
command.Observer.Output(result.Output);
command.Observer.ErrorOutput(result.Error);
command.Observer.Executed(command.Command, commandArguments, resultCode, result.Output, result.Error);
}

StopPersistentMercurialClient();
throw new MercurialExecutionException(
string.IsNullOrEmpty(result.Error) ?
"Unable to decode output from executing command, spinning down persistent client"
: result.Error);
command.After(resultCode, result.Output, result.Error);
}

internal static int ReadInt(byte[] buffer, int offset)
Expand All @@ -179,7 +159,8 @@ private int RunCommand(IList<string> command,
byte[] argumentBuffer;

argumentBuffer = command.Aggregate(new List<byte>(), (bytes, arg) => {
bytes.AddRange(_codec.GetBytes(arg));
// Trim surrounding double quotes for persistent client
bytes.AddRange(_codec.GetBytes(arg.Trim('"')));
bytes.Add(0);
return bytes;
},
Expand Down Expand Up @@ -394,10 +375,6 @@ public static bool IsSupported(string repositoryPath)
if (!Directory.Exists(repositoryPath))
return false;

// TODO: Determine if we need to check if the .hg folder is an actual repository
if (!Directory.Exists(Path.Combine(repositoryPath, ".hg")))
return false;

if (ClientExecutable.CurrentVersion < new Version(1, 9, 0, 0))
return false;

Expand Down