From d556734d71131e1c3b85056ab1d071dae96203c3 Mon Sep 17 00:00:00 2001 From: sidsail Date: Thu, 3 Sep 2026 05:27:53 -0700 Subject: [PATCH] lib: add functions for getting op heads Add get_op_heads_with_reconciliation and get_op_heads_without_reconciliation functions. The latter function (without) does not perform a reconciliation operation and just does a Store read to return the heads that are present. The former function just makes an RPC call to the ReconcileOpHeads RPC, which performs reconciliation and returns the resulting resolved head. The vast majority of get_op_heads calls will be made with reconciliation, as jj commands expect a singular op head per repository. --- lib/src/cc_op_heads_store.rs | 61 +++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/lib/src/cc_op_heads_store.rs b/lib/src/cc_op_heads_store.rs index b42c190..2aa4be4 100644 --- a/lib/src/cc_op_heads_store.rs +++ b/lib/src/cc_op_heads_store.rs @@ -23,6 +23,13 @@ impl CommitCloudOpHeadsStore { "commit_cloud" } + pub fn new(server_url: String, repo_id: String) -> Self { + Self { + server_url, + repo_id, + } + } + pub fn load(store_path: &Path) -> Result> { let config = CommitCloudConfig::load_from_store(store_path)?; Ok(Self { @@ -30,6 +37,44 @@ impl CommitCloudOpHeadsStore { repo_id: config.repo_id, }) } + + // Currently unused, the function is implemented here to make the distinction between the 2 functions (this and get_op_heads_with_reconciliation), for future use + pub async fn get_op_heads_without_reconciliation( + &self, + ) -> Result, OpHeadsStoreError> { + let server_url = self.server_url.clone(); + let repo_id = self.repo_id.clone(); + + run_async(move || async move { + let mut client = OpStoreServiceClient::connect(server_url).await?; + let response = client.get_op_heads(GetOpHeadsRequest { repo_id }).await?; + let head_ids: Vec = response + .into_inner() + .op_head_ids + .into_iter() + .map(|b| OperationId::from_bytes(&b)) + .collect(); + Ok(head_ids) + }) + .map_err(|e| OpHeadsStoreError::Read(e.into())) + } + + pub async fn get_op_heads_with_reconciliation( + &self, + ) -> Result, OpHeadsStoreError> { + let server_url = self.server_url.clone(); + let repo_id = self.repo_id.clone(); + + run_async(move || async move { + let mut client = OpStoreServiceClient::connect(server_url).await?; + let response = client + .reconcile_op_heads(ReconcileOpHeadsRequest { repo_id }) + .await?; + let head = OperationId::from_bytes(&response.into_inner().op_head); + Ok(vec![head]) + }) + .map_err(|e| OpHeadsStoreError::Read(e.into())) + } } #[async_trait] @@ -69,21 +114,7 @@ impl OpHeadsStore for CommitCloudOpHeadsStore { } async fn get_op_heads(&self) -> Result, OpHeadsStoreError> { - let server_url = self.server_url.clone(); - let repo_id = self.repo_id.clone(); - - run_async(move || async move { - let mut client = OpStoreServiceClient::connect(server_url).await?; - let response = client.get_op_heads(GetOpHeadsRequest { repo_id }).await?; - let head_ids: Vec = response - .into_inner() - .op_head_ids - .into_iter() - .map(|b| OperationId::from_bytes(&b)) - .collect(); - Ok(head_ids) - }) - .map_err(|e| OpHeadsStoreError::Read(e.into())) + self.get_op_heads_with_reconciliation().await } async fn lock(&self) -> Result, OpHeadsStoreError> {