@@ -17,7 +17,11 @@ use anyhow::Context;
17
17
use anyhow:: Result ;
18
18
use async_trait:: async_trait;
19
19
use clap:: Parser ;
20
+ use edenfs_client:: client;
21
+ use edenfs_client:: glob_files:: Glob ;
22
+ use edenfs_client:: glob_files:: dtype_to_str;
20
23
use edenfs_client:: utils:: locate_repo_root;
24
+ use edenfs_utils:: path_from_bytes;
21
25
use hg_util:: path:: expand_path;
22
26
23
27
use crate :: ExitCode ;
@@ -105,10 +109,52 @@ pub struct GlobCmd {
105
109
revision : Option < Vec < String > > ,
106
110
}
107
111
112
+ impl GlobCmd {
113
+ fn print_result ( & self , result : & Glob ) -> Result < ( ) > {
114
+ if self . json {
115
+ println ! (
116
+ "{}\n " ,
117
+ serde_json:: to_string( & result)
118
+ . with_context( || "Failed to serialize result to JSON." ) ?
119
+ ) ;
120
+ } else {
121
+ if result. matching_files . len ( ) != result. origin_hashes . len ( )
122
+ || ( self . dtype && result. matching_files . len ( ) != result. dtypes . len ( ) )
123
+ {
124
+ println ! ( "Error globbing files: mismatched results" )
125
+ }
126
+
127
+ for i in 0 ..result. matching_files . len ( ) {
128
+ print ! (
129
+ "{:?}" ,
130
+ path_from_bytes( result. matching_files[ i] . as_ref( ) ) ?
131
+ . to_string_lossy( )
132
+ . to_string( )
133
+ ) ;
134
+ if self . list_origin_hash {
135
+ print ! ( "@{}" , hex:: encode( & result. origin_hashes[ i] ) ) ;
136
+ }
137
+ if self . dtype {
138
+ print ! ( " {}" , dtype_to_str( & result. dtypes[ i] ) ) ;
139
+ }
140
+ println ! ( ) ;
141
+ }
142
+
143
+ if self . verbose {
144
+ println ! ( "Num matching files: {}" , result. matching_files. len( ) ) ;
145
+ println ! ( "Num dtypes: {}" , result. dtypes. len( ) ) ;
146
+ println ! ( "Num origin hashes: {}" , result. origin_hashes. len( ) ) ;
147
+ }
148
+ }
149
+ Ok ( ( ) )
150
+ }
151
+ }
152
+
108
153
#[ async_trait]
109
154
impl crate :: Subcommand for GlobCmd {
110
155
async fn run ( & self ) -> Result < ExitCode > {
111
- let _instance = get_edenfs_instance ( ) ;
156
+ let instance = get_edenfs_instance ( ) ;
157
+ let client = instance. get_client ( ) ;
112
158
113
159
// Get cwd mount_point if not provided.
114
160
let current_dir: PathBuf ;
@@ -125,17 +171,28 @@ impl crate::Subcommand for GlobCmd {
125
171
let repo_root = locate_repo_root ( mount_point) ;
126
172
127
173
// Get relative root (search root)
128
- let prefix = repo_root. unwrap_or_else ( || Path :: new ( "" ) ) ;
129
- let search_root = mount_point. strip_prefix ( prefix ) ;
174
+ let repo_root = repo_root. unwrap_or_else ( || Path :: new ( "" ) ) ;
175
+ let search_root = mount_point. strip_prefix ( repo_root ) ? ;
130
176
131
177
// Load patterns
132
- let patterns = self . common . load_patterns ( ) ;
178
+ let patterns = self . common . load_patterns ( ) ?;
179
+
180
+ let glob = client
181
+ . glob_files (
182
+ repo_root,
183
+ patterns,
184
+ self . common . include_dot_files ,
185
+ false ,
186
+ false ,
187
+ self . dtype ,
188
+ search_root,
189
+ false ,
190
+ self . common . list_only_files ,
191
+ )
192
+ . await ?;
193
+
194
+ self . print_result ( & glob) ?;
133
195
134
- // TEMP: debugging code
135
- println ! (
136
- "mount_point = {:?}\n repo_root = {:?}\n prefix = {:?}\n search_root = {:?}\n patterns = {:?}" ,
137
- mount_point, repo_root, prefix, search_root, patterns
138
- ) ;
139
196
Ok ( 0 )
140
197
}
141
198
}
0 commit comments