Skip to content

Commit

Permalink
lib: replace protobuf crate with prost
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Dec 21, 2022
1 parent 722f8ff commit 8fd0841
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 144 deletions.
95 changes: 65 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "../README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
protobuf-codegen = "3.2.0"
prost-build = "0.11.5"
version_check = "0.9.4"

[dependencies]
Expand All @@ -32,7 +32,6 @@ maplit = "1.0.2"
once_cell = "1.16.0"
pest = "2.5.1"
pest_derive = "2.5.1"
protobuf = { version = "3.0.1", features = ["with-bytes"] }
regex = "1.7.0"
serde_json = "1.0.91"
tempfile = "3.3.0"
Expand All @@ -42,6 +41,7 @@ uuid = { version = "1.2.2", features = ["v4"] }
whoami = "1.2.3"
zstd = "0.12.1"
tracing = "0.1.37"
prost = "0.11.5"

[dev-dependencies]
assert_matches = "1.5.0"
Expand Down
12 changes: 5 additions & 7 deletions lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

fn main() {
fn main() -> std::io::Result<()> {
let input = &[
"src/protos/op_store.proto",
"src/protos/store.proto",
"src/protos/working_copy.proto",
];
protobuf_codegen::Codegen::new()
.pure()
.inputs(input)
.include("src/protos")
.cargo_out_dir("protos")
.run_from_script();
prost_build::compile_protos(input, &["src/protos/"])?;

println!("cargo:rerun-if-changed=build.rs");
for file in input {
println!("cargo:rerun-if-changed={file}");
Expand All @@ -32,4 +28,6 @@ fn main() {
if let Some(true) = version_check::supports_feature("map_first_last") {
println!("cargo:rustc-cfg=feature=\"map_first_last\"");
}

Ok(())
}
9 changes: 4 additions & 5 deletions lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::{Arc, Mutex};

use git2::Oid;
use itertools::Itertools;
use protobuf::Message;
use prost::Message;
use uuid::Uuid;

use crate::backend::{
Expand Down Expand Up @@ -126,17 +126,16 @@ fn signature_to_git(signature: &Signature) -> git2::Signature {
}

fn serialize_extras(commit: &Commit) -> Vec<u8> {
let mut proto = crate::protos::store::Commit::new();
let mut proto = crate::protos::store::Commit::default();
proto.change_id = commit.change_id.to_bytes();
for predecessor in &commit.predecessors {
proto.predecessors.push(predecessor.to_bytes());
}
proto.write_to_bytes().unwrap()
proto.encode_to_vec()
}

fn deserialize_extras(commit: &mut Commit, bytes: &[u8]) {
let mut cursor = Cursor::new(bytes);
let proto: crate::protos::store::Commit = Message::parse_from_reader(&mut cursor).unwrap();
let proto = crate::protos::store::Commit::decode(bytes).unwrap();
commit.change_id = ChangeId::new(proto.change_id);
for predecessor in &proto.predecessors {
commit.predecessors.push(CommitId::from_bytes(predecessor));
Expand Down
Loading

0 comments on commit 8fd0841

Please sign in to comment.