Skip to content

feat: Richer tags api #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ pub struct HashAndFormat {
pub format: BlobFormat,
}

impl From<Hash> for HashAndFormat {
fn from(hash: Hash) -> Self {
Self::raw(hash)
}
}

#[cfg(feature = "redb")]
mod redb_support {
use postcard::experimental::max_size::MaxSize;
Expand Down
45 changes: 24 additions & 21 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use proto::{
},
tags::{
CreateRequest as TagsCreateRequest, DeleteRequest as TagDeleteRequest,
ListRequest as TagListRequest, SetRequest as TagsSetRequest, SyncMode,
ListRequest as TagListRequest, RenameRequest, SetRequest as TagsSetRequest, SyncMode,
},
Request, RpcError, RpcResult, RpcService,
};
Expand Down Expand Up @@ -158,6 +158,7 @@ impl<D: crate::store::Store> Handler<D> {
Set(msg) => chan.rpc(msg, self, Self::tags_set).await,
DeleteTag(msg) => chan.rpc(msg, self, Self::blob_delete_tag).await,
ListTags(msg) => chan.server_streaming(msg, self, Self::blob_list_tags).await,
Rename(msg) => chan.rpc(msg, self, Self::tags_rename).await,
}
}

Expand Down Expand Up @@ -295,7 +296,7 @@ impl<D: crate::store::Store> Handler<D> {

async fn blob_delete_tag(self, msg: TagDeleteRequest) -> RpcResult<()> {
self.store()
.set_tag(msg.name, None)
.delete_tags(msg.from, msg.to)
.await
.map_err(|e| RpcError::new(&e))?;
Ok(())
Expand All @@ -313,7 +314,7 @@ impl<D: crate::store::Store> Handler<D> {
tracing::info!("blob_list_tags");
let blobs = self;
Gen::new(|co| async move {
let tags = blobs.store().tags().await.unwrap();
let tags = blobs.store().tags(msg.from, msg.to).await.unwrap();
#[allow(clippy::manual_flatten)]
for item in tags {
if let Ok((name, HashAndFormat { hash, format })) = item {
Expand Down Expand Up @@ -382,6 +383,16 @@ impl<D: crate::store::Store> Handler<D> {
rx.map(AddPathResponse)
}

async fn tags_rename(self, msg: RenameRequest) -> RpcResult<()> {
let blobs = self;
blobs
.store()
.rename_tag(msg.from, msg.to)
.await
.map_err(|e| RpcError::new(&e))?;
Ok(())
}

async fn tags_set(self, msg: TagsSetRequest) -> RpcResult<()> {
let blobs = self;
blobs
Expand All @@ -393,13 +404,11 @@ impl<D: crate::store::Store> Handler<D> {
blobs.store().sync().await.map_err(|e| RpcError::new(&e))?;
}
if let Some(batch) = msg.batch {
if let Some(content) = msg.value.as_ref() {
blobs
.batches()
.await
.remove_one(batch, content)
.map_err(|e| RpcError::new(&*e))?;
}
blobs
.batches()
.await
.remove_one(batch, &msg.value)
.map_err(|e| RpcError::new(&*e))?;
}
Ok(())
}
Expand Down Expand Up @@ -572,10 +581,7 @@ impl<D: crate::store::Store> Handler<D> {
let HashAndFormat { hash, format } = *hash_and_format;
let tag = match tag {
SetTagOption::Named(tag) => {
blobs
.store()
.set_tag(tag.clone(), Some(*hash_and_format))
.await?;
blobs.store().set_tag(tag.clone(), *hash_and_format).await?;
tag
}
SetTagOption::Auto => blobs.store().create_tag(*hash_and_format).await?,
Expand Down Expand Up @@ -764,10 +770,7 @@ impl<D: crate::store::Store> Handler<D> {
let HashAndFormat { hash, format } = hash_and_format;
let tag = match msg.tag {
SetTagOption::Named(tag) => {
blobs
.store()
.set_tag(tag.clone(), Some(hash_and_format))
.await?;
blobs.store().set_tag(tag.clone(), hash_and_format).await?;
tag
}
SetTagOption::Auto => blobs.store().create_tag(hash_and_format).await?,
Expand Down Expand Up @@ -907,7 +910,7 @@ impl<D: crate::store::Store> Handler<D> {
SetTagOption::Named(tag) => {
blobs
.store()
.set_tag(tag.clone(), Some(*hash_and_format))
.set_tag(tag.clone(), *hash_and_format)
.await
.map_err(|e| RpcError::new(&e))?;
tag
Expand All @@ -922,7 +925,7 @@ impl<D: crate::store::Store> Handler<D> {
for tag in tags_to_delete {
blobs
.store()
.set_tag(tag, None)
.delete_tags(Some(tag.clone()), Some(tag.successor()))
.await
.map_err(|e| RpcError::new(&e))?;
}
Expand Down Expand Up @@ -959,7 +962,7 @@ impl<D: crate::store::Store> Handler<D> {
progress.send(DownloadProgress::AllDone(stats)).await.ok();
match tag {
SetTagOption::Named(tag) => {
self.store().set_tag(tag, Some(hash_and_format)).await?;
self.store().set_tag(tag, hash_and_format).await?;
}
SetTagOption::Auto => {
self.store().create_tag(hash_and_format).await?;
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/client/blobs/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ where
.rpc
.rpc(tags::SetRequest {
name: tag,
value: Some(tt.hash_and_format()),
value: tt.hash_and_format(),
batch: Some(self.0.batch),
sync: SyncMode::Full,
})
Expand Down
Loading
Loading