コード例 #1
0
 public void StoreState()
 {
     if (Hd != null)
     {
         File.WriteAllBytes(GitStateFile, ByteHelper.Serialize(Hd));
     }
 }
コード例 #2
0
        public void PushBranch(Remote remote, string branch, Branch branchInfo, Id fromPosition, KeyValuePair <Id, CommitNode>[] nodes)
        {
            var request = new GitPushBranchRequest()
            {
                Branch = branch, BranchInfo = branchInfo, LatestRemoteBranchPosition = fromPosition, Commits = nodes
            };
            var result = new HttpClient().PostAsync(remote.Url, new ByteArrayContent(ByteHelper.Serialize(request))).GetAwaiter().GetResult();

            Console.WriteLine($"Push status: {result.StatusCode}");
        }
コード例 #3
0
        public void StartDaemon(int port)
        {
            Console.WriteLine($"Serving on http://localhost:{port}/");

            listener = new HttpListener();
            listener.Prefixes.Add($"http://localhost:{port}/");
            listener.Start();

            Running = true;
            while (Running.Value)
            {
                var context = listener.GetContext();

                try
                {
                    if (context.Request.HttpMethod == "GET")
                    {
                        var branch = context.Request.QueryString.Get("branch");

                        if (!git.Hd.Branches.ContainsKey(branch))
                        {
                            context.Response.StatusCode = 404;
                            context.Response.Close();
                            continue;
                        }

                        context.Response.Close(ByteHelper.Serialize(new GitPullResponse()
                        {
                            BranchInfo = git.Hd.Branches[branch],
                            Commits    = git.GetReachableNodes(git.Hd.Branches[branch].Tip).ToArray()
                        }), true);
                    }

                    if (context.Request.HttpMethod == "POST")
                    {
                        var req = ByteHelper.Deserialize <GitPushBranchRequest>(context.Request.InputStream);
                        // todo check if we are loosing commits when updating the branch pointer..we get a fromid with the request
                        git.RawImportCommits(req.Commits, req.Branch, req.BranchInfo);
                        context.Response.Close();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"\n\n{DateTime.Now}\n{e} - {e.Message}");
                    context.Response.StatusCode = 500;
                    context.Response.Close();
                }
            }
        }