Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 46 additions & 15 deletions lib/src/cc_op_heads_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,58 @@ 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<Self, Box<dyn std::error::Error + Send + Sync>> {
let config = CommitCloudConfig::load_from_store(store_path)?;
Ok(Self {
server_url: config.server_url,
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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently unused, right? Or did I miss something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, currently unused but useful in the future (for read only checking for errors, visibility into repo state without modification, etc)

Added a comment clarifying that it is unused

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At Google we have a get_op_heads_without_reconciliation in our internal OpHeadsStore implementation that we use for a few commands that should modify repo state, for example for filing bug reports.

This LGTM.

&self,
) -> Result<Vec<OperationId>, 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<OperationId> = 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<Vec<OperationId>, 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]
Expand Down Expand Up @@ -69,21 +114,7 @@ impl OpHeadsStore for CommitCloudOpHeadsStore {
}

async fn get_op_heads(&self) -> Result<Vec<OperationId>, 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<OperationId> = 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<Box<dyn OpHeadsStoreLock + '_>, OpHeadsStoreError> {
Expand Down