Skip to content

Commit

Permalink
lib: add topic metadata to view
Browse files Browse the repository at this point in the history
  • Loading branch information
noahmayr committed May 4, 2024
1 parent 5322c1d commit 4f41994
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/src/commands/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ fn view_with_desired_portions_restored(
head_ids: repo_source.head_ids.clone(),
local_branches: repo_source.local_branches.clone(),
tags: repo_source.tags.clone(),
topics: repo_source.topics.clone(),
remote_views: remote_source.remote_views.clone(),
git_refs: current_view.git_refs.clone(),
git_head: current_view.git_head.clone(),
Expand Down
1 change: 1 addition & 0 deletions lib/src/op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ pub struct View {
pub head_ids: HashSet<CommitId>,
pub local_branches: BTreeMap<String, RefTarget>,
pub tags: BTreeMap<String, RefTarget>,
pub topics: BTreeMap<String, HashSet<CommitId>>,
pub remote_views: BTreeMap<String, RemoteView>,
pub git_refs: BTreeMap<String, RefTarget>,
/// The commit the Git HEAD points to.
Expand Down
6 changes: 6 additions & 0 deletions lib/src/protos/op_store.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ message Tag {
RefTarget target = 2;
}

message Topic {
string name = 1;
repeated bytes commit_ids = 2;
}

message View {
repeated bytes head_ids = 1;
reserved 4;
bytes wc_commit_id = 2 [deprecated = true];
map<string, bytes> wc_commit_ids = 8;
repeated Branch branches = 5;
repeated Tag tags = 6;
repeated Topic topics = 11;
// Only a subset of the refs. For example, does not include refs/notes/.
repeated GitRef git_refs = 3;
// This field is just for historical reasons (before we had the RefTarget
Expand Down
10 changes: 10 additions & 0 deletions lib/src/protos/op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ pub struct Tag {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Topic {
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
#[prost(bytes = "vec", repeated, tag = "2")]
pub commit_ids: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct View {
#[prost(bytes = "vec", repeated, tag = "1")]
pub head_ids: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
Expand All @@ -111,6 +119,8 @@ pub struct View {
pub branches: ::prost::alloc::vec::Vec<Branch>,
#[prost(message, repeated, tag = "6")]
pub tags: ::prost::alloc::vec::Vec<Tag>,
#[prost(message, repeated, tag = "11")]
pub topics: ::prost::alloc::vec::Vec<Topic>,
/// Only a subset of the refs. For example, does not include refs/notes/.
#[prost(message, repeated, tag = "3")]
pub git_refs: ::prost::alloc::vec::Vec<GitRef>,
Expand Down
22 changes: 22 additions & 0 deletions lib/src/simple_op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ fn view_to_proto(view: &View) -> crate::protos::op_store::View {
});
}

for (name, commit_ids) in &view.topics {
proto.topics.push(crate::protos::op_store::Topic {
name: name.clone(),
commit_ids: commit_ids.iter().map(|id| id.to_bytes()).collect(),
});
}

for (git_ref_name, target) in &view.git_refs {
proto.git_refs.push(crate::protos::op_store::GitRef {
name: git_ref_name.clone(),
Expand Down Expand Up @@ -463,6 +470,18 @@ fn view_from_proto(proto: crate::protos::op_store::View) -> View {
.insert(tag_proto.name, ref_target_from_proto(tag_proto.target));
}

for topic_proto in proto.topics {
view.topics.insert(
topic_proto.name,
topic_proto
.commit_ids
.iter()
.cloned()
.map(CommitId::new)
.collect(),
);
}

for git_ref in proto.git_refs {
let target = if git_ref.target.is_some() {
ref_target_from_proto(git_ref.target)
Expand Down Expand Up @@ -716,6 +735,9 @@ mod tests {
tags: btreemap! {
"v1.0".to_string() => tag_v1_target,
},
topics: btreemap! {
"topic".to_string() => hashset![CommitId::from_hex("ccc111"), CommitId::from_hex("ccc222")],
},
remote_views: btreemap! {
"origin".to_string() => RemoteView {
branches: btreemap! {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ impl View {
head_ids,
local_branches,
tags,
topics,
remote_views,
git_refs,
git_head,
Expand All @@ -352,6 +353,7 @@ impl View {
itertools::chain!(
head_ids,
local_branches.values().flat_map(ref_target_ids),
topics.values().flatten(),
tags.values().flat_map(ref_target_ids),
remote_views.values().flat_map(|remote_view| {
let op_store::RemoteView { branches } = remote_view;
Expand Down

0 comments on commit 4f41994

Please sign in to comment.