@@ -25,17 +25,12 @@ pub enum BlobFormat {
2525pub ( crate ) mod function {
2626 use std:: ffi:: OsString ;
2727
28- use anyhow:: { anyhow, Context } ;
29- use gix:: diff:: blob:: ResourceKind ;
30- use gix:: filter:: plumbing:: driver:: apply:: Delay ;
3128 use gix:: revision:: Spec ;
3229
3330 use super :: Options ;
31+ use crate :: repository:: cat:: display_object;
3432 use crate :: repository:: revision:: resolve:: BlobFormat ;
35- use crate :: {
36- repository:: { revision, revision:: resolve:: TreeMode } ,
37- OutputFormat ,
38- } ;
33+ use crate :: { repository:: revision, OutputFormat } ;
3934
4035 pub fn resolve (
4136 mut repo : gix:: Repository ,
@@ -109,52 +104,4 @@ pub(crate) mod function {
109104 }
110105 Ok ( ( ) )
111106 }
112-
113- fn display_object (
114- repo : & gix:: Repository ,
115- spec : Spec < ' _ > ,
116- tree_mode : TreeMode ,
117- cache : Option < ( BlobFormat , & mut gix:: diff:: blob:: Platform ) > ,
118- mut out : impl std:: io:: Write ,
119- ) -> anyhow:: Result < ( ) > {
120- let id = spec. single ( ) . context ( "rev-spec must resolve to a single object" ) ?;
121- let header = id. header ( ) ?;
122- match header. kind ( ) {
123- gix:: object:: Kind :: Tree if matches ! ( tree_mode, TreeMode :: Pretty ) => {
124- for entry in id. object ( ) ?. into_tree ( ) . iter ( ) {
125- writeln ! ( out, "{}" , entry?) ?;
126- }
127- }
128- gix:: object:: Kind :: Blob if cache. is_some ( ) && spec. path_and_mode ( ) . is_some ( ) => {
129- let ( path, mode) = spec. path_and_mode ( ) . expect ( "is present" ) ;
130- match cache. expect ( "is some" ) {
131- ( BlobFormat :: Git , _) => unreachable ! ( "no need for a cache when querying object db" ) ,
132- ( BlobFormat :: Worktree , cache) => {
133- let platform = cache. attr_stack . at_entry ( path, Some ( mode. into ( ) ) , & repo. objects ) ?;
134- let object = id. object ( ) ?;
135- let mut converted = cache. filter . worktree_filter . convert_to_worktree (
136- & object. data ,
137- path,
138- & mut |_path, attrs| {
139- let _ = platform. matching_attributes ( attrs) ;
140- } ,
141- Delay :: Forbid ,
142- ) ?;
143- std:: io:: copy ( & mut converted, & mut out) ?;
144- }
145- ( BlobFormat :: Diff | BlobFormat :: DiffOrGit , cache) => {
146- cache. set_resource ( id. detach ( ) , mode. kind ( ) , path, ResourceKind :: OldOrSource , & repo. objects ) ?;
147- let resource = cache. resource ( ResourceKind :: OldOrSource ) . expect ( "just set" ) ;
148- let data = resource
149- . data
150- . as_slice ( )
151- . ok_or_else ( || anyhow ! ( "Binary data at {} cannot be diffed" , path) ) ?;
152- out. write_all ( data) ?;
153- }
154- }
155- }
156- _ => out. write_all ( & id. object ( ) ?. data ) ?,
157- }
158- Ok ( ( ) )
159- }
160107}
0 commit comments