delta push service
This commit is contained in:
@@ -57,6 +57,9 @@ message CloneResponse {}
|
||||
|
||||
message PushRequest {
|
||||
string author_name = 1;
|
||||
string repository_name= 2;
|
||||
string branch_name = 3;
|
||||
repeated Commit commits = 4;
|
||||
}
|
||||
message PushResponse {}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <grpcpp/health_check_service_interface.h>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "src/app/delta/delta.grpc.pb.h"
|
||||
#include "src/app/delta/delta.pb.h"
|
||||
|
||||
@@ -22,13 +23,42 @@ using grpc::Server;
|
||||
using grpc::ServerBuilder;
|
||||
using grpc::Status;
|
||||
|
||||
namespace {
|
||||
auto FindRepository(std::vector<Repository>& repos, const std::string& name) {
|
||||
for (auto& repo : repos) {
|
||||
if (repo.project_name() == name) {
|
||||
return repo.mutable_tree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto FindBranch(google::protobuf::RepeatedPtrField<Branch>* repo,
|
||||
const std::string& branch_name) {
|
||||
for (auto it = repo->begin(); it != repo->end(); ++it) {
|
||||
if (it->branch_name() == branch_name) {
|
||||
return it->mutable_commits();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Status DeltaService::Init(grpc::ServerContext* context,
|
||||
const InitRequest* request, InitResponse* reply) {
|
||||
std::filesystem::create_directories("./.yaze");
|
||||
repos_.push_back(request->repo());
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status DeltaService::Push(grpc::ServerContext* context,
|
||||
const PushRequest* request, PushResponse* reply) {
|
||||
const auto& repository_name = request->repository_name();
|
||||
const auto& branch_name = request->branch_name();
|
||||
auto repo = FindRepository(repos_, repository_name);
|
||||
auto mutable_commits = FindBranch(repo, branch_name);
|
||||
auto size = request->commits().size();
|
||||
for (int i = 1; i < size; ++i) {
|
||||
*mutable_commits->Add() = request->commits().at(i);
|
||||
}
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
@@ -37,6 +67,11 @@ Status DeltaService::Pull(grpc::ServerContext* context,
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status DeltaService::Clone(grpc::ServerContext* context,
|
||||
const CloneRequest* request, CloneResponse* reply) {
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
} // namespace delta
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef YAZE_APP_DELTA_SERVICE_H
|
||||
#define YAZE_APP_DELTA_SERVICE_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <google/protobuf/message.h>
|
||||
#include <grpc/support/log.h>
|
||||
#include <grpcpp/ext/proto_server_reflection_plugin.h>
|
||||
@@ -17,6 +19,8 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace delta {
|
||||
|
||||
using grpc::Status;
|
||||
|
||||
class DeltaService final : public ::YazeDelta::Service {
|
||||
public:
|
||||
Status Init(grpc::ServerContext* context, const InitRequest* request,
|
||||
@@ -28,6 +32,11 @@ class DeltaService final : public ::YazeDelta::Service {
|
||||
Status Pull(grpc::ServerContext* context, const PullRequest* request,
|
||||
PullResponse* reply) override;
|
||||
|
||||
Status Clone(grpc::ServerContext* context, const CloneRequest* request,
|
||||
CloneResponse* reply) override;
|
||||
|
||||
auto Repos() const { return repos_; }
|
||||
|
||||
private:
|
||||
std::vector<Repository> repos_;
|
||||
};
|
||||
@@ -35,3 +44,5 @@ class DeltaService final : public ::YazeDelta::Service {
|
||||
} // namespace delta
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
@@ -104,6 +104,9 @@ class ROM {
|
||||
auto begin() { return rom_data_.begin(); }
|
||||
auto end() { return rom_data_.end(); }
|
||||
auto data() { return rom_data_.data(); }
|
||||
auto char_data() {
|
||||
return reinterpret_cast<char*>(rom_data_.data());
|
||||
}
|
||||
auto size() const { return size_; }
|
||||
|
||||
uchar& operator[](int i) {
|
||||
|
||||
Reference in New Issue
Block a user