From 589e0db3c53804129bf6a609500e3edb9e881b87 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 24 Aug 2023 21:41:24 -0700 Subject: [PATCH] git_backend: remove unused proto field for resolved tree id We store resolved tree ids in the regular Git commit, so we we never ended up using the `resolved` variant in the `root_tree`. --- lib/src/git_backend.rs | 41 +++++++++++++--------------------- lib/src/protos/git_store.proto | 6 ++--- lib/src/protos/git_store.rs | 16 +++---------- 3 files changed, 21 insertions(+), 42 deletions(-) diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index c34653499..d7a575d1a 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -293,7 +293,7 @@ fn serialize_extras(commit: &Commit) -> Vec { uses_tree_conflict_format: commit.uses_tree_conflict_format, ..Default::default() }; - if commit.root_tree.as_resolved().is_none() { + if !commit.root_tree.is_resolved() { assert!(commit.uses_tree_conflict_format); let removes = commit .root_tree @@ -307,10 +307,7 @@ fn serialize_extras(commit: &Commit) -> Vec { .iter() .map(|r| r.to_bytes()) .collect_vec(); - let conflict = crate::protos::git_store::TreeConflict { removes, adds }; - proto.root_tree = Some(crate::protos::git_store::commit::RootTree::Conflict( - conflict, - )); + proto.root_tree = Some(crate::protos::git_store::TreeConflict { removes, adds }); } for predecessor in &commit.predecessors { proto.predecessors.push(predecessor.to_bytes()); @@ -322,26 +319,20 @@ fn deserialize_extras(commit: &mut Commit, bytes: &[u8]) { let proto = crate::protos::git_store::Commit::decode(bytes).unwrap(); commit.change_id = ChangeId::new(proto.change_id); commit.uses_tree_conflict_format = proto.uses_tree_conflict_format; - match proto.root_tree { - Some(crate::protos::git_store::commit::RootTree::Conflict(proto_conflict)) => { - assert!(commit.uses_tree_conflict_format); - commit.root_tree = Merge::new( - proto_conflict - .removes - .iter() - .map(|id_bytes| TreeId::from_bytes(id_bytes)) - .collect(), - proto_conflict - .adds - .iter() - .map(|id_bytes| TreeId::from_bytes(id_bytes)) - .collect(), - ); - } - Some(crate::protos::git_store::commit::RootTree::Resolved(_)) => { - panic!("found resolved root tree in extras (should only be written to git metadata)"); - } - None => {} + if let Some(proto_conflict) = proto.root_tree { + assert!(commit.uses_tree_conflict_format); + commit.root_tree = Merge::new( + proto_conflict + .removes + .iter() + .map(|id_bytes| TreeId::from_bytes(id_bytes)) + .collect(), + proto_conflict + .adds + .iter() + .map(|id_bytes| TreeId::from_bytes(id_bytes)) + .collect(), + ); } for predecessor in &proto.predecessors { commit.predecessors.push(CommitId::from_bytes(predecessor)); diff --git a/lib/src/protos/git_store.proto b/lib/src/protos/git_store.proto index 67a39e5d8..450716420 100644 --- a/lib/src/protos/git_store.proto +++ b/lib/src/protos/git_store.proto @@ -25,10 +25,8 @@ message Commit { repeated bytes predecessors = 2; bytes change_id = 4; - oneof root_tree { - bytes resolved = 3; - TreeConflict conflict = 1; - } + // Set only for conflicts. Resolved trees are stored in the git commit + TreeConflict root_tree = 1; // TODO(#1624): delete when we assume that all commits use this format bool uses_tree_conflict_format = 10; diff --git a/lib/src/protos/git_store.rs b/lib/src/protos/git_store.rs index 70df97ab8..8f9fc01ca 100644 --- a/lib/src/protos/git_store.rs +++ b/lib/src/protos/git_store.rs @@ -13,6 +13,9 @@ pub struct Commit { pub predecessors: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, #[prost(bytes = "vec", tag = "4")] pub change_id: ::prost::alloc::vec::Vec, + /// Set only for conflicts. Resolved trees are stored in the git commit + #[prost(message, optional, tag = "1")] + pub root_tree: ::core::option::Option, /// TODO(#1624): delete when we assume that all commits use this format #[prost(bool, tag = "10")] pub uses_tree_conflict_format: bool, @@ -22,17 +25,4 @@ pub struct Commit { #[deprecated] #[prost(bool, tag = "9")] pub is_pruned: bool, - #[prost(oneof = "commit::RootTree", tags = "3, 1")] - pub root_tree: ::core::option::Option, -} -/// Nested message and enum types in `Commit`. -pub mod commit { - #[allow(clippy::derive_partial_eq_without_eq)] - #[derive(Clone, PartialEq, ::prost::Oneof)] - pub enum RootTree { - #[prost(bytes, tag = "3")] - Resolved(::prost::alloc::vec::Vec), - #[prost(message, tag = "1")] - Conflict(super::TreeConflict), - } }