@@ -30,7 +30,7 @@ use proto::{
3030 } ,
3131 tags:: {
3232 CreateRequest as TagsCreateRequest , DeleteRequest as TagDeleteRequest ,
33- ListRequest as TagListRequest , SetRequest as TagsSetRequest , SyncMode ,
33+ ListRequest as TagListRequest , RenameRequest , SetRequest as TagsSetRequest , SyncMode ,
3434 } ,
3535 Request , RpcError , RpcResult , RpcService ,
3636} ;
@@ -158,6 +158,7 @@ impl<D: crate::store::Store> Handler<D> {
158158 Set ( msg) => chan. rpc ( msg, self , Self :: tags_set) . await ,
159159 DeleteTag ( msg) => chan. rpc ( msg, self , Self :: blob_delete_tag) . await ,
160160 ListTags ( msg) => chan. server_streaming ( msg, self , Self :: blob_list_tags) . await ,
161+ Rename ( msg) => chan. rpc ( msg, self , Self :: tags_rename) . await ,
161162 }
162163 }
163164
@@ -295,7 +296,7 @@ impl<D: crate::store::Store> Handler<D> {
295296
296297 async fn blob_delete_tag ( self , msg : TagDeleteRequest ) -> RpcResult < ( ) > {
297298 self . store ( )
298- . set_tag ( msg. name , None )
299+ . delete_tags ( msg. from , msg . to )
299300 . await
300301 . map_err ( |e| RpcError :: new ( & e) ) ?;
301302 Ok ( ( ) )
@@ -313,7 +314,7 @@ impl<D: crate::store::Store> Handler<D> {
313314 tracing:: info!( "blob_list_tags" ) ;
314315 let blobs = self ;
315316 Gen :: new ( |co| async move {
316- let tags = blobs. store ( ) . tags ( ) . await . unwrap ( ) ;
317+ let tags = blobs. store ( ) . tags ( msg . from , msg . to ) . await . unwrap ( ) ;
317318 #[ allow( clippy:: manual_flatten) ]
318319 for item in tags {
319320 if let Ok ( ( name, HashAndFormat { hash, format } ) ) = item {
@@ -382,6 +383,16 @@ impl<D: crate::store::Store> Handler<D> {
382383 rx. map ( AddPathResponse )
383384 }
384385
386+ async fn tags_rename ( self , msg : RenameRequest ) -> RpcResult < ( ) > {
387+ let blobs = self ;
388+ blobs
389+ . store ( )
390+ . rename_tag ( msg. from , msg. to )
391+ . await
392+ . map_err ( |e| RpcError :: new ( & e) ) ?;
393+ Ok ( ( ) )
394+ }
395+
385396 async fn tags_set ( self , msg : TagsSetRequest ) -> RpcResult < ( ) > {
386397 let blobs = self ;
387398 blobs
@@ -393,13 +404,11 @@ impl<D: crate::store::Store> Handler<D> {
393404 blobs. store ( ) . sync ( ) . await . map_err ( |e| RpcError :: new ( & e) ) ?;
394405 }
395406 if let Some ( batch) = msg. batch {
396- if let Some ( content) = msg. value . as_ref ( ) {
397- blobs
398- . batches ( )
399- . await
400- . remove_one ( batch, content)
401- . map_err ( |e| RpcError :: new ( & * e) ) ?;
402- }
407+ blobs
408+ . batches ( )
409+ . await
410+ . remove_one ( batch, & msg. value )
411+ . map_err ( |e| RpcError :: new ( & * e) ) ?;
403412 }
404413 Ok ( ( ) )
405414 }
@@ -572,10 +581,7 @@ impl<D: crate::store::Store> Handler<D> {
572581 let HashAndFormat { hash, format } = * hash_and_format;
573582 let tag = match tag {
574583 SetTagOption :: Named ( tag) => {
575- blobs
576- . store ( )
577- . set_tag ( tag. clone ( ) , Some ( * hash_and_format) )
578- . await ?;
584+ blobs. store ( ) . set_tag ( tag. clone ( ) , * hash_and_format) . await ?;
579585 tag
580586 }
581587 SetTagOption :: Auto => blobs. store ( ) . create_tag ( * hash_and_format) . await ?,
@@ -764,10 +770,7 @@ impl<D: crate::store::Store> Handler<D> {
764770 let HashAndFormat { hash, format } = hash_and_format;
765771 let tag = match msg. tag {
766772 SetTagOption :: Named ( tag) => {
767- blobs
768- . store ( )
769- . set_tag ( tag. clone ( ) , Some ( hash_and_format) )
770- . await ?;
773+ blobs. store ( ) . set_tag ( tag. clone ( ) , hash_and_format) . await ?;
771774 tag
772775 }
773776 SetTagOption :: Auto => blobs. store ( ) . create_tag ( hash_and_format) . await ?,
@@ -907,7 +910,7 @@ impl<D: crate::store::Store> Handler<D> {
907910 SetTagOption :: Named ( tag) => {
908911 blobs
909912 . store ( )
910- . set_tag ( tag. clone ( ) , Some ( * hash_and_format) )
913+ . set_tag ( tag. clone ( ) , * hash_and_format)
911914 . await
912915 . map_err ( |e| RpcError :: new ( & e) ) ?;
913916 tag
@@ -922,7 +925,7 @@ impl<D: crate::store::Store> Handler<D> {
922925 for tag in tags_to_delete {
923926 blobs
924927 . store ( )
925- . set_tag ( tag, None )
928+ . delete_tags ( Some ( tag. clone ( ) ) , Some ( tag . successor ( ) ) )
926929 . await
927930 . map_err ( |e| RpcError :: new ( & e) ) ?;
928931 }
@@ -959,7 +962,7 @@ impl<D: crate::store::Store> Handler<D> {
959962 progress. send ( DownloadProgress :: AllDone ( stats) ) . await . ok ( ) ;
960963 match tag {
961964 SetTagOption :: Named ( tag) => {
962- self . store ( ) . set_tag ( tag, Some ( hash_and_format) ) . await ?;
965+ self . store ( ) . set_tag ( tag, hash_and_format) . await ?;
963966 }
964967 SetTagOption :: Auto => {
965968 self . store ( ) . create_tag ( hash_and_format) . await ?;
0 commit comments