Example #1
0
        private static void ReportFailure(HttpResponseBase response, int?reportBand, Dictionary <ProtocolUtils.UpdateRequest, string> errors, string message)
        {
            if (reportBand == ProtocolUtils.ErrorBand)
            {
                response.BinaryWrite(ProtocolUtils.Band(ProtocolUtils.MessageBand,
                                                        ProtocolUtils.DefaultEncoding.GetBytes(string.Format("{0}\n", message))));

                foreach (var e in errors)
                {
                    response.BinaryWrite(ProtocolUtils.Band(ProtocolUtils.MessageBand,
                                                            ProtocolUtils.DefaultEncoding.GetBytes(string.Format("{0} ({1})\n", e.Key.CanonicalName, e.Value ?? "not created, see other errors"))));
                }

                response.BinaryWrite(ProtocolUtils.Band(ProtocolUtils.ErrorBand, ProtocolUtils.DefaultEncoding.GetBytes("code review creation aborted\n")));
            }
            else
            {
                var status = new List <byte[]>();

                status.Add(ProtocolUtils.PacketLine(string.Format("unpack {0}\n", message)));

                foreach (var e in errors)
                {
                    status.Add(ProtocolUtils.PacketLine(string.Format("ng {0} {1}\n", e.Key.CanonicalName, e.Value ?? "not created, see other errors")));
                }

                status.Add(ProtocolUtils.EndMarker);

                response.BinaryWrite(ProtocolUtils.Band(reportBand, status));
            }
        }
Example #2
0
        /// <inheritdoc />
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;

            response.StatusCode  = 200;
            response.ContentType = "application/x-" + this.service + "-advertisement";
            response.BinaryWrite(ProtocolUtils.PacketLine("# service=" + this.service + "\n"));
            response.BinaryWrite(ProtocolUtils.EndMarker);

            var ids = new SortedSet <string>(this.repo.Refs.Select(r => r.TargetIdentifier));

            var first = true;

            foreach (var id in ids)
            {
                var line = first
                    ? string.Format("{0} refs/anonymous/{0}\0{1}\n", id, this.GetCapabilities())
                    : string.Format("{0} refs/anonymous/{0}\n", id);

                response.BinaryWrite(ProtocolUtils.PacketLine(line));

                first = false;
            }

            if (first)
            {
                var line = string.Format("{0} capabilities^{{}}\0{1}\n", ProtocolUtils.ZeroId, this.GetCapabilities());

                response.BinaryWrite(ProtocolUtils.PacketLine(line));
            }

            response.BinaryWrite(ProtocolUtils.EndMarker);
            response.End();
        }
Example #3
0
 private static void ReportSuccess(HttpResponseBase response, int?reportBand)
 {
     response.BinaryWrite(ProtocolUtils.Band(reportBand,
                                             ProtocolUtils.PacketLine("unpack ok\n"),
                                             ProtocolUtils.PacketLine("ok " + DestinationRefName + "\n"),
                                             ProtocolUtils.PacketLine("ok " + SourceRefName + "\n"),
                                             ProtocolUtils.EndMarker));
 }
Example #4
0
        private MemoryStream ReadPack(IList <ProtocolUtils.UpdateRequest> commands, HashSet <string> capabilities, Stream input)
        {
            var startInfo = new ProcessStartInfo(GitReviewApplication.GitPath, "receive-pack --stateless-rpc .")
            {
                WorkingDirectory       = GitReviewApplication.RepositoryPath,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                StandardOutputEncoding = ProtocolUtils.DefaultEncoding,
                UseShellExecute        = false,
            };

            var output = new MemoryStream();

            using (var git = Process.Start(startInfo))
            {
                var outputTask = Task.Factory.StartNew(() =>
                {
                    git.StandardOutput.BaseStream.CopyTo(output);
                });

                var first = true;
                foreach (var c in commands)
                {
                    var message = string.Format("{0} {1} {2}",
                                                c.SourceIdentifier ?? ProtocolUtils.ZeroId,
                                                c.TargetIdentifier ?? ProtocolUtils.ZeroId,
                                                c.CanonicalName);

                    if (first)
                    {
                        message += "\0atomic report-status";
                    }

                    var data = ProtocolUtils.PacketLine(message);
                    git.StandardInput.BaseStream.Write(data, 0, data.Length);

                    first = false;
                }

                var marker = ProtocolUtils.EndMarker;
                git.StandardInput.BaseStream.Write(marker, 0, marker.Length);

                input.CopyTo(git.StandardInput.BaseStream);
                git.StandardInput.Close();
                git.WaitForExit();
                outputTask.Wait();
            }

            output.Seek(0, SeekOrigin.Begin);
            return(output);
        }