bookmarks: rename proto symbols from "branch"

Proto fields are identified by the tag (and the message names are not
used), so it's safe to rename them.
This commit is contained in:
Martin von Zweigbergk 2024-09-11 09:46:05 -07:00 committed by Martin von Zweigbergk
parent 1aa2aec141
commit 8d4445d5d1
3 changed files with 25 additions and 25 deletions

View file

@ -43,22 +43,22 @@ enum RemoteRefState {
Tracking = 1;
}
message RemoteBranch {
message RemoteBookmark {
string remote_name = 1;
RefTarget target = 2;
// Introduced in jj 0.11.
optional RemoteRefState state = 3;
}
message Branch {
message Bookmark {
string name = 1;
// Unset if the branch has been deleted locally.
// Unset if the bookmark has been deleted locally.
RefTarget local_target = 2;
// TODO: How would we support renaming remotes while having undo work? If
// the remote name is stored in config, it's going to become a mess if the
// remote is renamed but the configs are left unchanged. Should each remote
// be identified (here and in configs) by a UUID?
repeated RemoteBranch remote_branches = 3;
repeated RemoteBookmark remote_bookmarks = 3;
}
message GitRef {
@ -80,7 +80,7 @@ message View {
reserved 4;
bytes wc_commit_id = 2 [deprecated = true];
map<string, bytes> wc_commit_ids = 8;
repeated Branch branches = 5;
repeated Bookmark bookmarks = 5;
repeated Tag tags = 6;
// Only a subset of the refs. For example, does not include refs/notes/.
repeated GitRef git_refs = 3;
@ -89,7 +89,7 @@ message View {
// TODO: Delete support for the old format.
bytes git_head_legacy = 7 [deprecated = true];
RefTarget git_head = 9;
// Whether "@git" branches have been migrated to remote_targets.
// Whether "@git" bookmark have been migrated to remote_targets.
bool has_git_refs_migrated_to_remote = 10;
}

View file

@ -49,7 +49,7 @@ pub mod ref_target {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RemoteBranch {
pub struct RemoteBookmark {
#[prost(string, tag = "1")]
pub remote_name: ::prost::alloc::string::String,
#[prost(message, optional, tag = "2")]
@ -60,10 +60,10 @@ pub struct RemoteBranch {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Branch {
pub struct Bookmark {
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// Unset if the branch has been deleted locally.
/// Unset if the bookmark has been deleted locally.
#[prost(message, optional, tag = "2")]
pub local_target: ::core::option::Option<RefTarget>,
/// TODO: How would we support renaming remotes while having undo work? If
@ -71,7 +71,7 @@ pub struct Branch {
/// remote is renamed but the configs are left unchanged. Should each remote
/// be identified (here and in configs) by a UUID?
#[prost(message, repeated, tag = "3")]
pub remote_branches: ::prost::alloc::vec::Vec<RemoteBranch>,
pub remote_bookmarks: ::prost::alloc::vec::Vec<RemoteBookmark>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
@ -108,7 +108,7 @@ pub struct View {
::prost::alloc::vec::Vec<u8>,
>,
#[prost(message, repeated, tag = "5")]
pub branches: ::prost::alloc::vec::Vec<Branch>,
pub bookmarks: ::prost::alloc::vec::Vec<Bookmark>,
#[prost(message, repeated, tag = "6")]
pub tags: ::prost::alloc::vec::Vec<Tag>,
/// Only a subset of the refs. For example, does not include refs/notes/.
@ -122,7 +122,7 @@ pub struct View {
pub git_head_legacy: ::prost::alloc::vec::Vec<u8>,
#[prost(message, optional, tag = "9")]
pub git_head: ::core::option::Option<RefTarget>,
/// Whether "@git" branches have been migrated to remote_targets.
/// Whether "@git" bookmark have been migrated to remote_targets.
#[prost(bool, tag = "10")]
pub has_git_refs_migrated_to_remote: bool,
}

View file

@ -436,7 +436,7 @@ fn view_to_proto(view: &View) -> crate::protos::op_store::View {
proto.head_ids.push(head_id.to_bytes());
}
proto.branches = bookmark_views_to_proto_legacy(&view.local_bookmarks, &view.remote_views);
proto.bookmarks = bookmark_views_to_proto_legacy(&view.local_bookmarks, &view.remote_views);
for (name, target) in &view.tags {
proto.tags.push(crate::protos::op_store::Tag {
@ -475,7 +475,7 @@ fn view_from_proto(proto: crate::protos::op_store::View) -> View {
view.head_ids.insert(CommitId::new(head_id_bytes));
}
let (local_bookmarks, remote_views) = bookmark_views_from_proto_legacy(proto.branches);
let (local_bookmarks, remote_views) = bookmark_views_from_proto_legacy(proto.bookmarks);
view.local_bookmarks = local_bookmarks;
view.remote_views = remote_views;
@ -511,7 +511,7 @@ fn view_from_proto(proto: crate::protos::op_store::View) -> View {
fn bookmark_views_to_proto_legacy(
local_bookmarks: &BTreeMap<String, RefTarget>,
remote_views: &BTreeMap<String, RemoteView>,
) -> Vec<crate::protos::op_store::Branch> {
) -> Vec<crate::protos::op_store::Bookmark> {
op_store::merge_join_bookmark_views(local_bookmarks, remote_views)
.map(|(name, bookmark_target)| {
let local_target = ref_target_to_proto(bookmark_target.local_target);
@ -519,30 +519,30 @@ fn bookmark_views_to_proto_legacy(
.remote_refs
.iter()
.map(
|&(remote_name, remote_ref)| crate::protos::op_store::RemoteBranch {
|&(remote_name, remote_ref)| crate::protos::op_store::RemoteBookmark {
remote_name: remote_name.to_owned(),
target: ref_target_to_proto(&remote_ref.target),
state: remote_ref_state_to_proto(remote_ref.state),
},
)
.collect();
crate::protos::op_store::Branch {
crate::protos::op_store::Bookmark {
name: name.to_owned(),
local_target,
remote_branches: remote_bookmarks,
remote_bookmarks,
}
})
.collect()
}
fn bookmark_views_from_proto_legacy(
bookmarks_legacy: Vec<crate::protos::op_store::Branch>,
bookmarks_legacy: Vec<crate::protos::op_store::Bookmark>,
) -> (BTreeMap<String, RefTarget>, BTreeMap<String, RemoteView>) {
let mut local_bookmarks: BTreeMap<String, RefTarget> = BTreeMap::new();
let mut remote_views: BTreeMap<String, RemoteView> = BTreeMap::new();
for bookmark_proto in bookmarks_legacy {
let local_target = ref_target_from_proto(bookmark_proto.local_target);
for remote_bookmark in bookmark_proto.remote_branches {
for remote_bookmark in bookmark_proto.remote_bookmarks {
let state = remote_ref_state_from_proto(remote_bookmark.state).unwrap_or_else(|| {
// If local bookmark doesn't exist, we assume that the remote bookmark hasn't
// been merged because git.auto-local-bookmark was off. That's
@ -905,13 +905,13 @@ mod tests {
state: RemoteRefState::Tracking,
};
let bookmark_to_proto =
|name: &str, local_ref_target, remote_branches| crate::protos::op_store::Branch {
|name: &str, local_ref_target, remote_bookmarks| crate::protos::op_store::Bookmark {
name: name.to_owned(),
local_target: ref_target_to_proto(local_ref_target),
remote_branches,
remote_bookmarks,
};
let remote_bookmark_to_proto =
|remote_name: &str, ref_target| crate::protos::op_store::RemoteBranch {
|remote_name: &str, ref_target| crate::protos::op_store::RemoteBookmark {
remote_name: remote_name.to_owned(),
target: ref_target_to_proto(ref_target),
state: None, // to be generated based on local bookmark existence
@ -923,7 +923,7 @@ mod tests {
};
let proto = crate::protos::op_store::View {
branches: vec![
bookmarks: vec![
bookmark_to_proto(
"main",
&normal_ref_target("111111"),
@ -986,7 +986,7 @@ mod tests {
// Once migrated, "git" remote bookmarks shouldn't be populated again.
let mut proto = view_to_proto(&view);
assert!(proto.has_git_refs_migrated_to_remote);
proto.branches.clear();
proto.bookmarks.clear();
let view = view_from_proto(proto);
assert!(!view.remote_views.contains_key("git"));
}